I'm fiddling with a simple implementation of the card game War, and I've hit a bit of a snag: how best to arrange the classes representing the individual player decks, and the play field itself.
As it stands, the Deck class contains a nested struct(linked list) to hold the values for each card in a player deck. This class also contains standard member functions for determining if the player is a winner or loser, as well as adding cards to the deck and playing a card(removing the top card).
The PlayField class is where I'm stuck. This class "has a" Deck (two, actually)
but it also "is a" deck, in that it also has a linked list to hold the values of the cards being played, as well as several Deck class methods.
In each round of the game, the top cards of each are removed, and the card values they contained are sent to the PlayField list, where they are compared. Then, the winner gets both cards (they are added to the end of the winner's list). However, when both cards played have the same value, a tie-breaker occurs. The top 3 cards of each deck are removed, and each player chooses 1 of those cards and their values are revealed. If a player's deck has less than 3 cards remaining, then all the cards of that deck are choosen. The values of the choosen cards are compared, and the winner gets all the cards in play.
The Problem: I can't think of a nice way to implement the PlayField list to track which cards in the list belong to which player. Should I just use an array of strings instead? I'd like to use linked lists all the way, if at all possible (as this is primarily a study piece in linked lists, for my own understanding), but am amenable to other possibilities.
if you know how to use classes this should be very easy ...
just make a class Player and a class Computer ... each having a int iHorC ; which will be 0 or 1 depending on whether the player is human or computer ... and make class Card which will get the same variable iHorC ...
i don't think it's the most efficient way to do this ... but it's definetely a solution ...
btw ... for starters i'd recommend reading Michael Dawson's book