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
|
#include <iostream>
#include <string>
#include <cstdilib>
#include <iomanip>
using namespace std;
//Function Prototypes
void displayHeading();
int drawCard();
int movePlayer(int, int);
void displayMove(int, int, int, int, int);
int main ()
{
//Variables
int playerTurn;
int playerOne = 1;
int playerTwo = 1;
int moveNumber = 1;
int card;
int currentPlayer;
int newLocation;
//Draw Card function
int drawCard ()
{
return rand() % 5 + 1;
}
//Heading Function
display Heading ();
currentPlayer = playerOne;
while (checkWin(currentPlayer) == false)
{
card = drawCard();
playerTurn = playerTurn + 1;
if (playerTurn > 3)
playerTurn = 1;
//whos turn is it and calling functions move() and printMove
if (playerTurn == 1)
{
newLocation = displayMove (playerOne, card);
movePlayer(playerTurn, moveNumber, playerOne, card, newLocation);
playerOne = newLocation;
currentPlayer = playerOne;
}
if (playerTurn == 2)
{
newLocation = displayMove (playerTwo, card);
displayMove(playerTurn, moveNumber, playerTwo, card, newLocation);
playerTwo = nextPosition;
currentPlayer = playerTwo;
moveNumber = moveNumber++;
}
}
//Candy Bonuses
int candyBonus(int position)
{
if (position == 6)
{
position = 40;
cout << "Rainbow Trail" << endl;
}
if (position == 9)
{
position = 24;
cout << "Lord Licorice" << endl;
}
if (position == 32)
{
position = 43;
cout << "Gumdrop Pass" << endl;
}
if (position == 40)
{
position = 50;
cout << "Hot Chocolate Gap" << endl;
}
if (position == 46)
{
position = 58;
cout << "Mr. Mint" << endl;
}
if (position == 62)
{
position = 73
cout << "Queen Frostine" << endl;
}
return position;
}
//Display heading for table
void displayHeading ()
{
cout << "Candyland Game" << endl;
cout << "Name" << endl;
cout << "Class Time" << endl;
cout << " " << endl;
cout << "Move #" << setw(10) << "Current Position" << setw(8) << "Card" << setw(8) "New Position" << setw (10) << "Candy Bonus" << endl;
return;
}
//Move the player
int movePlayer (int currentPlayer, int card)
{
int newLocation = 0;
if (newLocation < 85)
{
newLocation = currentPlayer + card;
newLocation = candyBonus(newLocation);
}
if (newLocation == 85)
{
newLocation = 85;
newLocation = candyBonus(newLocation);
}
if (newLocation > 85)
{
newLocation = currentPlayer;
newLocation = candyBonus(newLocation);
}
return newLocation;
}
//Display the move
void displayMove (int playerTurn, int moveNumber, int playerOne, int card, int
newLocation)
{
cout << "Player " << playerTurn << " " << moveNumber << " ";
cout << playerOne << " " << card << " " << newLocation << endl;
if (playerTurn == 3)
{cout <<
"-----------------------------------------------------------------" <<
endl;
}
if (newLocation >= 85)
cout <<"Player " << playerTurn << " wins" << endl;
return;
}
return 0;
}
|