-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollDice.cpp
70 lines (63 loc) · 890 Bytes
/
rollDice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <time.h>
using namespace std;
int rollDice()
{
int num1 = rand() % 6 + 1;
int num2 = rand() % 6 + 1;
int sum = num1 + num2;
cout << "player rolled:" << sum << endl;
return sum;
}
enum GameStatus
{
WIN,
LOSE,
PLAYING
};
int main()
{
srand((unsigned int)time(NULL));
int sum, mypoint;
GameStatus status;
sum = rollDice();
switch (sum)
{
case 7:
case 11:
status = WIN;
break;
case 2:
case 3:
case 12:
status = WIN;
break;
default:
status = PLAYING;
mypoint = sum;
cout << "当前点数是:" << mypoint << endl;
break;
}
while (status == PLAYING)
{
sum = rollDice();
if (sum == mypoint)
{
status = WIN;
}
else if (sum == 7)
{
status = LOSE;
}
}
if (status == WIN)
{
cout << "player wins" << endl;
}
else
{
cout << "player lose" << endl;
}
return 0;
}