C+---サイコロゲーム---ShinePans
2504 ワード
//this is a program witch played by two people
// , , 7 11 ,
// , 2,3 12, ,
// , , ,
#include <iostream>
#include <stdlib.h>
#include <ctime> //
#include <windows.h> //Sleep
#include <conio.h> //_kbhit
using namespace std;
int RollDice(); //
void SetSeed();
void PlayGame();
int RollDice() //
{
int die1 = 1 + rand() % 6;
int die2 = 1 + rand() % 6;
int sum = die1 + die2;
cout << "Player rooled " << die1 << "+" << die2 << "=" << sum << endl;
return sum;
}
void SetSeed() //
{
srand((unsigned)time(NULL)); //
}
enum GameStatus{WIN,LOSE,PLAYING}; // ;
void PlayGame()
{
int sumA = 0, sumB = 0, game = 1; //game , 1
GameStatus status = PLAYING;
while (status == PLAYING)
{
SetSeed(); //
cout << " AAAAAAAA :
( , )
";
system("pause");
while (game)
{
sumA = RollDice();
Sleep(20);
if (_kbhit())
{
game = 0;
}
}
game = 1;
if (sumA == 7 || sumA == 11)
{
status = WIN;
cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " << endl;
}
else if (sumA == 2 || sumA == 3 || sumA == 12)
{
status = LOSE;
cout << "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB " << endl;
}
else
{
cout << " BBBBBBBBBB :
( , )
";
system("pause");
while (game)
{
Sleep(20);
sumB = RollDice();
if (_kbhit())
{
game = 0;
}
}
game = 1;
if (sumB == 7 || sumB == 11)
{
status = WIN;
cout << "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB " << endl;
}
else if (sumB == 2 || sumB == 3 || sumB == 12)
{
status = WIN;
cout << "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " << endl;
}
else
; //do nothing;
}
}
}
int main()
{
char x;
PlayGame();
system("pause");
cout << " ?
" << "(Y/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;
}