Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

game lets me roll too many times

Status
Not open for further replies.

javaguy1

Programmer
May 14, 2003
136
US
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::play()
{
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 << &quot;Press ENTER to roll the dice.&quot; << endl;
getch();
if (ship == true)
cout << &quot;You have your ship\n&quot;;
if (captain == true)
cout << &quot;You have your captain\n&quot;;
if (mate == true)
cout << &quot;You have your mate\n&quot;;
cout << &quot;You rolled &quot;;
rolls = player.roll(roll, dice);
//is there a six?
for (i = 0; i < dice; i++)
{
if ((roll == 6) && (ship == false))
{
cout << &quot;You got your ship.\n&quot;;
cout << &quot;Do you wish to keep it? y/n&quot;;
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 << &quot;You got your captain.\n&quot;;
cout << &quot;Do you wish to keep him? y/n&quot;;
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 << &quot;You got your mate.\n&quot;;
cout << &quot;Do you wish to keep him? y/n&quot;;
cin >> response;
if (response == 'y' || response == 'Y')
{
mate = true;
dice--;
}
}
}
}
if (mate == true)
{
if (rolls != 0)
{
if ( dice > 1)
{
cout << &quot;The second die is a &quot; << roll[1]
<< &quot;. Do you want to keep it? y/n&quot;;
cin >> response;
if (response == 'y' || response == 'Y')
dice--;
}
if (dice > 0)
{
cout << &quot;The first die is a &quot; << roll[0]
<< &quot;. Do you want to keep it? y/n&quot;;
cin >> response;
if (response == 'y' || response == 'Y')
dice--;
}
if (dice == 0)
{
yourScore = roll[0] + roll[1];
cout << &quot;Your score is &quot; << yourScore << endl;
}
}
else
{
yourScore = roll[0] + roll[1];
cout << &quot;Your score is &quot; << yourScore << endl;
}
}
}
while ((rolls != 0) || (dice != 0));
//computers turn
rolls = 3;
dice = 5;
ship = false;
captain = false;
mate = false;
do
{
if (ship == true)
cout << &quot;I have my ship\n&quot;;
if (captain == true)
cout << &quot;I have my captain\n&quot;;
if (mate == true)
cout << &quot;I have my mate\n&quot;;
cout << &quot;I rolled &quot;;
rolls = computer .roll(roll, dice);
//is there a six?
for (i = 0; i < dice; i++)
{
if ((roll == 6) && (ship == false))
{
cout << &quot;I got my ship.\n&quot;;
ship = true;
dice--;
}
}
if ((ship == true) && (captain == false))
{
//is there a five?
for (i = 0; i < dice; i++)
{
if ((roll == 5) && (captain == false))
{
cout << &quot;I got my captain.\n&quot;;
captain = true;
dice--;
}
}
}
if ((captain == true) && (mate == false))
{
//is there a five?
for (i = 0; i < dice; i++)
{
if ((roll == 4) && (mate == false))
{
cout << &quot;I got my mate.\n&quot;;
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 << &quot;My score is &quot; << myScore << endl;
}
}
else
{
myScore = roll[0] + roll[1];
cout << &quot;My score is &quot; << myScore << endl;
}
}
}
while ((rolls != 0) || (dice != 0));
//game over
cout << &quot;Your score was &quot; << yourScore << endl;
cout << &quot;My score was &quot; << myScore << endl;
if (myScore > yourScore)
{
cout << &quot;I win!&quot; << endl;
losses++;
}
else if (yourScore > myScore)
{
cout << &quot;You win!&quot; << endl;
wins++;
}
else
{
cout << &quot;We tied!&quot; << endl;
}
if (wins == 1)
cout << &quot;You have won &quot; << wins << &quot; time&quot; << endl;
else
cout << &quot;You have won &quot; << wins << &quot; times&quot; << endl;
if (losses == 1)
cout << &quot;I have won &quot; << losses << &quot; time&quot; << endl;
else
cout << &quot;I have won &quot; << wins << &quot; times&quot; << endl;
cout << &quot;Would you like to play again? y/n&quot; << endl;
cin >> response;
if (response == 'n' || response == 'N')
quit = true;
}
while (quit == false);
cout << &quot;You won &quot; << wins << &quot; times.&quot; << endl;
cout << &quot;You lost &quot; << losses << &quot; times.&quot; << endl;
//why insult the player's intelligence?
//cout << &quot;I won &quot; << losses << &quot; times.&quot; << endl;
//cout << &quot;I lost &quot; << wins << &quot; times.&quot; << endl;
}

 
the call to player.roll(roll, dice); decrements rolls

int Player::roll(int roll[], int elements)
{
for (int i = 0; i < elements; i++)
roll = die.getDiePoint();
stuff.sort(roll, elements);
stuff.printArray(roll, elements);
rolls--;
return rolls;
}
 
Welcome to Tek-Tips forums, javaguy1!

For better replies you should probably read faq116-3426 and then revise your question.

Will
 
if that FAQ told me HOW to turn off TGML (whatever that is) it might be useful
 
>> if that FAQ told me HOW to turn off TGML (whatever
>> that is) it might be useful

ummm... how about the check box [red]Process TGML[/red] at the bottom of the <textarea> that you type your posts into!!!! [hammer]

-pete
I just can't seem to get back my IntelliSense
 
thanks, i see it now. i think i figured out the problem already. i believe i need to change a || to a &&....i probly shouldnt stay up writing code till 2 in the morning either....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top