Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int p1_score, p2_score;
- int roll1, roll2, roll3;
- int rollcount=0, turns;
- bool isEven, isOdd, is3kind, is2kind, is3inarow;
- bool player1;
- char roll;
- int big, mid, lil;
- int main(void){
- cout<<"Welcome to Schmahtzee! It's just like Yahtzee...Except, not."<<endl<<endl<<endl;
- srand(time(NULL));
- player1=true;
- do{
- do{
- roll1=1+rand()%6;
- roll2=1+rand()%6;
- roll3=1+rand()%6;
- rollcount++;
- if(player1)
- cout<<"It's time to roll, Player 1!"<<endl<<endl;
- else
- cout<<"It's time to roll, Player 2!"<<endl<<endl;
- cout<<"press any key to roll."<<endl<<endl;
- cin>>roll;
- cout<<endl<<endl;
- cout<<"You rolled: " <<roll1<< ", " <<roll2<< ", and " <<roll3<<"."<<endl<<endl;
- cout<<"Would you like to keep these? (y/n)";
- cin>>roll;
- if (roll=='y'){
- if (roll1%2==0&&roll2%2==0&&roll3%2==0){isEven=true;}//3even
- if (roll1%2==1&&roll2%2==1&&roll3%2==1){isOdd=true;}//odd
- if (roll1==roll2&&roll1==roll3){is3kind=true;} //3 of a kind
- if (roll1>roll2&&roll1>roll3)//begin 3 in a row
- big=roll1;
- else if (roll1>roll2&&roll1<roll3)
- mid=roll1;
- else if (roll1>roll3&&roll1<roll2)
- mid=roll1;
- else
- lil=roll1;
- if (roll2>roll1&&roll2>roll3)
- big=roll2;
- else if (roll2>roll1&&roll2>roll3)
- mid=roll2;
- else if (roll2>roll3&&roll2<roll1)
- mid=roll2;
- else
- lil=roll2;
- if (roll3>roll1&&roll3>roll2)
- big=roll3;
- else if (roll3>roll1&&roll3<roll2)
- mid=roll3;
- else if (roll3>roll2&&roll3<roll1)
- mid=roll3;
- else
- lil=roll3;
- if (big==mid+1&&big==lil+2){is3inarow=true;}//end 3 in a row
- if(roll1==roll2||roll2==roll3||roll1==roll3){is2kind=true;}//2 of a kind
- cout<<"You could put them in: ";
- if(isEven)cout<<"3 Evens";
- if(isOdd)cout<<"3 Odds";
- if(is3kind)cout<<"3 of a kind";
- if(is2kind)cout<<"2 of a kind";
- if(is3inarow)cout<<"3 in a row";
- cout<<"Option 1: 3 odds (5 points)."<<endl;
- cout<<"Option 2: 3 evens(5 points)."<<endl;
- cout<<"Option 3: 3 of a kind (30 points)"<<endl;
- cout<<"Option 4: 2 of a kind (face of 2)"<<endl;
- cout<<"Option 5: 3 in a row(15 points)."<<endl;
- cout<<"So what'll it be?"<<endl<<endl;
- cin>>roll;
- if (roll==1&&isOdd){
- if(player1)
- p1_score+=5;
- else
- p2_score+=5;
- }
- if (roll==2&&isEven){
- if(player1)
- p1_score+5;
- else
- p2_score+5;
- }
- if (roll==3&&is3kind){
- if (player1)
- p1_score+30;
- else
- p2_score+30;
- }
- if (roll==4&&is2kind){
- if (player1){
- if(roll1==roll2)
- p1_score+=roll1+roll1;
- else if(roll2==roll3)
- p1_score+=roll2+roll2;
- else
- p1_score+=roll3+roll3;
- }
- else{
- if(roll1==roll2)
- p2_score+=roll1+roll1;
- else if(roll2==roll3)
- p2_score+=roll2+roll2;
- else
- p2_score+=roll3+roll3;
- }
- }
- if (roll==5&&is3inarow){if (player1)
- p1_score+15;
- else
- p2_score+15;
- }
- }
- isEven=0;
- isOdd=0;
- is3kind=0;
- is2kind=0;
- is3inarow=0;
- }while (rollcount<3&&roll!='y');
- if(player1)
- player1=false;
- else
- player1=true;
- turns++;
- }while (turns<60);
- cout<<"Player 1's Score:"<<p1_score<<endl;
- cout<<"Player 2's Score:"<<p2_score<<endl;
- if(p1_score>p2_score)
- cout<<"Player 1 Won!"<<endl;
- else if(p1_score<p2_score)
- cout<<"Player 2 Won!"<<endl;
- else
- cout<<"It's a tie!"<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement