-
Notifications
You must be signed in to change notification settings - Fork 2
/
united_guards.py
119 lines (98 loc) · 3 KB
/
united_guards.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
#version 0.3, released on September 26, 2012 by Vojtech Polasek <[email protected]>
# the game is structured into several modules:
#game - game functions
# ug_data - various declarations that won't change
# speech - module for speech
# menu - module for creating menus
#menus - definitions of actual menus
#see included README file for more info
#initialisation
import time, pygame, os.path, random, speech, sys, cPickle
#pygame initialisation
pygame.init()
pygame.display.set_mode((320, 200))
pygame.display.set_caption ('United guards')
#initialisation of speech
s =speech.Speaker()
s.init()
speech.s = s
_ = speech.getTransFunc()
import game, menu, menus
loop_running = None #True if main loop catching events is running
game_active = None
menu_active = None
current_menu = None
def loop():
"""main loop catching keyboard and other events."""
global game_active, menu_active, current_menu
loop_running = True
while loop_running == True:
pygame.time.wait(1)
event = pygame.event.poll ()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
if game_active == True:
game.pausegame()
elif event.key == pygame.K_RETURN:
if menu_active == True:
returned = current_menu.select()
if returned != None:
current_menu = returned
elif event.key == pygame.K_LEFT:
if game_active == True:
game.check(0)
elif event.key == pygame.K_UP:
if menu_active == True:
current_menu.moveup()
elif game_active == True:
game.check(1)
elif event.key == pygame.K_RIGHT:
if game_active == True:
game.check(2)
elif event.key == pygame.K_DOWN:
if menu_active == True:
current_menu.movedown()
elif event.key == pygame.K_s:
if game_active == True:
s.say(_("Your score is {0}.").format(game.score), 1)
elif event.key == pygame.K_l:
if game_active == True:
s.say (_("You have {0} lives remaining.").format(game.lives), 1)
elif event.key == pygame.K_LCTRL or event.key == pygame.K_RCTRL:
s.stop()
if event.type == pygame.USEREVENT:
if event.code == 1:
game_active = True
menu_active = False
if event.code == 2:
game_active = False
menu_active = True
current_menu = menus.abortprompt.init()
if event.code == 3:
game_active = False
menu_active = True
current_menu = menus.main_menu.init()
if game_active == True:
game.gamechecker()
if __name__ == "__main__":
from ug_data import *
s.say(_("Welcome to the game."), 1)
current_menu = menus.main_menu.init()
menu_active = True
try:
scorefile = open("score.dat", "r")
try:
game.scoreboard = cPickle.load(scorefile)
for score in game.scoreboard:
if score == None:break
if len(score) < 3:
score.append(None)
except EOFError:
game.scoreboard = []
scorefile.close()
except IOError:
game.scoreboard = []
scorefile = open("score.dat", "w")
scorefile.close()
loop()