def main (): widthSet = False heightSet = False while not widthSet: try: again.") again.") again.") if width = int(input("Enter the width of your game board (4-10):")) if width >= 4 and width <= 10: widthSet = True else: except: while not heightSet: try: print("The width must be an integer from 4-10. Please try print("The width must be an integer from 4-10. Please try again.") height = int(input("Enter the height of your game board (4-10): ")) if height >= 4 and height <= 10: heightSet = True print("The height must be an integer from 4-10. Please try except: else: print("The height must be an integer from 4-10. Please try board Board (width, height) allPlayersAdded = False players = [] while not allPlayersAdded: validName = False while not validName: name = input("Enter this player's name:") validName = True for player in players: Please try again.") if player.getName() == name: name main () validName = False print("There is already a player called " + name if name == "Nobody": validName = False print("You cannot use the name \"Nobody\". Please try again.") newPlayer = Player (name, len(players) + 1) players.append(newPlayer) print("Player " + str(newPlayer.getNumber()) + " is: " + name) if len (players) > 1 and len (players) < 4: addMore=input("Keep adding players (y/n)") if addMore.lower() != "y" and addMore.lower() != "yes": allPlayersAdded = True elif len(players) == 4: allPlayersAdded = True print() print("This game has + str(len (players)) + players:") for player in players: print (player.getName()) game Over = False winner = "Nobody" while not game Over: for player in players: print () print (player.getName() + ", it's your turn:") board.display() player.makeMove (board) winner = player.checkWinner (board) if winner != "Nobody" or board.boardFull(): game Over = True break board.display() input (winner + wins the game!") main
def main (): widthSet = False heightSet = False while not widthSet: try: again.") again.") again.") if width = int(input("Enter the width of your game board (4-10):")) if width >= 4 and width <= 10: widthSet = True else: except: while not heightSet: try: print("The width must be an integer from 4-10. Please try print("The width must be an integer from 4-10. Please try again.") height = int(input("Enter the height of your game board (4-10): ")) if height >= 4 and height <= 10: heightSet = True print("The height must be an integer from 4-10. Please try except: else: print("The height must be an integer from 4-10. Please try board Board (width, height) allPlayersAdded = False players = [] while not allPlayersAdded: validName = False while not validName: name = input("Enter this player's name:") validName = True for player in players: Please try again.") if player.getName() == name: name main () validName = False print("There is already a player called " + name if name == "Nobody": validName = False print("You cannot use the name \"Nobody\". Please try again.") newPlayer = Player (name, len(players) + 1) players.append(newPlayer) print("Player " + str(newPlayer.getNumber()) + " is: " + name) if len (players) > 1 and len (players) < 4: addMore=input("Keep adding players (y/n)") if addMore.lower() != "y" and addMore.lower() != "yes": allPlayersAdded = True elif len(players) == 4: allPlayersAdded = True print() print("This game has + str(len (players)) + players:") for player in players: print (player.getName()) game Over = False winner = "Nobody" while not game Over: for player in players: print () print (player.getName() + ", it's your turn:") board.display() player.makeMove (board) winner = player.checkWinner (board) if winner != "Nobody" or board.boardFull(): game Over = True break board.display() input (winner + wins the game!") main
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 2GZ
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 5 steps with 10 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT