forked from PyLadiesCZ/roboprojekt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
50 lines (38 loc) · 1.17 KB
/
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
41
42
43
44
45
46
47
48
49
50
"""
The game module
- coordinate everything and run the game
- call pyglet window, various backend and frontend functions
- choose standard or other map to be loaded
"""
from backend import get_start_state
from frontend import init_window, draw_board
import pyglet
import sys
# load JSON map data from the backend module
if len(sys.argv) == 1:
map_name = "maps/test_3.json"
# if other map should be loaded, use extra argument "maps/MAP_NAME.json" when calling game.py by Python
# for example: python game.py maps/test_2.json
else:
map_name = sys.argv[1]
# Get starting state of the game from the backend module.
state = get_start_state(map_name)
# Load pyglet graphic window from the frontend module.
window = init_window(state)
@window.event
def on_draw():
"""
Clears the graphic window and draw the game state (board and robots).
"""
window.clear()
draw_board(state)
def move_once(t):
"""
Move all robots 2 tiles forward and rotate 180 degrees.
"""
for robot in state.robots:
robot.walk(3, state)
robot.rotate("upside_down")
pyglet.clock.schedule_once(move_once, 3)
# Run the pyglet library.
pyglet.app.run()