#include "stdafx.h"
#include "bluff_funcs.h" //include header file of functions used in this project
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
enum states {INITIAL, P1ROLL, P2ROLL, P1INIT, P2INIT, P1SEQ, P2SEQ ,REVEAL};
states state;
int main() {
srand(time(NULL)); //seed random number generator
state = INITIAL;
static int round = 1; //static to insure variable "round" is never reset to 1
int die_roll;
int P1_DICE_ROLL[5];
int P2_DICE_ROLL[5];
int winner;
int turn = 0;
int selection;
int bidder;
int challenger;
char exit;
while(1) { //run while loop until return(0)
switch(state)
{
case INITIAL:
if (round > 1) { //will always be the case after initial round 1 has completed
cout<<"Want to play again? (Y or N) "; //prompt to play again
cin>>exit;
switch(exit)
{ //start switch(exit)
case 'y':
case 'Y': //player wants to play another round
system("cls");
cout<<"*ROUND "<<round<<"*"<<endl; //prints out current round (2 and above)
if (winner == 1) { //player 1 won last round
turn = 0;
reset_game(); //call function to reset game variables to initial values
cout<<"Player 1, you won the last round. You'll go first this round."<<endl;
state = P1ROLL; //change case to initialize player 1 dice roll
} else { //player 2 won last round
turn = 0;
reset_game(); //call function to reset game variables to initial values
cout<<"Player 2, you won the last round. You'll go first this round."<<endl;
state = P2ROLL; //change case to initialize player 2 dice roll
}
break;
case 'n':
case 'N': //player does not want to play another round
cout<<"Goodbye!"<<endl;
return(0); //end program
break;
} //end switch(exit)
} else { //this will only occur the first time the program runs
cout<<"Welcome to the game of BLUFF, a coin flip will determine who goes first."<<endl;
int rn = rand(); //generate random number to be passed into the coinflip function
winner = coin_flip(rn); //call coinflip function
switch(winner)
{ //start switch(winner)
case 1: //player 1 won the coinflip
state = P1ROLL; //change case to initialize player 1 dice roll
break;
case 2: //player 1 lost the coinflip
state = P2ROLL; //change case to initialize player 2 dice roll
break;
default:
break;
} //end switch(winner)
cout<<"*ROUND "<<round<<"*"<<endl; //prints out *ROUND 1* only once
}
break;
case P1ROLL: //player 1 won the initial coinflip or the previous round
cout<<"******PLAYER 2 LOOK AWAY FROM THE SCREEN******"<<endl;
cout<<"Player 1 . . . ";
system("pause"); //wait until player 2 is looking away from the screen
for (int i=0; i<5; i++) { //start for loop to simulate rolling 5 dice
int rn = rand(); //generate random number to pass into die roll function
die_roll = roll_die(rn); //call die roll function
tally(die_roll); //call tally function for current die roll
P1_DICE_ROLL[i] = die_roll; //store player 1 die rolls in array for later recall
} //end for loop
print_array(P1_DICE_ROLL, 5); //call print array function to display player 1 dice roll
cout<<endl;
cout<<"1's are wild! Remember your dice roll!"<<endl;
system("pause"); //wait until player 1 is done looking at their dice roll
if (turn == 0) { //will be true only if player 2 die roll has not occured yet
system("cls");
state = P2ROLL; //change case to initialize player 2 dice roll
turn++; //increment turn
} else { //player 2 dice roll has already occured
system("cls");
state = P2INIT; //change case to initialize player 2 initial bid
turn++; //increment turn
}
break;
case P2ROLL: //player 2 won the initial coinflip or the previous round
cout<<"******PLAYER 1 LOOK AWAY FROM THE SCREEN******"<<endl;
cout<<"Player 2 . . . ";
system("pause"); //wait until player 1 is looking away from the screen
for (int i=0; i<5; i++) { //start for loop to simulate rolling 5 dice
int rn = rand(); //generate random number to pass into die roll function
die_roll = roll_die(rn); //call die roll function
tally(die_roll); //call tally function for current die roll
P2_DICE_ROLL[i] = die_roll; //store player 2 die rolls in array for later recall
} //end for loop
print_array(P2_DICE_ROLL, 5); //call print array function to display player 2 dice roll
cout<<endl;
cout<<"1's are wild! Remember your dice roll!"<<endl;
system("pause"); //wait until player 1 is done looking at their dice roll
if (turn == 0) { //will be true only if player 1 die roll has not occured yet
system("cls");
state = P1ROLL; //change case to initialize player 1 dice roll
turn++; //increment turn
} else { //player 1 dice roll has already occured
system("cls");
state = P1INIT; //change case to initialize player 1 initial bid
turn++; //increment turn
}
break;
case P1INIT: //player 1 won coinflip or last round ... bid only this turn
system("cls");
initial_bid(1); //call initial bid function for player 1
state = P2SEQ; //change case to initialize player 2 sequent turn
break;
case P2INIT: //player 2 won coinflip or last round ... bid only this turn
system("cls");
initial_bid(2); //call initial bid function for player 2
state = P1SEQ; //change case to initialize player 1 sequent turn
break;
case P1SEQ: //player 2 has just bid or re-bid, player 1 turn ... re-bid or challenge
system("cls");
selection = sequent_turn(1); //call sequent turn function for player 1
if (selection == 1) //will be true only if player 1 re-bid
state = P2SEQ; //change case to initialize player 2 sequent turn
else { //player 1 has challenged player 2 bid
bidder = 2; //set player 2 as bidder
challenger = 1; //set player 1 as challenger
state = REVEAL; //change case to initialize end of round reveal
}
break;
case P2SEQ: //player 1 has just bid or re-bid, player 2 turn ... re-bid or challenge
system("cls");
selection = sequent_turn(2); //call sequent turn function for player 2
if (selection == 1) //will be true only if player 2 re-bid
state = P1SEQ; //change case to initialize player 1 sequent turn
else { //player 2 has challenged player 1 bid
bidder = 1; //set player 1 as bidder
challenger = 2; //set player 2 as challenger
state = REVEAL; //change case to initialize end of round reveal
}
break;
case REVEAL: //a bid has been challenged, reveal dice and determine a winner
system("cls");
winner = challenge(challenger, bidder, P1_DICE_ROLL, P2_DICE_ROLL); //call challenge function and assign winner
round++; //increment round (insures prompt to play again)
state = INITIAL; //change case to reset game and prompt to play again
break;
default:
break;
} //end switch(state)
} //end while loop
} //end main function
|