Changeset 346:6baf8b5beb5c


Ignore:
Timestamp:
Sep 5, 2009, 11:11:16 PM (11 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@347
Message:

Remove the "constant" constant

Location:
gamelib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • gamelib/constants.py

    r331 r346  
    5353        }
    5454
    55 # This is a "constant".
    56 TURN_LIMIT = TURN_LIMITS['Two weeks']
     55DEFAULT_MODE = 'Two weeks'
    5756
    5857ABS_MAX_NUM_FOXES = 50 # Limit possible uppoer number of foxes, due to concerns
  • gamelib/engine.py

    r336 r346  
    3434    def create_game_board(self):
    3535        """Create and open a gameboard window."""
    36         self.gameboard = gameboard.GameBoard(self.main_app)
     36        self.mode = self.main_menu.get_mode()
     37        if not self.mode:
     38            self.mode = constants.DEFAULT_MODE
     39        self.gameboard = gameboard.GameBoard(self.main_app,
     40                constants.TURN_LIMITS[self.mode])
    3741        self.open_window(self.gameboard.get_top_widget())
    3842
     
    4852    def create_game_over(self):
    4953        """Create and open the Game Over window"""
    50         for mode, days in constants.TURN_LIMITS.iteritems():
    51             if days == constants.TURN_LIMIT:
    52                 game_over = gameover.create_game_over(self.gameboard,
    53                         self.scoreboard[mode], mode)
     54        game_over = gameover.create_game_over(self.gameboard,
     55                self.scoreboard[self.mode], self.mode)
    5456        self.gameboard = None
    5557        self.open_window(game_over)
  • gamelib/gameboard.py

    r345 r346  
    318318        )
    319319
    320     def __init__(self, main_app):
     320    def __init__(self, main_app, max_turns):
    321321        self.disp = main_app
    322322        self.tv = tiles.FarmVid()
     
    326326        # Ensure we don't every try to create more foxes then is sane
    327327        self.max_foxes = min(height+width-15, constants.ABS_MAX_NUM_FOXES)
     328        self.max_turns = max_turns
    328329        self.create_display()
    329330
     
    827828    def advance_day(self):
    828829        self.days += 1
    829         if self.days == constants.TURN_LIMIT:
     830        if self.days == self.max_turns:
    830831            self.toolbar.day_counter.style.color = (255, 0, 0)
    831         self.toolbar.update_day_counter("%s/%s" % (self.days, constants.TURN_LIMIT if constants.TURN_LIMIT > 0 else "-"))
     832        self.toolbar.update_day_counter("%s/%s" % (self.days,
     833            self.max_turns if self.max_turns > 0 else "-"))
    832834
    833835    def clear_foxes(self):
     
    10611063        if self.trees_left() == 0:
    10621064            return True
    1063         if constants.TURN_LIMIT > 0 and self.days >= constants.TURN_LIMIT:
     1065        if self.max_turns > 0 and self.days >= self.max_turns:
    10641066            return True
    10651067        if len(self.chickens) == 0:
  • gamelib/mainmenu.py

    r312 r346  
    2323        gui.Container.paint(self, s)
    2424
     25    def get_mode(self):
     26        return self.widgets[0].mode
     27
    2528class MainMenu(gui.Table):
    2629    def __init__(self, **params):
    2730        gui.Table.__init__(self, **params)
     31        self.mode = None
    2832
    2933        def fullscreen_toggled():
     
    3438
    3539        def start_game(mode):
    36             constants.TURN_LIMIT = constants.TURN_LIMITS[mode]
     40            self.mode = mode
    3741            pygame.event.post(engine.START_DAY)
    3842
Note: See TracChangeset for help on using the changeset viewer.