Changeset 47


Ignore:
Timestamp:
02/23/12 06:27:10 (3 years ago)
Author:
mmorton
Message:
 
Files:
4 added
9 edited

Legend:

Unmodified
Added
Removed
  • src/constants.py

    r26 r47  
    3737AIRPLANE = 1
    3838# etc.
     39
     40# constants for map
     41BLOCKS = 5
     42MAX_BUILDINGS = 2
  • src/game.py

    r43 r47  
    66from turn import *
    77from state import *
    8 
     8from map import *
    99
    1010class Game:
     
    1313        self.oldState = state
    1414        self.currentTurn = Turn(state)
     15        self.map = Map()
    1516       
    1617    def endTurn(self):
    1718        self.currentTurn.endTurn()
     19        self.map.endTurn()
    1820        self.oldState = self.currentTurn.getState()
    1921   
    2022    def createWindow(self, name):
     23        windowType = name.split('_')
     24       
     25        # Messing with the map
     26        if windowType[0] == 'blockMap':
     27            return self.map.createSmallMap(int(windowType[1]))
     28       
     29        # If we have a 'create' command, we need to check if there is room on the block, and if there is, pass it to the turn
     30        if windowType[0] == 'create':
     31            if self.currentTurn.buildingPossible(windowType[1]) and self.map.checkSpace():
     32                self.map.addBuilding(windowType[1])
     33                self.currentTurn.addBuilding(windowType[1])
     34            return self.currentTurn.createBuildMenu()
     35       
     36       
    2137        return self.currentTurn.createWindow(name)
    2238   
     39    def createSmallMap(self, blockID):
     40        return self.map.createSmallMap(blockID)
    2341   
     42   
  • src/main.py

    r43 r47  
    3030    screenSurface.fill(BLACK)
    3131   
     32    # If you want to see bad coding, this is it...
     33    from staticWindows import *
     34   
    3235    # create user interface object
    3336    ui = UI()
    3437   
    3538    # create game object
    36     game = Game(State(Spec(200,50,20,50,50)))
    37    
    38     # Windows Dictionary... whatever, it works
    39     windowsDict = {}
    40    
    41     # create necessary windows
    42     backGround = Window('background',0,0)
    43     backGroundEntry = WindowEntry(('',False,False))
    44     openingArt = pygame.image.load(resourceDir + os.sep + "menu_icons" + os.sep +"intro1.jpg")
    45     backGroundEntry.addImage(Image((0,0),1080,792,openingArt))
    46     backGround.addEntry(backGroundEntry)
    47     windowsDict['background'] = backGround
    48    
    49     buildGameMenu = Window('buildButton',40,720)
    50     buildIcon = WindowEntry(('build_menu',False,False))
    51     buildArt = pygame.image.load(os.path.abspath(resourceDir + os.sep + "menu_icons" + os.sep + "png" + os.sep + "build.png"))
    52     buildIcon.addImage(Image((5,5),40,40,buildArt,))
    53     buildIcon.addRectangle(Rectangle((0,0),220,50,BLUE))
    54     buildIcon.addText(Text((80,13),"BUILD",42,WHITE))
    55     buildGameMenu.addEntry(buildIcon)
    56     windowsDict['buildButton'] = buildGameMenu
    57    
    58     researchGameMenu = Window('researchButton',275,720)
    59     researchIcon = WindowEntry(('researchMenu',False,False))
    60     buildArt = pygame.image.load(os.path.abspath(resourceDir + os.sep + "menu_icons" + os.sep  + "png" + os.sep +"research.png"))
    61     researchIcon.addImage(Image((5,5),40,40,buildArt))
    62     researchIcon.addRectangle(Rectangle((0,0),220,50,BLUE))
    63     researchIcon.addText(Text((55,13),"RESEARCH",42,WHITE))
    64     researchGameMenu.addEntry(researchIcon)
    65     windowsDict['researchButton'] = researchGameMenu
    66    
    67 #    buildMenu = Window('buildMenu',20,20)
    68 #    buildMenu.setDefaultResponse(('',True,True))
    69 #    # Hard coded for now, but eventually will be a for loop through each object
    70 #    buildIcon = WindowEntry(('',False,False))
    71 #    buildArt = pygame.image.load(os.path.abspath(resourceDir + os.sep + "menu_icons" + os.sep + "png" + os.sep + "build.png"))
    72 #    buildIcon.addImage(Image((120,10),40,40,buildArt))
    73 #    buildIcon.addImage(Image((345,10),40,40,buildArt))
    74 #    buildIcon.addRectangle(Rectangle((0,0),MENU_W,MENU_H,BLUE))
    75 #    buildIcon.addText(Text((210,17),"BUILD",42,WHITE,))
    76 #    buildMenu.addEntry(buildIcon) 
    77 #    windowsDict['buildMenu'] = buildMenu 
    78    
    79     researchMenu = Window('researchMenu',20,20)
    80     researchMenu.setDefaultResponse(('',True,True))
    81     # Hard coded for now, but eventually will be a for loop through each object
    82     researchIcon = WindowEntry(('',False,False))
    83     researchArt = pygame.image.load(os.path.abspath(resourceDir + os.sep + "menu_icons" + os.sep + "png" + os.sep + "research.png"))
    84     researchIcon.addImage(Image((120,10),40,40,researchArt))
    85     researchIcon.addImage(Image((345,10),40,40,researchArt,))
    86     researchIcon.addRectangle(Rectangle((0,0),MENU_W,MENU_H,BLUE))
    87     researchIcon.addText(Text((175,17),"RESEARCH",42,WHITE))
    88     researchMenu.addEntry(researchIcon)
     39    game = Game(State(Spec(2000,500,200,500,500)))
    8940   
    9041   
    91    
    92     # Swifting each entry down 120
    93     # Each description is shifted down 30 from name
    94    
    95     researchIcon = WindowEntry(('researchPower',False,False))
    96     buildArt = pygame.image.load(os.path.abspath(resourceDir + os.sep + "menu_icons" + os.sep + "png" + os.sep + "power.png"))
    97     researchIcon.addImage(Image((390,110),ICON_SIZE,ICON_SIZE,buildArt))
    98     researchIcon.addRectangle(Rectangle((20,100),460,100,CYAN))
    99     researchIcon.addText(Text((25,110),"POWER",32,WHITE))
    100     researchIcon.addText(Text((25,140),"This is where the text would go.",24,WHITE))
    101     researchMenu.addEntry(researchIcon)
    102    
    103     researchIcon = WindowEntry(('researchMoney',False,False))
    104     buildArt = pygame.image.load(os.path.abspath(resourceDir + os.sep + "menu_icons" + os.sep + "png" + os.sep + "coins.png"))
    105     researchIcon.addImage(Image((390,230),ICON_SIZE,ICON_SIZE,buildArt))
    106     researchIcon.addRectangle(Rectangle((20,220),460,100,CYAN))
    107     researchIcon.addText(Text((25,230),"MONEY",32,WHITE))
    108     researchIcon.addText(Text((25,260),"This is where the text would go.",24,WHITE))
    109     researchMenu.addEntry(researchIcon)
    110    
    111     researchIcon = WindowEntry(('researchMaterial',False,False))
    112     buildArt = pygame.image.load(os.path.abspath(resourceDir + os.sep + "menu_icons" + os.sep + "png" + os.sep + "material.png"))
    113     researchIcon.addImage(Image((390,350),ICON_SIZE,ICON_SIZE,buildArt))
    114     researchIcon.addRectangle(Rectangle((20,340),460,100,CYAN))
    115     researchIcon.addText(Text((25,350),"MATERIAL",32,WHITE))
    116     researchIcon.addText(Text((25,380),"This is where the text would go.",24,WHITE))
    117     researchMenu.addEntry(researchIcon)
    118     windowsDict['researchMenu'] = researchMenu
    119 
    12042   
    12143    """
     
    15577    ui.addWindow(buildGameMenu)
    15678    ui.addWindow(researchGameMenu)
     79    ui.addWindow(endTurn)
     80    ui.addWindow(game.createSmallMap(0))
    15781   
    15882    # deprecated
    15983    # window.displayImages(screenSurface)
    16084   
    161     # flag for toggling
    162     buildMenuFlag = False
    163     researchMenuFlag = False
     85
    16486   
    16587
     
    17395                if windowsDict.has_key(i[0]):
    17496                    ui.addWindow(windowsDict[i[0]])
     97                elif i[0] == 'endTurnNow':
     98                    game.endTurn()
    17599                else:
    176100                    ui.addWindow(game.createWindow(i[0]))
  • src/map.py

    r28 r47  
     1from block import *
     2from constants import *
     3
     4class Map:
     5   
     6    def __init__(self):
     7       
     8
     9       
     10        #placeholder
     11        self.landscapeIDs =[0,1]
     12        self.currentBlock = 0
     13        self.blockList = []
     14        for i in range(BLOCKS):
     15            self.blockList.append(Block(i,i))
     16           
     17   
     18    def createSmallMap(self,blockNumber):
     19        smallMap = self.blockList[blockNumber].createBlockMap()
     20        self.currentBlock = blockNumber
     21       
     22        # add back button
     23        if blockNumber > 0:
     24            backButton = WindowEntry(('blockMap_' + str(blockNumber-1),True,False))
     25        else:
     26            backButton = WindowEntry(('',False,False))
     27        backButton.addRectangle(Rectangle((10,200),80,80,self.blockList[blockNumber].myColor))
     28        backButtonArt = pygame.image.load(os.path.abspath(resourceDir + os.sep + "images" + os.sep + "test images" + os.sep + "backButton.png"))
     29        backButton.addImage(Image((10,200),80,80,backButtonArt))
     30        smallMap.addEntry(backButton)
     31       
     32        # add next button
     33        if blockNumber < BLOCKS-1:
     34            nextButton = WindowEntry(('blockMap_' + str(blockNumber+1),True,False))
     35        else:
     36            nextButton = WindowEntry(('',False,False))
     37            print 'blah'
     38        nextButton.addRectangle(Rectangle((200,200),80,80,self.blockList[blockNumber].myColor))
     39        nextButtonArt = pygame.image.load(os.path.abspath(resourceDir + os.sep + "images" + os.sep + "test images" + os.sep + "nextButton.png"))
     40        nextButton.addImage(Image((200,200),80,80,nextButtonArt))
     41        smallMap.addEntry(nextButton)
     42       
     43        # jump to block
     44        for i in range(BLOCKS):
     45            if i < self.currentBlock:
     46                jumpButton = WindowEntry(('blockMap_' + str(i),True,False))
     47                jumpButton.addRectangle(Rectangle((80 + 40*i,320),20,20,self.blockList[i].myColor))
     48                smallMap.addEntry(jumpButton)
     49            elif i > self.currentBlock:
     50                jumpButton = WindowEntry(('blockMap_' + str(i),True,False))
     51                jumpButton.addRectangle(Rectangle((80 + 40*(i-1),320),20,20,self.blockList[i].myColor))
     52                smallMap.addEntry(jumpButton)
     53        return smallMap
     54       
     55       
     56    def addBuilding(self,name):
     57        self.blockList[self.currentBlock].addBuilding(name)
     58       
     59    def checkSpace(self):
     60        return self.blockList[self.currentBlock].checkSpace()
     61   
     62    def endTurn(self):
     63        for block in self.blockList:
     64            block.endTurn()
     65       
  • src/pygame2exe.py

    r23 r47  
    8080       
    8181        #DLL Excludes
    82         self.exclude_dll = ['']
     82        self.exclude_dll = []
    8383        #python scripts (strings) to be included, seperated by a comma
    8484        self.extra_scripts = []
  • src/turn.py

    r44 r47  
    1717        if windowType[0] == 'describe':
    1818            return self.turnMenu.createDescription(windowType[1])
    19         if windowType[0] == 'create' :
    20             self.currentState.addBuilding(windowType[1])
    21             return self.turnMenu.createBuildMenu(self.currentState)
     19   
     20    def createBuildMenu(self):
     21        return self.turnMenu.createBuildMenu(self.currentState)
     22   
     23    def addBuilding(self,name):
     24        self.currentState.addBuilding(name)
     25   
     26    def buildingPossible(self,name):
     27        return self.currentState.checkThresh(name)
    2228   
    2329    def getState(self):
  • src/turnMenu.py

    r44 r47  
    5454        buildIcon = WindowEntry(('create_' + name,True,False))
    5555        buildArt = pygame.image.load(os.path.abspath(resourceDir + os.sep + 'menu_icons' + os.sep + buildingLUT[name].imageFileName))
    56         #buildIcon.addImage(Image((390,110),ICON_SIZE,ICON_SIZE,buildArt))
     56        buildIcon.addImage(Image((390,110),ICON_SIZE,ICON_SIZE,buildArt))
    5757        buildIcon.addRectangle(Rectangle((20,100),460,100,CYAN))
    5858        buildIcon.addText(Text((25,110),name,32,WHITE))
  • src/ui.py

    r43 r47  
    2020        """ add window """
    2121        if window != None:
     22            if window in self.windows:
     23                self.windows.remove(window)
    2224            self.windows.append(window)
    2325       
     
    4345                closeList = []
    4446                for i in reversed(range(len(self.windows))):
    45                     print self.windows[i].id, ':', self.windows[i].left, '  ' , self.windows[i].top
    4647                    # get response from each window, starting with most recent
    4748                    responseSignal = self.windows[i].response(self.lastClick)
     49                    print responseSignal[0]
    4850                    if responseSignal[0] != '':
    4951                        exists = False
  • src/window.py

    r43 r47  
    2626        self.left = left
    2727        self.top = top
    28         self.defaultResponse = ('', False, True) # Resonse tuple gives ( Response ID, bool Close, bool Propogate )
     28        self.defaultResponse = ('', False, True) # Resonse tuple gives ( Response ID, bool CloseSelf, bool Propogate )
    2929       
    3030    def addEntry(self,entry):
Note: See TracChangeset for help on using the changeset viewer.