This was a program witch played by two people//two people game, if the first throw dice, throw two times and for 7 or 11 then the first person direct victory, the second person direct failure//If the first person throws the dice, throw two times and 2, 3 or 12, Then the first person directly fails, the second person wins//if the first person throws a sieve, throws two times and above are not, then by the second person throws, until one party wins # include <iostream> #include <stdlib.h> #include <ctime>//Get the system time header file # include <windows.h>//sleep function # include <conio.h>//_kbhit get keyboard percussion using namespace Std;int Rolldice (); function prototype void Setseed (), void PlayGame (), int rolldice ()//throw dice function {int die1 = 1 + rand ()% 6;int Die2 = 1 + rand ()% 6;int sum = Die1 + die2;cout << "Player rooled" << die1 << "+" << die2 << "=" << sum << E Ndl;return sum;} void Setseed ()//Set the SEED function to use system time to set the random seed {srand ((unsigned) times (NULL)); Get system Time settings seed}enum gamestatus{win,lose,playing}; Enumerates game states; void PlayGame () {int SumA = 0, Sumb = 0, game = 1; The game is a flag, and when it is 1 o'clock continuously throws gamestatus status = playing;while (status = = PLAYING) {setseed (); Set seed cout << "please aaaaaaaa throw: \ n (Press any key to start throwing, press any key to end the throw) \ n"; system ("pause"); while (game) {SumA = Rolldice (); SleeP (+); if (_kbhit ()) {game = 0;}} Game = 1;if (SumA = = 7 | | sumA = =) {status = Win;cout << "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa won" << Endl ;} else if (SumA = = 2 | | sumA = = 3 | | sumA = =) {status = Lose;cout << "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB won" < ;< Endl;} Else{cout << "Please bbbbbbbbbb throw: \ n (Press any key to start throwing, press any key to end the throw) \ n"; system ("pause"); while (game) {Sleep]; sumb = Rolldice () ; if (_kbhit ()) {game = 0;}} Game = 1;if (Sumb = = 7 | | sumb = =) {status = Win;cout << "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB won" << Endl;} else if (Sumb = = 2 | | sumb = = 3 | | sumb = =) {status = Win;cout << "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa won" & lt;< Endl;} Else Do nothing; Continue next round}}}int main () {char x; PlayGame (); System ("pause"); cout << "Do you want another plate?" \ n "<<" (y/n): \ n "<< endl;while (1) {if (_kbhit ()) {x = _getch (); if ((x = = ' Y ') | | (x = = ' Y ')) {PlayGame ();} if ((x = = ' n ') | | (x = = ' N ')) {System ("pause"); return 0;}}} return 0;}
Relive the C + +---dice game---shinepans