-
Notifications
You must be signed in to change notification settings - Fork 1
/
Zyanken.c
87 lines (78 loc) · 1.65 KB
/
Zyanken.c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// じゃんけんゲーム作りまーす。
int randum(void){
int par;
srand((unsigned)time(NULL));
par = (rand() % 3) + 1;
printf("%d\n", par);
return par;
}
int judge(int player, int computer){
if((player == 1 || player == 2) && (player == computer-1)){
printf("君の勝ち\n");
return 1;
}else if(player == 3 && computer == 1){
printf("君の勝ち\n");
return 1;
}else if(player == 1 && computer == 3){
printf("CPUの勝ち\n");
return 2;
}else if((player == 2 || player == 3) && (player == computer+1)){
printf("CPUの勝ち\n");
return 2;
}else if(player == computer){
printf("あいこ\n");
return 0;
}else{
printf("不正な手です。\n");
return 0;
}
}
void hand(int somehand){
switch(somehand){
case 1: printf("ぐー");
break;
case 2: printf("ちょき");
break;
case 3: printf("ぱー");
break;
}
}
int main(void){
int x;
int myhand, cpuhand;
int mywin, cpuwin;
mywin = 0;
cpuwin = 0;
printf("じゃんけんしようよ!\n");
printf("数字の1が[ぐー],2が[ちょき],3が[ぱー]だよ!\n");
while(mywin < 3 && cpuwin < 3){
printf("じゃん、けん、...\n");
scanf("%d", &myhand);
cpuhand = randum();
hand(myhand);
printf(" 対 ");
hand(cpuhand);
printf("\n");
x = judge(myhand, cpuhand);
switch(x){
case 0: break;
case 1: mywin++;
break;
case 2: cpuwin++;
break;
}
printf("%d 対 %d\n", mywin, cpuwin);
}
if(mywin == 3){
printf("あなたの勝ちです。\n");
}else if(cpuwin == 3){
printf("私の勝ちです。\n");
}else{
printf("ERROR\n");
}
scanf("%d", &x);
return 0;
}