Пример #1
0
    def cell_clicked(self, pos):
        ''' Method runs when the user clicks on a cell in the grid.'''
        from interface import singleton_interface        
        from resource  import singleton_resource
        
        r,c = pos

        # check for building construction
        if self.squares[r][c].buildable():
            try:
                mode = singleton_interface.get_mode()
                cost = building_costs[mode]
                if singleton_resource.spend(cost):
                    self.squares[r][c] = buildings[mode]()
            except KeyError:
                pass

        # check for worker assigning;
        if self.squares[r][c].workable():
            # if we want to assign a worker, we have to have one available.
            if singleton_interface.get_mode() == ASSIGN_WORKER \
                       and singleton_resource.get('Unemployed') >= 1 \
                       and self.squares[r][c].num_workers < 5:
                # then use up the worker and assign it to the square
                self.squares[r][c].num_workers += 1
                singleton_resource.resources['Unemployed'] -= 1
            if singleton_interface.get_mode() == REMOVE_WORKER \
                       and self.squares[r][c].num_workers > 0:
                self.squares[r][c].num_workers -= 1
                singleton_resource.resources['Unemployed'] += 1

        # demolish a building if requested
        if singleton_interface.get_mode() == DESTROY_BUILDING:
            self.demolish(r,c)
Пример #2
0
 def is_active(self):
     ''' a mode button is "active" if the interface mode is set to its mode.'''
     from interface import singleton_interface
     return singleton_interface.get_mode() == self.mode