1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <ctime>
#include <cstdlib>
#include <algorithm>
//#include <Windows.h>
// Game Specific Files
#include "CardGameConfig.h"
#include "CardGameFunctions.h"
#include "CardGameStructs.h"
//#include "CardGameFunctions.cpp"
using namespace std;
int main(int argc, char* argv[]){
SPlayer sHuman;
SPlayer sComputer;
sHuman.iTricks = 0;
sComputer.iTricks = 0;
int iHumanScore = 0;
int iCompScore = 0;
sHuman.name = "";
sComputer.name = "Fred";
Card sComputerPlayedCard;
Card sHumanPlayedCard;
Deck Deck;
bool bIsHumanTurn = true;
cout << "Welcome to the game of Spades!" << endl;
cout << "What is your name? "<< endl;
capturePlayerName(&sHuman);
do
{
render("\nAlright then, "+sHuman.name+", welcome! Your opponent will be "+sComputer.name+".", 2);
Deck.Shuffle(); // shuffles the deck
render("The cards have been shuffled so now you will start by picking a card. "
"If you don't want the first card you draw, you must accept the second. "
"After you pick a card, your opponent, "+sComputer.name+", will choose one from the stack "
"until you each have a total of "+toString(TOTAL_CARDS_IN_HAND)+" in hand.", 2);
render("Ready? Type C to continue or Q to quit game: ", 0);
if(captureStartGameDecision() == true)
{
render("Great! Let's get started", 2);
render("Fred always lets you start the game (because he's nice like that) so here we go... ", 2);
// you need to pass the pointer to fill hands function
fillHands(&Deck, &sHuman, &sComputer);
// gotta win it now
render("OK, now that you have cards in your hands, let's start by bidding. "
"Enter the amount of times (0-13) you think you will have the highest card", 2);
render("Enter number between 0-13: ", 0);
captureBids(&sHuman, &sComputer);
render("Now that you've made your bids, "+sComputer.name+" will let you start the trick.", 2);
do {
if (bIsHumanTurn==false) {
// computer
sComputerPlayedCard = sComputer.aHand[sComputer.iTotalHand-1];
sComputer.iTotalHand--;
render(sComputer.name+" placed this on the table: ", 2);
Deck.DrawCard(sComputerPlayedCard);
// human
render("Your opponent has played a card, which card do you want to play? ", 2);
renderHand(&sHuman);
render("Enter card abbreviation to select from hand (example: 2H or JS): ", 0);
sHumanPlayedCard = captureCardToPlay(&sHuman);
sHuman.iTotalHand--;
render(sHuman.name+" placed this on the table: ", 2);
Deck.DrawCard(sHumanPlayedCard);
bIsHumanTurn=true;
}
else
{
// human
render("You may lead the trick with a card, which one do you want to play? ", 2);
renderHand(&sHuman);
render("Enter card abbreviation to select from hand (example: 2H or JS): ", 0);
sHumanPlayedCard = captureCardToPlay(&sHuman);
sHuman.iTotalHand--;
render(sHuman.name+" placed this on the table: ", 2);
Deck.DrawCard(sHumanPlayedCard);
// computer
sComputerPlayedCard = sComputer.aHand[sComputer.iTotalHand-1];
sComputer.iTotalHand--;
render(sComputer.name+" placed this on the table: ", 2);
Deck.DrawCard(sComputerPlayedCard);
bIsHumanTurn = false;
}
// is computer card higher than player card?
if (sComputerPlayedCard.GetSuit() > sComputerPlayedCard.GetSuit()) {
// human wins trick
render("You won that trick!", 2);
// record score
sHuman.iTricks++;
} else if(sHumanPlayedCard.GetSuit() < sComputerPlayedCard.GetSuit()){
// computer wins trick
render(sComputer.name+" won that trick", 2);
// record score
sComputer.iTricks++;
} else {
// they are tied with suit, figure out rank
if (sHumanPlayedCard.GetRank() > sComputerPlayedCard.GetRank()) {
// human wins trick
render("You won that trick!", 2);
// record score
sHuman.iTricks++;
} else if(sHumanPlayedCard.GetRank() < sComputerPlayedCard.GetRank()) {
// computer wins trick
render(sComputer.name+" won that trick", 2);
// record score
sComputer.iTricks++;
} else {
// both have the same card
render("Both of you have the same card", 2);
// record score
}
}
} while (sHuman.iTotalHand > 0 && sComputer.iTotalHand > 0);
render("Good game! Let's play again sometime. ", 2);
//Calculating Final Scores
finalScores( &sHuman, &sComputer);
cout << "Your final score is: "<< sHuman.iScore << endl;
cout << "Fred's final score is: " << sComputer.iScore << endl;
// checking to see who starts the next round
// iHumanScore = sHuman.iScore + iHumanScore;
// iCompScore = sComputer.iScore + iCompScore;
if(sHuman.iScore > sComputer.iScore)
{
bIsHumanTurn = true;
}
else
{
bIsHumanTurn = false;
}
} else {
render("Leaving so soon? OK, bye bye.", 2);
}
}while(iHumanScore >= 500 || iHumanScore < -200 || iCompScore >= 500 || iCompScore < -200);
return 0;
system("PAUSE");
// std::cin.get();
// std::cin.get();
}
|