-
Notifications
You must be signed in to change notification settings - Fork 0
/
User_game.py
40 lines (30 loc) · 910 Bytes
/
User_game.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
import pygame, os
import _2048
from _2048.game import Game2048
from _2048.manager import GameManager
def run_game(game_class=Game2048, title='2048!', data_dir='save'):
'''
This will run a traditional one-human-player 2048 game
'''
pygame.init()
pygame.display.set_caption(title)
pygame.display.set_icon(game_class.icon(32))
clock = pygame.time.Clock()
os.makedirs(data_dir, exist_ok=True)
screen = pygame.display.set_mode((game_class.WIDTH, game_class.HEIGHT))
manager = GameManager(Game2048, screen,
os.path.join(data_dir, '2048.score'),
os.path.join(data_dir, '2048.%d.state'))
# game loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
break
manager.dispatch(event)
manager.draw()
# end while
pygame.quit()
manager.close()
run_game()