-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (34 loc) · 1.03 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
"""
This module contains the main function of the game. It initializes the game and runs the game loop.
"""
import gamelib
from logic import Game, draw_background, draw_new_game_button
def main():
"""
Main function. Initializes the game and runs the game loop.
"""
gamelib.resize(600, 600)
gamelib.title("2048")
draw_background()
draw_new_game_button()
game = Game()
while gamelib.is_alive():
game.show()
if game.lost() or game.won():
message = "You won!" if game.won() else "You lost!"
gamelib.say(message)
game.reset()
continue
event = gamelib.wait()
if not event:
game.store_best_score()
break
if event.type == gamelib.EventType.KeyPress:
game.update(event.key)
elif (
event.type == gamelib.EventType.ButtonPress
and event.mouse_button == 1
and game.new_game_button_clicked(event.x, event.y)
):
game.reset()
gamelib.init(main)