Harry Potter
A better way to prepare for coding interviews.
Connect Four is a popular game played on a 7x6 grid. Two players take turns dropping colored discs into the grid. The first player to get four discs in a row (vertically, horizontally or diagonally) wins.
Some possible questions to ask:
We will use an enum to represent the GridPosition.
The Grid will maintain the state of the board and all of the pieces. It will also check for a win condition. Perhaps it would be more appropriate to name the checkWin
method to checkNConnected
, since the Grid itself shouldn't need to know what the rules of the game are.
A Player is only mean to encapsulate the player's information, more importantly the player's piece color.
The Game class will be used to play the game. It will keep track of the players, the score, and the grid. It will also be responsible for the game loop. The game parameters passed in via the constructor give us flexibility to play the game with slightly different rules and dimensions.
While we could instantiate the board within the Game class, it's preferred to pass it in via the constructor. This means the Game class does not need to know how to instantiate the board.
Even though we are only playing with two players, we can still use a list to store the players. This is not necessary, but it's easy enough and gives us flexibility to add more players in the future.
Finally, we can create the grid, set the game parameters, and play the game.
Wait a second...
Watch 👉How to download video
Password can be one of these :- CheapUniverse OR FreeCourseUniverse
If u face any issues with the link, email us at - harry@freecourseuniverse.com
Hey Guys We are Tech Enthusiasts and we know knowledge is key to success ! We are here to open path to your success by providing what you want. Today education == business. Our moto is education should be accessible by any person who is not able to purchase overpriced content.
© 2023 CheapUniverse. All Rights Reserved