root/src/map.py @ 147

Revision 147, 5.0 KB (checked in by mmorton, 2 years ago)

Block and map completed.

Line 
1'''
2Created on Feb 22, 2012
3Map functionality
4
5@author: TechTrek
6'''
7from globals import *
8from block import *
9
10
11class Map:
12    """
13        Map holds all the blocks, and handles all accesses to these blocks.
14        Including calls to render the blocks. Also creates all buttons that
15        will change the block that is visible.
16    """
17   
18    def __init__(self):
19        """
20            Initializes all the blocks in the Map and the current visible block.
21
22            input type: None
23        """
24        self.currentBlock = 0
25        self.blockList = []
26        for i in range(BLOCKS):
27            self.blockList.append(Block(i))
28           
29    def createSmallMap(self,blockNumber,scale):
30        """
31            Creates the map for the desired block. Also scales the map as desired.
32            This calls createBlockMap on the specified block, then adds the next
33            and back buttons, and finally adds the block shortcuts below the map.
34
35            input type: int(blockNumber), int(scale)
36            return type: Window(smallMap)
37        """
38        smallMap = self.blockList[blockNumber].createBlockMap(scale)
39        self.currentBlock = blockNumber
40       
41        # Add back button. No response if this is the first block.
42        if blockNumber > 0:
43            backButton = WindowEntry(Response('windows',['blockMap_' + str(blockNumber - 1)],True,False))
44        else:
45            backButton = WindowEntry(Response('windows',[],False,False))
46        backButtonArt = pygame.image.load(os.path.abspath(mapDir + os.sep + "backButton.png"))
47        backButton.addImage(Image((10,(MAP_H - 25) * scale),25 * scale,25 * scale,backButtonArt))
48        smallMap.addEntry(backButton)
49       
50        # Add next button. No response if this is the last block.
51        if blockNumber < BLOCKS - 1:
52            nextButton = WindowEntry(Response('windows',['blockMap_' + str(blockNumber + 1)],True,False))
53        else:
54            nextButton = WindowEntry(Response('windows',[],False,False))
55        nextButtonArt = pygame.image.load(os.path.abspath(mapDir + os.sep + "nextButton.png"))
56        nextButton.addImage(Image(((MAP_W - 25) * scale - 10,(MAP_H - 25) * scale),25 * scale,25 * scale,nextButtonArt))
57        smallMap.addEntry(nextButton)
58       
59        # Add the block shorcuts. Small windows that allow the user to jump
60        # directly to any block desired.
61        for i in range(BLOCKS):
62            # Experimental: use smaller versions of the landscape image of the
63            #               block as the square for the shortcuts.
64            landscapeArt = pygame.image.load(os.path.abspath(landscapeDir + os.sep + "landscape-0" + str(self.blockList[i].ID + 1) + ".png"))
65           
66            # If we're already looking at this block, we make the shortcut
67            # button bigger.
68            if i == self.currentBlock:
69                jumpButton = WindowEntry(Response('windows',['blockMap_' + str(i)],False,False))
70                jumpButton.addRectangle(Rectangle((5 * scale + 20 * scale * i - 5,MAP_H * scale + 5),30,30,self.blockList[i].myColor))
71                jumpButton.addImage(Image((5 * scale + 20 * scale * i - 5,MAP_H * scale + 5),30,30,landscapeArt))
72                smallMap.addEntry(jumpButton)
73               
74            # Otherwise, it is small.
75            else:
76                jumpButton = WindowEntry(Response('windows',['blockMap_' + str(i)],True,False))
77                jumpButton.addRectangle(Rectangle((5 * scale + 20 * scale * i,MAP_H * scale + 10),20,20,self.blockList[i].myColor))
78                jumpButton.addImage(Image((5 * scale + 20 * scale * i,MAP_H * scale + 10),20,20,landscapeArt))
79                smallMap.addEntry(jumpButton)
80               
81        # Finally, return the completed map.
82        return smallMap
83         
84    def addBuilding(self,building):
85        """
86            Adds a building to the currently visible block. Assumes that the
87            block has room, and that building is a valid building.
88
89            input type: Building(building)
90            return type: None
91        """
92        self.blockList[self.currentBlock].addBuilding(building)
93       
94    def checkSpace(self):
95        """
96            Returns True if the currently visible block has room for another
97            building. Otherwise, returns false.
98
99            input type: None
100            return type: bool
101        """
102        return self.blockList[self.currentBlock].checkSpace()
103   
104    def endTurn(self):
105        """
106            Ends turn by calling end turn function on every block
107
108            input type: None
109            return type: None
110        """
111        for block in self.blockList:
112            block.endTurn()
113       
114    def undoTurn(self):
115        """
116            Undoes the current turn by removing all the buildings that
117            would have been added this turn to each block.
118
119            input type: None
120            return type: None
121        """
122        for block in self.blockList:
123            block.flushBuildingsToBuild()
Note: See TracBrowser for help on using the browser.