I was trying to implement the Sorry! board game using C++ such that 4 players (Includes computer as one of the player) could play the game over a network and there is also a score board and a message board for the players to chat.
The main idea is to crystallize my understanding of C++ and use almost all OOP concepts while implementing this game.
I was trying divide the problem into classes and had 2 questions:
1. Each player green, yellow, blue, red have 4 pieces each. Is each piece a class or green1class, green2 class ….. or is it just that each color is a class and each piece of the same color is just an instance of the class.
2. Also How do I start dividing a generic problem like this into classes?
Start thinking in objects, and in a “is a” and “has a” manner kind of like this:
A game piece is an object
A player is another object.
A player has 4 game pieces.
A player has a color
A gameboard is an object.
A gameboard has spaces.
A gameboard has 4 players
And so on. As you get used to thinking in a “is a” and “has a” manner, it gets easier.
Also try to break down things to the lowest level – if every player has a color, then maybe player should be an object that has a color, instead of 4 player objects based on color
Do this (I know this is not proper c/c++ code, but it demonstrates the ides):
instead of
etc.