root/src/gameData.py @ 451

Revision 451, 4.1 KB (checked in by jelinson, 2 years ago)

added building interlude

Line 
1'''
2Created on Mar 24, 2012
3
4@author: Michael
5'''
6
7import copy
8
9from stateAnalysis import StateAnalysis
10from event import Event
11from globals import *
12
13
14class GameData:
15    '''
16        holds all of the game data for our game.
17    '''
18
19    def __init__(self, state):
20        '''
21            initializes based on a given state.
22        '''
23        self.oldState = copy.deepcopy(state)
24        self.currentState = state
25        self.stateAnalysis = StateAnalysis()
26        self.sceneQueue = []
27        self.enqueueScene('intro')
28
29    def endTurn(self):
30        '''
31            ends the turn, updating states as necessary.
32
33            input type: none
34            return type: none
35        '''
36        change = self.oldState.calcTurnChange()
37        self.currentState.updateSpec(change)
38
39        buildSceneText = ""
40        for block in self.currentState.buildingsToAdd:
41            for building in block:
42                buildSceneText += building.name
43        if buildSceneText != "":
44            self.enqueueScene("build", buildSceneText)
45        self.currentState.endTurn()
46        self.oldState = copy.deepcopy(self.currentState)
47
48        self.stateAnalysis.analyze(self.oldState)
49        event = self.stateAnalysis.popAndFlushEvent()
50        if event is not None:
51            self.handleEvent(event)
52
53    def handleEvent(self, event):
54        self.oldState.specs += event.specChange
55        for building in event.buildingsToDelete:
56            if not self.oldState.deleteFirstBuilding(building):
57                print "Error in event: tried to delete %s, which wasn't present" % building
58        self.enqueueScene((event.sceneName, ""))
59
60    def getMoney(self):
61        """
62            gets the current level of money.
63
64            input type: none
65            return type: int
66        """
67        return self.currentState.getMoney()
68
69    def undoTurn(self):
70        """
71            undoes all buildings and actions for this turn.
72
73            input type: none
74            return type: none
75        """
76        self.currentState = copy.deepcopy(self.oldState)
77        self.clearScene()
78
79    def deleteBuilding(self, blockNumber, indexNumber):
80        """
81            deletes the selected building from the map.
82
83            input type: blockNumber(int), indexNumber(int)
84            return type: none
85        """
86        self.currentState.deleteBuilding(blockNumber, indexNumber)
87
88    def getBlockBuildings(self, blockNumber):
89        """
90            returns the images associated with the buildings that exist in the
91            designated block.
92
93            input type: blockNumber(int)
94            return type: none
95        """
96        return self.currentState.getBlockBuildings(blockNumber)
97
98    def blockHasSpace(self, blockNumber):
99        """
100            returns whether the designated block has space for more buildings.
101
102            input type: blockNumber(int)
103            return type: boolean
104        """
105        return self.currentState.blockHasSpace(blockNumber)
106
107    def build(self, building, blockNumber):
108        """
109            builds the building. Assumes there are enough stats and space on
110            the designated block.
111
112            input type: building(str), blockNumber(int)
113            return type: none
114        """
115        self.currentState.addBuilding(building, blockNumber)
116
117    def research(self, researchType, value):
118        """
119            adds research to the designated type.
120
121            input type: type(int), value(int)
122            return type: none
123        """
124        self.currentState.research(researchType, value)
125
126    def getSpec(self):
127        """
128            returns the spec containing values of current resources.
129
130            input type: none
131            return type: spec
132        """
133        return self.currentState.getSpec()
134
135    def enqueueScene(self, sceneName, auxText=""):
136        self.sceneQueue.append((sceneName, auxText))
137
138    def dequeueScene(self):
139        if len(self.sceneQueue) != 0:
140            return self.sceneQueue.pop(0)
141        else:
142            return (None, None)
143
144    def clearScene(self):
145        self.sceneQueue = []
Note: See TracBrowser for help on using the browser.