root/src/gameData.py @ 401

Revision 401, 3.4 KB (checked in by rthomas, 2 years ago)

added win scene and back/forward responses

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