Gotten base code down for Go Fish.
This commit is contained in:
parent
28e820292f
commit
b34d34a63d
2 changed files with 85 additions and 14 deletions
Binary file not shown.
|
|
@ -33,12 +33,12 @@ Dependencies: ???
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <random>
|
||||||
|
#include <algorithm>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
// function prototypes
|
|
||||||
|
|
||||||
// class definitions
|
// class definitions
|
||||||
class Card
|
class Card
|
||||||
{
|
{
|
||||||
|
|
@ -49,11 +49,6 @@ class Card
|
||||||
// store the value and suit. (possible values 2-9, T, J, Q, K, A)
|
// store the value and suit. (possible values 2-9, T, J, Q, K, A)
|
||||||
cardValue = value;
|
cardValue = value;
|
||||||
cardSuit = suit;
|
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)
|
// get the numerical value of the card, casting from string to num where possible. (2-9)
|
||||||
if((cardValue >= 2) || (cardValue <= 9))
|
if((cardValue >= 2) || (cardValue <= 9))
|
||||||
{
|
{
|
||||||
|
|
@ -81,13 +76,40 @@ class Card
|
||||||
// king
|
// king
|
||||||
cardNumericalValue = 13;
|
cardNumericalValue = 13;
|
||||||
}
|
}
|
||||||
|
// special 1/Ace card here
|
||||||
|
if (cardValue == 'A')
|
||||||
|
{
|
||||||
|
cardNumericalValue = 1;
|
||||||
|
}
|
||||||
|
// add the cardValue and cardSuit to the string
|
||||||
|
fullCard = fullCard + cardValue;
|
||||||
|
fullCard = fullCard + cardSuit;
|
||||||
|
}
|
||||||
|
int getCardValue()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
return cardNumericalValue;
|
||||||
|
}
|
||||||
|
char getCardSuit()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
return cardSuit;
|
||||||
|
}
|
||||||
|
string getFullCard()
|
||||||
|
{
|
||||||
|
return fullCard;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
char cardValue;
|
char cardValue;
|
||||||
char cardSuit;
|
char cardSuit;
|
||||||
int cardNumericalValue;
|
int cardNumericalValue;
|
||||||
|
string fullCard;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// function prototypes
|
||||||
|
int humanTurn(vector<Card> &human, vector<Card> &computer);
|
||||||
|
int computerTurn(vector<Card> &human, vector<Card> &computer);
|
||||||
|
|
||||||
// main program
|
// main program
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
@ -96,18 +118,61 @@ int main(int argc, char **argv)
|
||||||
// have two hands for cards
|
// have two hands for cards
|
||||||
vector<Card> humanHand;
|
vector<Card> humanHand;
|
||||||
vector<Card> computerHand;
|
vector<Card> computerHand;
|
||||||
|
// keep count of the number of sets collected. ends when number is 13.
|
||||||
|
int currentNumSets = 0;
|
||||||
|
// char array for the setups
|
||||||
|
char suits[] = {'C','D','H','S'};
|
||||||
|
int suitsLen = sizeof(suits)/sizeof(suits[0]);
|
||||||
|
// char values[] = {'A','2','3','4','5','6','7','8','9','T','J','Q','K'};
|
||||||
|
char values[] = {'K','Q','J','T','9','8','7','6','5','4','3','2','A'};
|
||||||
|
int valuesLen = (sizeof(values)/sizeof(values[0]));
|
||||||
// game setup
|
// game setup
|
||||||
// create deck by loop for 1 - 13 with each suit {(H)earts, S(pades), C(lubs), D(iamonds)}.
|
// 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.
|
// use double for loop, outer for suits, inner for values.
|
||||||
// shuffle deck randomly? (use shuffle function from vector library)
|
for (int deckCounter = 0; deckCounter < suitsLen; deckCounter++)
|
||||||
|
{
|
||||||
|
// creates each suit
|
||||||
|
for (int suitCounter = 0; suitCounter < valuesLen; suitCounter++)
|
||||||
|
{
|
||||||
|
// creates each card/value
|
||||||
|
deck.push_back(Card(values[suitCounter], suits[deckCounter]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// shuffle deck randomly? (use shuffle function from algorithm library)
|
||||||
|
// generate a random number (which is so much harder in CPP because they 'frown upon' using the C STL rand stuff)
|
||||||
|
default_random_engine randNumGen(time(NULL));
|
||||||
|
// shuffle the deck using that rng engine.
|
||||||
|
shuffle(deck.begin(), deck.end(), randNumGen);
|
||||||
// deal hands by taking each card from the deck, one by one (7x) (for loop here.)
|
// deal hands by taking each card from the deck, one by one (7x) (for loop here.)
|
||||||
|
for(int dealIterator = 0; dealIterator < 7; dealIterator++)
|
||||||
|
{
|
||||||
|
// grab the last card from the deck, put it in the human's hand
|
||||||
|
humanHand.push_back(deck.back());
|
||||||
|
deck.pop_back();
|
||||||
|
// grab the last card from the deck, put it in the computer's hand
|
||||||
|
computerHand.push_back(deck.back());
|
||||||
|
deck.pop_back();
|
||||||
|
}
|
||||||
// main gameplay loop (while?)
|
// main gameplay loop (while?)
|
||||||
// ask for card rank/number/value
|
while(currentNumSets != 13)
|
||||||
// if card is in hand,
|
{
|
||||||
|
// switch back and forth between human and computer.
|
||||||
|
currentNumSets = currentNumSets + humanTurn(humanHand, computerHand);
|
||||||
|
currentNumSets = currentNumSets + computerTurn(humanHand, computerHand);
|
||||||
|
}
|
||||||
// return 0
|
// return 0
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* THIS BELOW CODE IS FOR CHECKING THE DECK
|
||||||
|
for (int tempIterator = 0; tempIterator < 52; tempIterator++)
|
||||||
|
{
|
||||||
|
// print off each card to see if it was correctly made.
|
||||||
|
cout << tempIterator << ": " << deck[tempIterator].getFullCard() << " | ";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
*/
|
||||||
|
|
||||||
// compiles using "g++ -Wall -pedantic go_fish.cpp -o go_fish" - note to programmer
|
// compiles using "g++ -Wall -pedantic go_fish.cpp -o go_fish" - note to programmer
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -120,7 +185,7 @@ Device Input/Device: ???
|
||||||
Device Output/Monitor: ???
|
Device Output/Monitor: ???
|
||||||
Dependencies: ???
|
Dependencies: ???
|
||||||
*/
|
*/
|
||||||
void humanTurn()
|
int humanTurn(vector<Card> &human, vector<Card> &computer)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Handles the human’s turn. It will prompt the player to ask for a card rank/number and
|
Handles the human’s turn. It will prompt the player to ask for a card rank/number and
|
||||||
|
|
@ -128,7 +193,12 @@ void humanTurn()
|
||||||
computer’s hand, it will transfer the card to the human’s hand otherwise, it will draw a
|
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
|
card. The function should return the number of sets collected during the turn
|
||||||
*/
|
*/
|
||||||
// void function, no return.
|
|
||||||
|
// ask for card rank/number/value
|
||||||
|
// if card is in hand,
|
||||||
|
|
||||||
|
// return the number of sets
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -141,11 +211,12 @@ Device Input/Device: ???
|
||||||
Device Output/Monitor: ???
|
Device Output/Monitor: ???
|
||||||
Dependencies: ???
|
Dependencies: ???
|
||||||
*/
|
*/
|
||||||
void computerTurn()
|
int computerTurn(vector<Card> &human, vector<Card> &computer)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Handles the computer’s turn and it should do the same actions as the human but for the
|
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.
|
computer. The function should return the number of set that is collected during its turn.
|
||||||
*/
|
*/
|
||||||
// void function, no return.
|
// return the number of sets
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue