If you don't want to read all this, just look at the bottom part :-P
I'm currently making a Tic Tac Toe game, just for fun, and ran across an interesting subject(for me). I have a method in class Player that can be used for two uses. It can check for a win and check for a possible win. Once it finds a possible win, it puts the X and Y coords of that possible win into a variable, located in the class. But what if I wanted to fulfill a second use of this function and store those X and Y variables in a different class instance of Player, allowing the other player to block that attack? That is to say, this way the function can be used to see if a player can possibly win, or if a player can possibly block a win, and give the exact coordinates of these events. Ok, onto the point: In order to do this, my first idea was to include an optional parameter.
So the prototype would be:
Expand|Select|Wrap|Line Numbers
- checkForWin(board& gameBoard, player &opponent);
Hope this was clear.
Thanks,
Austen