this worked before i fixed it. it should only let each player roll 3 times.
#include "ShipCaptainMateCrew.h"
ShipCaptainMateCrew::ShipCaptainMateCrew()
{
wins = 0;
losses = 0;
}
void ShipCaptainMateCrew:
lay()
{
int i; //loop counter
int myScore;
int yourScore;
int rolls;
int dice ;
int roll[5];
char response;
bool quit = false;
bool ship;
bool captain;
bool mate;
do
{
myScore = 0;
yourScore = 0;
//players turn...parts of this should be in another function maybe
rolls = 3;
dice = 5;
ship = false;
captain = false;
mate = false;
do
{
cout << "Press ENTER to roll the dice." << endl;
getch();
if (ship == true)
cout << "You have your ship\n";
if (captain == true)
cout << "You have your captain\n";
if (mate == true)
cout << "You have your mate\n";
cout << "You rolled ";
rolls = player.roll(roll, dice);
//is there a six?
for (i = 0; i < dice; i++)
{
if ((roll == 6) && (ship == false))
{
cout << "You got your ship.\n";
cout << "Do you wish to keep it? y/n";
cin >> response;
if (response == 'y' || response == 'Y')
{
ship = true;
dice--;
}
}
}
if ((ship == true) && (captain == false))
{
//is there a five?
for (i = 0; i < dice; i++)
{
if ((roll == 5) && (captain == false))
{
cout << "You got your captain.\n";
cout << "Do you wish to keep him? y/n";
cin >> response;
if (response == 'y' || response == 'Y')
{
captain = true;
dice--;
}
}
}
}
if ((captain == true) && (mate == false))
{
//is there a four?
for (i = 0; i < dice; i++)
{
if ((roll == 4) && (mate == false))
{
cout << "You got your mate.\n";
cout << "Do you wish to keep him? y/n";
cin >> response;
if (response == 'y' || response == 'Y')
{
mate = true;
dice--;
}
}
}
}
if (mate == true)
{
if (rolls != 0)
{
if ( dice > 1)
{
cout << "The second die is a " << roll[1]
<< ". Do you want to keep it? y/n";
cin >> response;
if (response == 'y' || response == 'Y')
dice--;
}
if (dice > 0)
{
cout << "The first die is a " << roll[0]
<< ". Do you want to keep it? y/n";
cin >> response;
if (response == 'y' || response == 'Y')
dice--;
}
if (dice == 0)
{
yourScore = roll[0] + roll[1];
cout << "Your score is " << yourScore << endl;
}
}
else
{
yourScore = roll[0] + roll[1];
cout << "Your score is " << yourScore << endl;
}
}
}
while ((rolls != 0) || (dice != 0));
//computers turn
rolls = 3;
dice = 5;
ship = false;
captain = false;
mate = false;
do
{
if (ship == true)
cout << "I have my ship\n";
if (captain == true)
cout << "I have my captain\n";
if (mate == true)
cout << "I have my mate\n";
cout << "I rolled ";
rolls = computer .roll(roll, dice);
//is there a six?
for (i = 0; i < dice; i++)
{
if ((roll == 6) && (ship == false))
{
cout << "I got my ship.\n";
ship = true;
dice--;
}
}
if ((ship == true) && (captain == false))
{
//is there a five?
for (i = 0; i < dice; i++)
{
if ((roll == 5) && (captain == false))
{
cout << "I got my captain.\n";
captain = true;
dice--;
}
}
}
if ((captain == true) && (mate == false))
{
//is there a five?
for (i = 0; i < dice; i++)
{
if ((roll == 4) && (mate == false))
{
cout << "I got my mate.\n";
mate = true;
dice--;
}
}
}
if (mate == true)
{
if (rolls != 0)
{
if ( dice > 1)
if (roll[1] > 3)
dice--;
if ( dice > 0)
if (roll[0] > 3)
dice--;
if (dice == 0)
{
myScore = roll[0] + roll[1];
cout << "My score is " << myScore << endl;
}
}
else
{
myScore = roll[0] + roll[1];
cout << "My score is " << myScore << endl;
}
}
}
while ((rolls != 0) || (dice != 0));
//game over
cout << "Your score was " << yourScore << endl;
cout << "My score was " << myScore << endl;
if (myScore > yourScore)
{
cout << "I win!" << endl;
losses++;
}
else if (yourScore > myScore)
{
cout << "You win!" << endl;
wins++;
}
else
{
cout << "We tied!" << endl;
}
if (wins == 1)
cout << "You have won " << wins << " time" << endl;
else
cout << "You have won " << wins << " times" << endl;
if (losses == 1)
cout << "I have won " << losses << " time" << endl;
else
cout << "I have won " << wins << " times" << endl;
cout << "Would you like to play again? y/n" << endl;
cin >> response;
if (response == 'n' || response == 'N')
quit = true;
}
while (quit == false);
cout << "You won " << wins << " times." << endl;
cout << "You lost " << losses << " times." << endl;
//why insult the player's intelligence?
//cout << "I won " << losses << " times." << endl;
//cout << "I lost " << wins << " times." << endl;
}
#include "ShipCaptainMateCrew.h"
ShipCaptainMateCrew::ShipCaptainMateCrew()
{
wins = 0;
losses = 0;
}
void ShipCaptainMateCrew:
{
int i; //loop counter
int myScore;
int yourScore;
int rolls;
int dice ;
int roll[5];
char response;
bool quit = false;
bool ship;
bool captain;
bool mate;
do
{
myScore = 0;
yourScore = 0;
//players turn...parts of this should be in another function maybe
rolls = 3;
dice = 5;
ship = false;
captain = false;
mate = false;
do
{
cout << "Press ENTER to roll the dice." << endl;
getch();
if (ship == true)
cout << "You have your ship\n";
if (captain == true)
cout << "You have your captain\n";
if (mate == true)
cout << "You have your mate\n";
cout << "You rolled ";
rolls = player.roll(roll, dice);
//is there a six?
for (i = 0; i < dice; i++)
{
if ((roll == 6) && (ship == false))
{
cout << "You got your ship.\n";
cout << "Do you wish to keep it? y/n";
cin >> response;
if (response == 'y' || response == 'Y')
{
ship = true;
dice--;
}
}
}
if ((ship == true) && (captain == false))
{
//is there a five?
for (i = 0; i < dice; i++)
{
if ((roll == 5) && (captain == false))
{
cout << "You got your captain.\n";
cout << "Do you wish to keep him? y/n";
cin >> response;
if (response == 'y' || response == 'Y')
{
captain = true;
dice--;
}
}
}
}
if ((captain == true) && (mate == false))
{
//is there a four?
for (i = 0; i < dice; i++)
{
if ((roll == 4) && (mate == false))
{
cout << "You got your mate.\n";
cout << "Do you wish to keep him? y/n";
cin >> response;
if (response == 'y' || response == 'Y')
{
mate = true;
dice--;
}
}
}
}
if (mate == true)
{
if (rolls != 0)
{
if ( dice > 1)
{
cout << "The second die is a " << roll[1]
<< ". Do you want to keep it? y/n";
cin >> response;
if (response == 'y' || response == 'Y')
dice--;
}
if (dice > 0)
{
cout << "The first die is a " << roll[0]
<< ". Do you want to keep it? y/n";
cin >> response;
if (response == 'y' || response == 'Y')
dice--;
}
if (dice == 0)
{
yourScore = roll[0] + roll[1];
cout << "Your score is " << yourScore << endl;
}
}
else
{
yourScore = roll[0] + roll[1];
cout << "Your score is " << yourScore << endl;
}
}
}
while ((rolls != 0) || (dice != 0));
//computers turn
rolls = 3;
dice = 5;
ship = false;
captain = false;
mate = false;
do
{
if (ship == true)
cout << "I have my ship\n";
if (captain == true)
cout << "I have my captain\n";
if (mate == true)
cout << "I have my mate\n";
cout << "I rolled ";
rolls = computer .roll(roll, dice);
//is there a six?
for (i = 0; i < dice; i++)
{
if ((roll == 6) && (ship == false))
{
cout << "I got my ship.\n";
ship = true;
dice--;
}
}
if ((ship == true) && (captain == false))
{
//is there a five?
for (i = 0; i < dice; i++)
{
if ((roll == 5) && (captain == false))
{
cout << "I got my captain.\n";
captain = true;
dice--;
}
}
}
if ((captain == true) && (mate == false))
{
//is there a five?
for (i = 0; i < dice; i++)
{
if ((roll == 4) && (mate == false))
{
cout << "I got my mate.\n";
mate = true;
dice--;
}
}
}
if (mate == true)
{
if (rolls != 0)
{
if ( dice > 1)
if (roll[1] > 3)
dice--;
if ( dice > 0)
if (roll[0] > 3)
dice--;
if (dice == 0)
{
myScore = roll[0] + roll[1];
cout << "My score is " << myScore << endl;
}
}
else
{
myScore = roll[0] + roll[1];
cout << "My score is " << myScore << endl;
}
}
}
while ((rolls != 0) || (dice != 0));
//game over
cout << "Your score was " << yourScore << endl;
cout << "My score was " << myScore << endl;
if (myScore > yourScore)
{
cout << "I win!" << endl;
losses++;
}
else if (yourScore > myScore)
{
cout << "You win!" << endl;
wins++;
}
else
{
cout << "We tied!" << endl;
}
if (wins == 1)
cout << "You have won " << wins << " time" << endl;
else
cout << "You have won " << wins << " times" << endl;
if (losses == 1)
cout << "I have won " << losses << " time" << endl;
else
cout << "I have won " << wins << " times" << endl;
cout << "Would you like to play again? y/n" << endl;
cin >> response;
if (response == 'n' || response == 'N')
quit = true;
}
while (quit == false);
cout << "You won " << wins << " times." << endl;
cout << "You lost " << losses << " times." << endl;
//why insult the player's intelligence?
//cout << "I won " << losses << " times." << endl;
//cout << "I lost " << wins << " times." << endl;
}