classes

Pages: 12
to a typical game of pairs card game how many classes would i initially need to for the whole thing :)
what i taught of so far is
class deck
class getPlayerinfo
class gameApplication
do i need an other class for shuffling as well?
The design of any sufficiently complicated program becomes more subjective than objective. There are generally good practices, but there is usually never anything you need to do.

In most cases, I find it odd to have a class with a verb in it -- "getplayerinfo". When you see verbs like that, generally that suggests function names. Perhaps the class should just be called "playerinfo" and you have a separate function that can then be used to fill that player info with data.

If the gameApplication owns one or more decks of cards, then perhaps the gameApplication class should have a function called "shuffleDeck".

Also, if the deck is a collection of cards, perhaps it makes sense to have a card be a class (or, maybe an int/enum would do, depending on what the actual cards are used for).
Last edited on
no, shuffle should be a member of a deck of cards.

classes represent 'things' , functions are 'actions' though this can be very loose terminology.

the how many question is useless: we don't know enough about your design or needs. The number of classes is 'how many things do I need to represent to make my program'. Less is more, usually... you probably don't need more than 5 total classes, depending on what else you have going on in the code, and 3 may be fine, or even 2 (deck looks like a wrapper for vector, does it DO anything?).
Last edited on
Ganado & jonnin i made this description for my project :) so can i get anymore ideas the ones you have explained also helped me to get an idea thank you :)

the basic game play is as follows:
All the player gets 1 card in the beginning of the first round.the card with the lowest value gets to go first .
If there's a tie , the players that has those cards should be dealt another card and then the player with the least value gets to go first
If the tied players get an pair while dealing the cards should be declined and has to be dealt with another card to that player

After the card are dealt and the player who goes first is decided you can start playing the game
Either you can “HIT” or “FOLD”
Hitting: When you hit you have to get a card from the deck hoping not to get a pair.

Pair: getting two cards of the same type.that will add up to your score

NOTE :- To avoid losing, test your luck or fold because your goal is not to reach the target score.

Folding: When you fold you have to get the least valued card in play
and that card value will be added to your score.

A round ends if someone decides to fold or get a pair

When the deck ends it gets the discarded cards again and deals them .

And most importantly this game has no winners, it only has one loser and that is gonna be the person who reaches the target score that varies from the number of players. So the goal is to score less as possible.
how are you representing a 'hand' ?
I'd start with these classes: Card, Hand, Player, Game.

I'd represent the value of a card with an integer between 0 and 51. Add value() and suit() methods that return the face value and suit.

A "hand" is a collection of cards (probably a vector). The deck itself is a hand, along with the hands of the players, the discard pile, whatever. Hand has a shuffle() method and a deal method that removes the top card (probably the card at the back of the vector) and returns it.

A player has a hand and a score and whatever else they need. The value to decide whether to hit or fold should be virtual. That way you can have Human players and Computer players.

A Game has two players, a deck, a discard pile, a method to select the first player and a method to have the two players play a game

And so forth and so on.
https://www.youtube.com/watch?v=bq7Em3p7oS0
this is not a normal card game so im kinda having a hard time wrapping my head around this theory and the video above explains about the game Jonin & dhyden thank you both :)
feel free to share more ideas
It isn't a standard deck, so your Card class might have just the value of the card.

Notice how powerful the Hand class is. You can use it to represent the deck, the discard pile, the players' hands, and the cards that they've accumulated that count for points.

It seems that the part you're struggling with is the actual game play. You might learn about top-down or bottom-up programming. You can also work from inputs to outputs, or from outputs to inputs. I find it easiest to do all of the above, so it's like peeling an onion. Think about what you need from all of these perspectives. Then work your way in.

For example. You have multiple players so you need vector<Player> players.
And you need to determine who goes first: getFirstPlayer(). And you need to know who is the current player: curPlayer.

A human player either hits or folds. Since a lot happens to the game when a player does this, I'd make these members of the Game class: hit(Player&) and fold(Player&).

When a player folds they take the lowest card on the table. What if there are ties? How will you enforce that they take the lowest? Maybe make a method for that. As a first cut, I'd say it tranfers the lowest card to the player. If multiple opponents have the same lowest card, it prompts the player for which one he/she wants to take: Game::takeLowest(Player &)

And a method to see if anyone has lost: Player *loser()

I'd start with those. Then go through the rules (or the video) again and see if there's anything useful that's missing. Then start writing and testing the code.
thank you!! dhayden ill keep you updated cus you helped me alot to get the perspective of the game :)
if you go that route, hand is a good variable name, but the class name may need to be more generic (just style/readability minor nitpick).
if you go that route, hand is a good variable name, but the class name may need to be more generic
I agree completely. CardStack? Cards? CardCollection? Something like that is less biased.
Outline the Functionality of Classes

For my project after understanding the requirements and its functionality into consideration,
I have decided to have 3 classes in my game and those are,

Player class: This class will get player information such as how many players will be playing and their information(names).this will simplify the complexity of the functions used in the game due to this information being used in mostly every function that we will be creating.This class will also hold their individual score so that will be easier to keep track of players individual scores.

Card class: this class will be used to represent the deck of cards that we will use to play the game and the current hand of the players.This deck has to be randomly dealt to the players so this will also include the ‘shuffling’ function as well.when a player decides to fold or when they get a pair the cards get discarded and those cards also should be able to be used again once the deck that is in play runs out of cards so i will also include the ‘discarded cards’.Having all the functions related to this deck of cards will be an advantage when programming the player interactions with the deck.

Application file: this is where the game will be assembled and the classes that we have created earlier will be used accordingly so we can have a proper functioning game as an end result.this is also the place where the game will start to get its interface by getting defined by the created classes and the functions.I will be using the proper methods that has to be followed in order to get the expected outcome without any errors.I will be using comments during completion so it will be easy for another programmer to get an idea of what i have done to get this output.







The Game Setup
Open the menu and display the menu interface having the options,
Option 1 - How to play “Pairs”
Option 2 - Start game.
Option 3 - Exit Pairs .
When ‘Option 1’ is selected it will display what's inside the “How_To_Play.txt” which explains how to play the game.This will be done in “displayHowToPlay()” function.

When ‘Option 2’ is selected it will start the game.and it will start,
Processing player input
I will be using these functions to process player inputs throughout the game,
Int menu(int option);
This is to get players input to select the options from the menu.
int getNoOfPlayers(int number);
This is to get how many number of players in the game
string getName(string name) ;
This is to get the player names.
char getOption(char option);
This is to get the options either they hit , fold or quit the game
char playAgain(char answer);
This is to after the end of the game to get the input of the player if the player wants to play again.

Based on the player’s response, the game will perform the required action
The player's decision will be processed in this function either to play the game or show how to play or quit the game
.
If the player decides to choose to start the game it gets the input of the player to get how many players will be playing and it will move to the next step of getting their names.

getting the names will be done in the “getName” function so it can start the process of getting the names and creating the players in the player class.

After starting the game the player gets either to hit fold or quit the game those inputs will be taken in and those will be processed and the output of that chosen input will be shown.

In the end of a complete game the player will get an option to play again or quit there according to the input it will get processed and the game either will start again from the beginning or the program will exit.




The Player’s turn
After that that will lead to the start of the actual gameplay.Starting with dealing their first hand and identifying the first person who gets to play this will be processed inside the “getFirstPlayer()” function.

output
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pairs::Target score = 31
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Name :- Cooldood94 Score:- 0
Hand: [6]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Name:-Cooldood95 Score:- 0
Hand:[1]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cooldood95, Will you [H]it or [F]old or [Q]uit (H/Q/F) :-

After the first person who will be playing will be decided the player will get 3 options.either to Hit Fold or Quit .

Providing feedback to the player
The player will have three options either to “HIT” or “Fold”or “Exit game now”.
HIT :This option will allow the player to get a card from the deck that will be done in the function ”hit(player&)” in the application file.
FOLD: This Option will let you get the card out of all the players hands that will be done in the function “fold(player&)”in the application file.
Quit: Player will leave the game.this will be done in “exitGame()”function.

Display the result if “HIT” selected.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pairs::Target score = 31
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Name :- Cooldood94 Score:- 0
Hand: [6] [9]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Name:-NotsoCooldood94 Score:- 0
Hand:[1]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CoolDood94, Will you [H]it or [F]old or [Q]uit (H/Q/F) :- H

if they hit and get a pair the existing hand of the players will be moved to the discarded cards(class cards,discardedCards()). But the person who got the pair will be left with the card that he last took by using “HIT”as a way of keeping score and that won't be going to the discarded cards pile. After that they will be dealt with new cards.
If the deck original deck runs out of cards after rounds . the discarded pile has to be back and the top 5 cards have to be burned. “burnCards()”function is there for that .
Display the result if “Fold” is selected
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pairs::Target score = 31
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Name :- Cooldood94 Score:- 1
Hand: [10]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Name:-NotsoCooldood94 Score:- 0
Hand:[2]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CoolDood94, Will you [H]it or [F]old or [Q]uit (H/Q/F) :- F

When the player folds

Display the result if “Quit” is selected
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pairs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Come back to play again :)
Good bye !!!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CoolDood94, Will you [H]it or [F]old or [Q]uit (H/Q/F) :- Q

If they fold the card that player took will add up to the score and this card will be kept as a way of keeping score and the other players hands will be discarded and those will go to the discarded cards pile and they will again be dealt with new cards.

Display the result if “Quit” is selected

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
YOU ARE SO LUCKY :)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_______
| |
(| YOU!! |)
| WON!! |
\ /
`---'
_|_|_
YOU WON!!!!!!Cooldood95
HAVE A WALK YOU MIGHT FIND A PENNY
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do you wanna play again (y/n)?
Display the result if when a player reach the target score
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
YOUR SO UNLUCKY :(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.--'''''''''--.
.' .---. '.
/ .-----------. \
/ .-----. \
| .-. .-. |
| / \ / \ |
\ | .-. | .-. | /
'-._| | | | | | |_.-'
| '-' | '-' |
\___/ \___/
_.-' / \ `-._
.' _.--| |--._ '.
' _...-| |-..._ '
| |
'.___.'

YOU LOST!! Cooldood94 GOOD LUCK NEXT TIME!!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do you wanna play again (y/n)?


These ascii art will be read into the program by putting these to text files “Loser_Face.txt” and “Winner_Trhophy.txt”.

The end game conditions

Rounds will continue until one player loses the game by reaching the target score.this has to be checked each round to see when the game should stop and show the losing player's name this will be done in “checkLoser()”function or either using a pointer ”Player *loser()”

When a game ends if the player,
WIN: Show the winners display
LOOSE: Show the losers display
To find these” gameOutCome() “will be used.

The game will be running till the above conditions are met.
this is what i have come up with so far
Player class: This class will get player information such as how many players will be playing and their information(names).

This doesn't seem right. A class called Player would, presumably. model the properties and behaviour of a player. A player doesn't have a number of players - it's a single player. A player would have a name, not a list of names.

It sounds like you want is a Game class. A game has players. A game would know the number of players, and those players' details - presumably, stored as a list of Player objects, each of which contains a name.
Your description seems to indicate that the Card class represents a collection of cards, not just one. And why does the Player class get the number of players? If the Player class is a single player then conceptually, why do you ask an individual player how many players there are? Determining the number of players is the job of the Game class (which you didn't mention).

These are small comments. Overall it's looking good. At this point you should start to define the data and methods of all the classes.

If this is an assignment, can you post the text of the assignment? We might spot something important that you haven't seen.
In this program, the computer (dealer) controls a triangular deck of cards. The deck is made up of 1x1, 2x2s, 3x3s, all the way up to 10x10s, making a deck of 55 cards. This is NOT a standard deck of playing cards. The basic game play is as follows:  Shuffle the deck and burn (discard) five cards, facedown, into the middle of the table. This creates the start of the discard pile. Each time you reshuffle, you will burn five cards. This makes it harder for players to guess what cards are left at the end of the deck.  To start each round, deal one card face up to each player. The player with the lowest card will go first. If there is a tie for lowest card, deal a second card to the tied players to break the tie. If the second card creates a pair, discard it and deal another.  Example: In the diagram at right, Player A is dealing. She shuffles the deck and burns five cards into the middle. She then deals one card to each player, face up. Player D will go first because she has the lowest card, a 6.
 On your turn: you have two choices – you may hit (take a card), or fold (end the round).  If you get a pair, or fold, the round is over and you score points.  If not, play passes to the left.
 Hitting: When you take a hit, you’re hoping not to get a pair. If you catch a pair, the round ends, and you score points equal to the rank of the paired card.  For example, if you catch a pair of 8’s, you score 8 points. Keep one of those cards aside face up, to track your score.  Folding: You can surrender (fold) instead of taking a card. This also ends the round. When you fold, you must take the lowest card in play and keep it for points. You may choose this card from any player’s stack, including your own.
 Folding can be better than hitting, depending on your odds of catching a pair, but it’s up to you to decide when to do it.
 Ending the Round: As soon as one person catches a pair or folds, the round is over. Discard all the cards in players’ stacks, face down into the middle, and deal another round.  Scoring cards (those cards that were kept aside for points) are not discarded.
 Reshuffling: When the deck runs out, just shuffle and continue. Pause the deal, reshuffle the discards, and resume dealing where you left off. (Remember to burn five cards.)
 Losing the Game: There is no winner, just one loser. The game ends when one player reaches the target score. This number changes with the number of players. The formula for 2 to 6 players is: (60 ÷ number of player) + 1. For 7 or 8 players, keep the value at 11. Players: 2 3 4 5 6+ Score: 31 21 17 13 11  For example, in a 4-player game, the loser is the first player to score 16 points.
 Breaking a Tie: If 2 or more players are tied for the lowest card, deal additional cards to the tied players, and use those cards a tie-breakers. If the tie-breakers are tied, deal more cards until one player has the lowest card. If someone gets a pair during this process, discard the paired card and deal a replacement. Players cannot be knocked out by a pair during this process, although they can sometimes wind up with several extra cards!
 Dealing: deal cards in a consistent order, starting with the first player, and continuing in clockwise order around the table. Deal tie breaking cards in the same order.
 Pair: any 2 cards in a single player’s stack that have the same rank – the cards do not have to be next to each other to be a pair. Other players may have the same value card but this is not classed as a pair in this game. There are many variations to this basic game, some of which you will be able to implement as part of the extra functionality for your assignment
A development outline of your game Using a simple outline format (numbered or bullet points) state the main actions that the program will have and then, as sub-points, state the things you will need to do to make that happen. The outline structure should contain all the elements of your game, as this is a high-level description of your approach to the development of your program. You should include at least the following headings and provide examples of happens under each section.  The game setup (everything that happens before the game starts)  The player’s turn (the sequence of events that happen during a turn)  Processing player input (include each of the commands your player can use)  Providing feedback to the player (in response to the player’s interactions)  The end game conditions (include all win and lose conditions)  Additional Features included, if any – see Assignment 3  Outline the functionality of all your game classes – see Assignment 3 Here is an example to get you started with your project outline: o The Game Setup  Display an overview of the game rule so the player knows what to do to win.  read this information from a text file  Initialise the game elements:  add the player – ask for the player’s name, set default variables  all the other things that will happen during initialisation including  creating the characters and the game world  initialising other game variables (list them here) As you can see, you only have to describe the actions the program will take, not the code, for the outline. The idea here is to give you a starting point for when you start writing your code as you can use this as a checklist of the things you need to include
this is a text file of my assignment dhyden and i didnt quite get what you said in this game thers no ai that an additonal task in the end so your gonna be players ranging from 1 to 8 was like when you ask how many players it asks the player to fill their names then he has to play for all the players i hope it made sense
Last edited on
I assume the original was considerably better formatted than that... and hence a lot easier to read?
Pages: 12