board.py 663 Bytes
Newer Older
Fedrico Otaran's avatar
Fedrico Otaran committed
1
import PySimpleGUI as sg
2
from itertools import cycle
Fedrico Otaran's avatar
Fedrico Otaran committed
3
4
5
6
7
8
9
10
11
from src.windows import board


def start():
    window = loop()
    window.close()


def loop():
12
13
14
15
16
17
18
    player_1 = {"name": "Maria", "value": "X"}
    player_2 = {"name": "Marta", "value": "O"}
    turn = cycle([player_1, player_2])

    board_data = [[" "] * 3 for _i in range(3)]

    window = board.build(player_1, player_2, board_data)
Fedrico Otaran's avatar
Fedrico Otaran committed
19
20
21
22
23
24
25
26

    while True:
        event, _values = window.read()

        if event in (sg.WINDOW_CLOSED, "Exit", "-exit-"):
            break

        if event.startswith("cell"):
27
28
            player = next(turn)
            window[event].update(player["value"])
Fedrico Otaran's avatar
Fedrico Otaran committed
29
30

    return window