File size: 2,148 Bytes
0bf6ae6
fa23469
0bf6ae6
 
366b3be
7de08f1
0bf6ae6
 
 
15d490f
fa23469
 
 
 
 
 
 
 
 
190a1fc
c0ecdf0
 
fa23469
 
 
 
 
418d718
 
 
 
81981b8
 
 
 
e690fd1
 
 
 
81981b8
 
0655c1e
cb3cd0f
efd547e
b232823
2959764
7de08f1
2959764
7de08f1
0655c1e
4cf694c
190a1fc
b50fde9
fa23469
efd547e
 
fa23469
 
 
 
 
 
 
 
c0857f7
7de08f1
 
 
 
15d490f
4cf694c
15d490f
e41ed87
b00ba63
366b3be
 
 
efd547e
b00ba63
efd547e
 
 
c0857f7
efd547e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from fastapi import FastAPI
from fastapi.responses import HTMLResponse

app = FastAPI()
state = [-1,-1,-1,-1,-1,-1,-1,-1,-1]
step = '🐱'

@app.get("/")
def greet_json():
    # return {"Hello": "World!"}
    # return state
    html_content = """
        <html>
            <head>
                <title>Some HTML in here</title>
                <style>
                .char{
                    padding:20px;
                    background-color:green;
                    margin-left:55px;
                    margin-right:55px;
                    cursor:pointer;
                }
                .char:even {
                    background-color:yellow;
                }
                </style>
                <script
			  src="https://code.jquery.com/jquery-3.7.1.min.js"
			  integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
			  crossorigin="anonymous"></script>
			  
            </head>
            <body>
            <script>
			  function go(i){
			    $.get('/turn/'+i);
			    document.location.reload();
			  }
            </script>
            """
    html_content += 'сейчас ходит: ' + step + '<br><br>'
    for i in range(9):
        if state[i] == -1:
            char = '_'
        elif state[i] == 1:
            char = '🐭'
        elif state[i] == 0:
            char = '🐱'

        if i in [0,3,6]:
            html_content += '<br><br><br><br>'
        html_content += '<span class="char"><span onclick="go('+str(i)+')">' + char + '</span></span>'

    html_content += '<br><br><br><br><br><a href="/reset">reset</a>'

    html_content += """
            </body>
        </html>
        """
    return HTMLResponse(content=html_content, status_code=200)

def change_step():
    global step
    print(step)
    if step == '🐱':
        step = '🐭'
    elif step == '🐭':
        step = '🐱'

@app.get('/turn/{pos}')
def turn(pos):
    global state

    if state[int(pos)] == '-1':
        state[int(pos)] = step
    else:
        state[int(pos)] = int(not state[int(pos)])
    change_step()

@app.get('/reset')
def reset():
    global state
    state = [-1,-1,-1,-1,-1,-1,-1,-1,-1]