def __init__(self, num_players, difficulty): self.board = Board() self.storm = Storm(num_players, difficulty) self.players = [] #shuffle(self.abilities) equipment_deck = EquipmentDeck() for i in range(num_players): self.players.append(Player(self.abilities[i], self.board, equipment_deck)) self.__set_players_starting_spaces__() self.finishing_pieces = [] #When all 4 are collected, the game can be won
class Game: abilities = ["Navigator", "Water Carrier", "Explorer", "Climber", "Archaeologist", "Climber"] def __init__(self, num_players, difficulty): self.board = Board() self.storm = Storm(num_players, difficulty) self.players = [] #shuffle(self.abilities) equipment_deck = EquipmentDeck() for i in range(num_players): self.players.append(Player(self.abilities[i], self.board, equipment_deck)) self.__set_players_starting_spaces__() self.finishing_pieces = [] #When all 4 are collected, the game can be won def __set_players_starting_spaces__(self): starting_tile = self.board.get_starting_tile() for player in self.players: player.current_tile = starting_tile starting_tile.players_on = self.players def run_game(self): while(True): for player in self.players: print "STARTING PLAYER TURN: %s" % player.ability self.play_turn(player) save_game(self) def play_turn(self, player): player.solar_shielded = False actions_remaining = 4 while actions_remaining > 0: self.board.print_board() self.check_for_victory() self._print_player_info(player, actions_remaining) action, direction = self.get_action(player) valid, sand_removed, additional_actions = player.make_action(action, direction, self.players, self.storm) self.storm.sand += sand_removed if valid: actions_remaining -= 1 actions_remaining += additional_actions self.draw_cards() def _print_player_info(self, player, actions_remaining): print "Storm Level: %d, Sand Remaining: %d, Cards in Storm Deck: %d" % (self.storm.storm_level, self.storm.sand, len(self.storm.face_down_storm_cards)) print "Player: %s, Water: %d, Actions Remaining: %d" % (player.ability, player.water, actions_remaining) print "Equipment cards: " + str(player.equipment) def draw_cards(self): storm_increments = 0 for i in range(self.storm.this_turn_storm_level): self.board.print_board() to_use = "init" while to_use != "": to_use = raw_input("Press ENTER to Draw Card... (E[Q]uipment, [D]isplay info, [S]hare) ").lower().strip() if to_use == "q": self.players[0].use_equipment(self.players, during_storm_cards=True) elif to_use == "d": self.players[0].display(self.storm, self.players) elif to_use == "s": self.players[0].select_sharer(self.players) card = self.storm.draw_card() if card == "Sun beats down": print card for player in self.players: if (not player.current_tile.tunnel or not player.current_tile.excavated) and not player.is_solar_shielded(): player.water -= 1 print "%s: %d water remaining." % (player.ability, player.water) if player.water < 0: print "\n\nYou have lost! %s has run out of water!" % player.ability exit(0) elif card == "Storm picks up": print card storm_increments += 1 else: #Move stuff move_direction = card[0] move_amount = card[1] storm_center_tile = get_storm_center(self.board.tiles) print move_amount, if move_direction == "n": print "v" elif move_direction == "s": print "^" elif move_direction == "w": print "->" elif move_direction == "e": print "<-" for i in range(move_amount): x_delta = 0 y_delta = 0 if move_direction == "n": y_delta = -1 elif move_direction == "s": y_delta = 1 elif move_direction == "w": x_delta = -1 elif move_direction == "e": x_delta = 1 if storm_center_tile.position["row"] + x_delta < 0 or storm_center_tile.position["col"] + y_delta < 0: break if storm_center_tile.position["row"] + x_delta > 4 or storm_center_tile.position["col"] + y_delta > 4: break else: card_to_move = get_tile(self.board.tiles, [storm_center_tile.position["row"] + x_delta, storm_center_tile.position["col"] + y_delta]) self.board.switch_tile_positions(storm_center_tile, card_to_move) self.storm.sand -= 1 # Raise storm level for i in range(storm_increments): self.storm.increment_storm_pointer() if self.storm.storm_level == "Death": print "\n\nYou have lost! Storm level has reached max storm!" exit(0) self.storm.this_turn_storm_level = self.storm.structure[self.storm.storm_pointer] def check_for_victory(self): num_parts = 0 for player in self.players: if not player.current_tile.is_escape_point: return False num_parts += len(player.ship_parts) if num_parts == 4: print "Vroom! You have won!" exit() else: return False def get_action(self, player): direction_list = "n/s/e/w" if player.ability == "Explorer": direction_list = "n/s/e/w/nw/ne/se/sw" tunnel_travel = "" if player.current_tile.tunnel and player.current_tile.excavated: tunnel_travel = "/t" player_ability = "" if player.ability != "Archaeologist" and player.ability != "Climber" and player.ability != "Explorer": player_ability = ", [U]se ability" print "Options: [E]xcavate, [C][%s/c]lear sand, [M][%s%s]ove, [P]ickup, E[Q]uipment, [D]isplay info, [S]hare%s" % (direction_list, direction_list, tunnel_travel, player_ability) user_input = raw_input("Select your move: ").lower() action = None if len(user_input) > 0: action = user_input[0] direction = None if len(user_input) > 1: direction = user_input[1:] return action, direction