Ejemplo n.º 1
0
 def __init__(self,num_players):
     self.current_round = 0
     self.map_grid = Map_grid()
     self.mission_factory = Mission_factory()
     self.underling_factory = Underling_factory()
     self.shop = Shop(self.underling_factory)
     self.num_players = num_players
     self.players = []
     for player_num in range(self.num_players):
         self.players.append(Player(player_num,self.shop,self.map_grid,self.mission_factory))
         self.players[player_num].give_resources(('w',1))
         self.players[player_num].give_resources(('s',1))
         self.players[player_num].give_resources(('g',1))
     assert(NUM_MISSIONS_EACH > NUM_MISSION_TYPES)
     #Give each player one mission of each type
     for mission_type in range(NUM_MISSION_TYPES):
         for a_player in self.players:
             a_player.give_mission(self.mission_factory.get_mission(mission_type))
     #Give each player the rest of their missions
     for mission in range(NUM_MISSIONS_EACH-NUM_MISSION_TYPES):
         for a_player in self.players:
             a_player.give_mission(self.mission_factory.get_mission())
     #Give players a copy of the starting Underlings
     for underling in range(NUM_UNDERLINGS):
         for a_player in self.players:
             a_player.gain_underling(self.underling_factory.get_underling(0,underling).copy())
     self.start_player = randint(0,self.num_players-1)
     self.current_player = self.start_player
Ejemplo n.º 2
0
class GameObject:
    def __init__(self,num_players):
        self.current_round = 0
        self.map_grid = Map_grid()
        self.mission_factory = Mission_factory()
        self.underling_factory = Underling_factory()
        self.shop = Shop(self.underling_factory)
        self.num_players = num_players
        self.players = []
        for player_num in range(self.num_players):
            self.players.append(Player(player_num,self.shop,self.map_grid,self.mission_factory))
            self.players[player_num].give_resources(('w',1))
            self.players[player_num].give_resources(('s',1))
            self.players[player_num].give_resources(('g',1))
        assert(NUM_MISSIONS_EACH > NUM_MISSION_TYPES)
        #Give each player one mission of each type
        for mission_type in range(NUM_MISSION_TYPES):
            for a_player in self.players:
                a_player.give_mission(self.mission_factory.get_mission(mission_type))
        #Give each player the rest of their missions
        for mission in range(NUM_MISSIONS_EACH-NUM_MISSION_TYPES):
            for a_player in self.players:
                a_player.give_mission(self.mission_factory.get_mission())
        #Give players a copy of the starting Underlings
        for underling in range(NUM_UNDERLINGS):
            for a_player in self.players:
                a_player.gain_underling(self.underling_factory.get_underling(0,underling).copy())
        self.start_player = randint(0,self.num_players-1)
        self.current_player = self.start_player
    def __repr__(self):
        return '\n'.join([str(self.map_grid),str(self.mission_factory),str(self.underling_factory),str(self.shop), '\n'.join((str(p) for p in self.players))])

    def all_players_passed(self):
        return all((player.is_passed() for player in self.players))

    def new_round(self):
        self.current_round += 1
        self.shop.new_round(self.current_round)
        for player in self.players:
            player.new_round()
        self.start_player = (self.start_player + 1)%self.num_players
        self.current_player = self.start_player
    def next_player(self, clockwise=True):
        if self.all_players_passed():
            return None
        delta = 1 if clockwise else -1 + self.num_players 
        self.current_player = (self.current_player + delta) % self.num_players 
        while self.players[self.current_player].is_passed():
            self.current_player = (self.current_player + delta) % self.num_players 
        return self.current_player
    def get_current_player(self):
        return self.players[self.current_player]
    def place_initial_settlements(self):
        for i in range(NUM_INITIAL_PLACEMENTS):
            if i % 2 == 0:
                clockwise = True
            else:
                clockwise = False
            for j in range(len(self.players)):
                all_tiles = self.map_grid.valid_initial_placement(self.current_player)
                show_tiles(self.map_grid,all_tiles)
                additional_options = ['Automate Player','view Player','Show map']
                selection = ''
                while selection == '' or selection in additional_options: 
                    selection = selectionMaker('Player {} Initial Placement'.format(self.current_player),additional_options+all_tiles,self.get_current_player())
                    if selection == additional_options[0]:
                        self.get_current_player().do_automate()
                    elif selection == additional_options[1]:
                        print self.get_current_player()
                    elif selection == additional_options[2]:
                        show_tiles(self.map_grid,all_tiles)
                #selection = all_tiles[0]
                self.get_current_player().give_tile(selection)
                self.next_player(clockwise)
            self.next_player(not clockwise)
    def score_rewards(self, player, number_of_rewards):
        for n in range(number_of_rewards):
            if self.current_round  <= 4:
                player.give_score(6)
                player.give_resources(('s',1))
                player.give_resources(('w',1))
                player.give_resources(('g',1))
            elif self.current_round <= 7:
                player.give_score(5)
                player.give_resources(('s',1))
                player.give_resources(('w',1))
            else:
                player.give_score(4)
        
    def scoring_round(self):       
        for player_offset in range(self.num_players):
            selection_options = []
            player_num = (player_offset+self.start_player)%self.num_players
            player = self.players[player_num]
            missions = player.get_missions()
            for mission in missions:
                mission_result = self.map_grid.find_max_number_groups(player_num,mission.points,mission.check_condition)
                if mission_result != None:
                    selection_options.append((mission,mission_result))
            
            selection = selectionMaker('Mission to Score',['None']+selection_options,player)
            if selection == 'None':
                #TODO
                pass
            else:
                mission, groups = selection
                self.score_rewards(player,len(groups))
                mission.scored()