-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.py
executable file
·71 lines (57 loc) · 1.84 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'''
@authors: Richard B. Johnson
'''
from level import *
from utility import *
import time
class Game:
def __init__(self, interval = 200, path=""):
self.reset()
self.interval = interval
if (len(path) > 0):
self.loadPackageData(path)
def reset(self):
self.active = False
self.totalscore = 0
self.resetPackageData()
def resetPackageData(self):
self.datafile = ""
self.levels = 0
self.level = None
def loadPackageData(self, path):
file = None
try:
# load the header information
file = open(path, "rb")
self.datafile = path
#self.levels = 0
except IOError as e:
debug.error(e)
finally:
if (file != None):
file.close()
def nextLevel(self):
try:
if (self.level != None):
nxtlvl = self.level.ID + 1
else:
nxtlvl = 0
self.level = Level(self.datafile, nxtlvl)
except IOError:
debug.error("Unable to locate '%s'."%(self.datafile))
self.resetPackageData()
except InvalidLevel:
debug.notify("All levels have been completed.")
def randomLevel(self):
try:
nxtlvl = random.randint(0, self.levels)
self.level = Level(self.datafile, nxtlvl)
except IOError:
debug.error("Unable to locate '%s'."%(self.datafile))
self.resetPackageData()
def update(self):
if (self.active == False):
return False
self.level.tick()
time.sleep(self.interval / 1000.0)
return True