Python: Please read the following. The Game class The Game class brings together an instance of the GameBoard class, a list of Player objects who are playing the game, and an integer variable “n” indicating how many tokens must be aligned to win (as in the name “Connect N”). The game class has a constructor and two additional methods. The most complicated of these, play, is provided for you and should not be modified. However, you must implement the constructor and the add_player method. __init__(self,n,height,width) The Game constructor needs to initialize three instance variables. The first, self.n, simply holds the integer value “n” provided as a parameter. The second, self.board, should be a new instance of the GameBoard class (described below), built using the provided height and width as dimensions. The third, self.players, should be an initially empty list. add_player(self,name,symbol) The add_player method is provided a name string and a symbol string. These two values should be used to create a new instance of the Player class and to add this new instance to self.players UNLESS either the name or the symbol provided is the same as any of the Players already in self.players. The method should also return a bool indicating whether or not the add was successful. The code is attached in the image below.
Python:
Please read the following.
The Game class
The Game class brings together an instance of the GameBoard class, a list of Player objects who are playing the game, and an integer variable “n” indicating how many tokens must be aligned to win (as in the name “Connect N”).
The game class has a constructor and two additional methods. The most complicated of these, play, is provided for you and should not be modified. However, you must implement the constructor and the add_player method.
__init__(self,n,height,width)
The Game constructor needs to initialize three instance variables. The first, self.n, simply holds the integer value “n” provided as a parameter. The second, self.board, should be a new instance of the GameBoard class (described below), built using the provided height and width as dimensions. The third, self.players, should be an initially empty list.
add_player(self,name,symbol)
The add_player method is provided a name string and a symbol string. These two values should be used to create a new instance of the Player class and to add this new instance to self.players UNLESS either the name or the symbol provided is the same as any of the Players already in self.players. The method should also return a bool indicating whether or not the add was successful.
The code is attached in the image below.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images