示例#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 update(self):
        from resource import singleton_resource

        global current_level
        # Check if victory condition has been met
        bool0 = singleton_resource.get_total_workers() >= self.population_goal
        bool1 = singleton_resource.get("Gold") >= self.gold_goal
        if bool0 and bool1:
            try:
                current_level += 1
                levels[current_level].begin()
                show_message("You have conquered this level! Next is level {0}.".format(current_level + 1))
            except IndexError:
                show_message("You have beaten each level in the game! We will now take you back to the first level.")
                current_level = 0
                levels[current_level].begin()

        # Check if player has run out of time
        self.time_remaining -= 0.01
        if self.time_remaining <= 0:
            # Restart the current level
            show_message("Oh no, you have run out of time!")
            levels[current_level].begin()