151 lines
No EOL
5.1 KiB
C++
151 lines
No EOL
5.1 KiB
C++
/*
|
||
Program Name: Go Fish
|
||
Process: Does the following according to spec:
|
||
Players take turns asking their opponent for a specific card. The game will continue until all sets are
|
||
collected.
|
||
Here are the rules of the game:
|
||
● Use a 52-card deck
|
||
● Deal 7 cards to each player (human and computer).
|
||
Each play will take turns asking for a card rank/number from the opponent. If the opponent has the card
|
||
that is requested, they must hand over all the cards of that rank/number. If the opponent does not have the
|
||
card requested, then the player number “go fish” meaning they must draw a card from the deck. If a
|
||
player collects a set of four cards of the same rank, they will lay down the set and earn a point. The game
|
||
will end when all sets have been collected.
|
||
Function requirements:
|
||
● humanTurn
|
||
○ Handles the human’s turn. It will prompt the player to ask for a card rank/number and
|
||
check if the computer has the requested rank/number. If the card is available in the
|
||
computer’s hand, it will transfer the card to the human’s hand otherwise, it will draw a
|
||
card. The function should return the number of sets collected during the turn
|
||
● computerTurn
|
||
○ Handles the computer’s turn and it should do the same actions as the human but for the
|
||
computer. The function should return the number of set that is collected during its turn.
|
||
Function Input/Parameters: ???
|
||
Function Output/Parameters: ???
|
||
Function Output/Returned: ???
|
||
Device Input/Device: ???
|
||
Device Output/Monitor: ???
|
||
Dependencies: ???
|
||
*/
|
||
|
||
#include <cstdio>
|
||
#include <cstdlib>
|
||
#include <iostream>
|
||
#include <cstring>
|
||
#include <vector>
|
||
#include <time.h>
|
||
|
||
using namespace std;
|
||
|
||
// function prototypes
|
||
|
||
// class definitions
|
||
class Card
|
||
{
|
||
//
|
||
public:
|
||
Card(char value, char suit)
|
||
{
|
||
// store the value and suit. (possible values 2-9, T, J, Q, K, A)
|
||
cardValue = value;
|
||
cardSuit = suit;
|
||
// special 1/Ace card here
|
||
if(cardValue == 'A')
|
||
{
|
||
cardNumericalValue = 1;
|
||
}
|
||
// get the numerical value of the card, casting from string to num where possible. (2-9)
|
||
if((cardValue >= 2) || (cardValue <= 9))
|
||
{
|
||
// cast the character to number.
|
||
cardNumericalValue = (int)cardValue - 48; // numerical values 2-9 only
|
||
}
|
||
// face values here.
|
||
if(cardValue == 'T')
|
||
{
|
||
// 'ten' card
|
||
cardNumericalValue = 10;
|
||
}
|
||
if(cardValue == 'J')
|
||
{
|
||
// jack
|
||
cardNumericalValue = 11;
|
||
}
|
||
if(cardValue == 'Q')
|
||
{
|
||
// queen
|
||
cardNumericalValue = 12;
|
||
}
|
||
if(cardValue == 'K')
|
||
{
|
||
// king
|
||
cardNumericalValue = 13;
|
||
}
|
||
}
|
||
private:
|
||
char cardValue;
|
||
char cardSuit;
|
||
int cardNumericalValue;
|
||
};
|
||
|
||
// main program
|
||
int main(int argc, char **argv)
|
||
{
|
||
// create array of cards called deck.
|
||
vector<Card> deck;
|
||
// have two hands for cards
|
||
vector<Card> humanHand;
|
||
vector<Card> computerHand;
|
||
// game setup
|
||
// create deck by loop for 1 - 13 with each suit {(H)earts, S(pades), C(lubs), D(iamonds)}.
|
||
// use double for loop, outer for suits, inner for values.
|
||
// shuffle deck randomly? (use shuffle function from vector library)
|
||
// deal hands by taking each card from the deck, one by one (7x) (for loop here.)
|
||
// main gameplay loop (while?)
|
||
// ask for card rank/number/value
|
||
// if card is in hand,
|
||
// return 0
|
||
return 0;
|
||
}
|
||
|
||
// compiles using "g++ -Wall -pedantic go_fish.cpp -o go_fish" - note to programmer
|
||
|
||
/*
|
||
Function Name: humanTurn
|
||
Process: ???
|
||
Function Input/Parameters: ???
|
||
Function Output/Parameters: ???
|
||
Function Output/Returned: ???
|
||
Device Input/Device: ???
|
||
Device Output/Monitor: ???
|
||
Dependencies: ???
|
||
*/
|
||
void humanTurn()
|
||
{
|
||
/*
|
||
Handles the human’s turn. It will prompt the player to ask for a card rank/number and
|
||
check if the computer has the requested rank/number. If the card is available in the
|
||
computer’s hand, it will transfer the card to the human’s hand otherwise, it will draw a
|
||
card. The function should return the number of sets collected during the turn
|
||
*/
|
||
// void function, no return.
|
||
}
|
||
|
||
/*
|
||
Function Name: computerTurn
|
||
Process: ???
|
||
Function Input/Parameters: ???
|
||
Function Output/Parameters: ???
|
||
Function Output/Returned: ???
|
||
Device Input/Device: ???
|
||
Device Output/Monitor: ???
|
||
Dependencies: ???
|
||
*/
|
||
void computerTurn()
|
||
{
|
||
/*
|
||
Handles the computer’s turn and it should do the same actions as the human but for the
|
||
computer. The function should return the number of set that is collected during its turn.
|
||
*/
|
||
// void function, no return.
|
||
} |