-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathController.py
38 lines (32 loc) · 1.46 KB
/
Controller.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
"""Controller - The controller object that mediates between the game world and the display window"""
import random, datetime
import Game
days_to_sec = 24*60*60
class World(object):
""" global controller construct"""
def __init__(self):
self.id=random.randint(101,1001)
self.timeScale = 1 #Number of seconds per day in game-time
self.time = 0 #realtime in seconds since start of game
self.G= Game.Game()
self.end = False
self.history={}
def quit(self):
self.end = True
def step(self, elapsedtime=1, GW=False):
# Primary logic loop for a 'turn'
self.time=self.time + elapsedtime/1000.
self.elapsedtime = elapsedtime/1000.
# Run World Value / Progress Calcs
step_messages = []
self.G.date += datetime.timedelta(days = elapsedtime/1000./self.timeScale)
decimal_days = elapsedtime/1000./self.timeScale
for mycity in self.G.cities:
#note that the cities update their projects
step_messages.extend(mycity.time_step(decimal_days, self.G))
for myplayer in self.G.players:
#Note that players update their dredges
step_messages.extend(myplayer.time_step(decimal_days, self.G))
# Record world for history I'm sure this will be interesting later
self.history[self.time]=self
return step_messages