def get_a_game(player_id): if len(players)%2 == 0: game = str(uuid4().hex) games[game] = BattleshipGame() player_numbers[player_id] = 1 join_room(game) send_alert("New Game started waiting on player two.") return game else: seen_games = {} for (player,game) in players.items(): if game in seen_games: seen_games[game]= seen_games[game] + 1 else: seen_games[game]=1 for (game, count) in seen_games.items(): if count == 1: player_numbers[player_id] = 2 join_room(game) send_alert("Game ready, place ships!", game) return game
__author__ = 'Aidan McRitchie, [email protected], Onyen = mcaim' from battleship import BattleshipGame # Ask the user how many players will be playing the game. print("*************** Welcome to BATTLESHIP! ***************") num_of_players = None while num_of_players == None: try: num_of_players = int( input("Would you like to play with 1 player or 2? ")) if (num_of_players != 1) and (num_of_players != 2): raise Exception() except: print("You must enter either 1 or 2. Please try again.") num_of_players = None # Create the new game for the correct number of players. Then start the game! game = BattleshipGame(num_of_players) game.play()
from battleship import BattleshipGame bsg = BattleshipGame() # Test 1: should have created a board with 3 "S" markers ship_location = [] for i in range(bsg.size): for j in range(bsg.size): if bsg.board[i][j] == "S": ship_location.append((i, j)) if len(ship_location) == 3: print("Pass") else: print("Fail") # Test 2: ship should be all in one row or in one column assert len(ship_location) == 3 ship_location.sort() if ship_location[0][0] == ship_location[1][0] and \ ship_location[0][0] == ship_location[2][0] and \ ship_location[0][1] == ship_location[1][1] - 1 and \ ship_location[1][1] == ship_location[2][1] - 1: print("Pass") elif ship_location[0][1] == ship_location[1][1] and \ ship_location[0][1] == ship_location[2][1] and \ ship_location[0][0] == ship_location[1][0] - 1 and \ ship_location[1][0] == ship_location[2][0] - 1: print("Pass") else: print("Fail")
__author__ = 'Zhenwei Wang, [email protected], Onyen = wangzw1' from battleship import BattleshipGame # Ask the user how many players will be playing the game. print("*************** Welcome to BATTLESHIP! ***************") num_of_players = None while num_of_players == None: try: num_of_players = int(input("Would you like to play with 1 player or 2? ")) if (num_of_players != 1) and (num_of_players != 2): raise Exception() except: print("You must enter either 1 or 2. Please try again.") num_of_players = None # Create the new game for the correct number of players. Then start the game! game = BattleshipGame(num_of_players) game.play()