-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (47 loc) · 1.86 KB
/
main.py
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
import logging
import pygame as pg
from pygame.event import EventType
from game.board import Board, Player
logger = logging.getLogger("main")
def main():
logging.basicConfig(level=logging.INFO)
pg.init()
pg.display.set_caption("Othello")
done = False
board = Board()
while not done:
for event in pg.event.get():
match event:
case EventType(type=pg.KEYDOWN):
if event.key == pg.K_p:
board.pass_move()
elif event.key == pg.K_p: # pass
board.pass_move
elif event.key == pg.K_q: # quit
done = True
elif event.key == pg.K_r: # revert
board.revert()
elif event.key == pg.K_s: # score
logger.info(
"Current score of %s: %d",
Player.BLACK,
board.score(Player.BLACK),
)
logger.info(
"Current score of %s: %d",
Player.WHITE,
board.score(Player.WHITE),
)
case EventType(type=pg.QUIT):
done = True
case EventType(type=pg.MOUSEBUTTONDOWN):
x = pg.mouse.get_pos()[0] // Board.SQUARE_SIZE
y = pg.mouse.get_pos()[1] // Board.SQUARE_SIZE
logger.debug(f"{board.player} on row:{y} and column:{x}")
board.update(column=x, row=y)
pg.display.flip()
pg.quit()
logger.info("Score of %s: %d", Player.BLACK, board.score(Player.BLACK))
logger.info("Score of %s: %d", Player.WHITE, board.score(Player.WHITE))
if __name__ == "__main__":
main()