回答編集履歴

1

説明の追加

2018/04/29 03:27

投稿

退会済みユーザー
test CHANGED
@@ -2,21 +2,21 @@
2
2
 
3
3
  プログラムの都合上 Rock: 0, Scissors: 1, Paper: 2にしております。
4
4
 
5
- また、対戦相手はcpuで乱数を利用しています。
5
+
6
6
 
7
7
  ジャンケンの判定をするところですが
8
8
 
9
- 重要になってくるのが(あなたの手 - cpuの手 + 3) % 3です。この値をResult_numと名づけることにします。例えば、
9
+ 重要になってくるのが(user1の手 - user2の手 + 3) % 3です。この値をResult_numと名づけることにします。例えば、
10
10
 
11
- |あなたの手|cpuの手|結果|Result_num|
11
+ |user1の手|user2の手|結果|Result_num|
12
12
 
13
13
  |:--|:--:|--:|
14
14
 
15
15
  |Rock|Rock|Draw|0|
16
16
 
17
- |Rock|Paper|Your_lose|1|
17
+ |Rock|Paper|user1 lose|1|
18
18
 
19
- |Scissors|Paper|Your_win|2|
19
+ |Scissors|Paper|user2 win|2|
20
20
 
21
21
 
22
22
 
@@ -38,7 +38,7 @@
38
38
 
39
39
  ```
40
40
 
41
- char result_text[3][15] = {"Draw","Your_Lose...","Your_Win!!"};
41
+ char result_text[3][15] = {"Draw","user1 Lose","user1 Win!!"};
42
42
 
43
43
  ```
44
44
 
@@ -48,23 +48,19 @@
48
48
 
49
49
  私が書いたソースコードを載せておきます。
50
50
 
51
+
52
+
51
53
  ```C
52
54
 
53
55
  #include <stdio.h>
54
56
 
55
57
  #include <stdlib.h>
56
58
 
57
- #include <time.h>
58
-
59
59
 
60
60
 
61
61
  #define BUFSIZE 256
62
62
 
63
63
  #define HAND 3
64
-
65
-
66
-
67
- void judge(int,int);
68
64
 
69
65
 
70
66
 
@@ -76,29 +72,23 @@
76
72
 
77
73
  char buf[BUFSIZE];
78
74
 
79
- char result_text[3][15] = {"Draw","Your_Lose...","Your_Win!!"};
75
+ char result_text[HAND][20] = {"Draw","user1 Lose","user1 Win"};
80
76
 
81
- char hand[3][10] = {"Rock","Scissors","Paper"};
77
+ char hand[HAND][10] = {"Rock","Scissors","Paper"};
82
78
 
83
79
  int i;
84
80
 
85
81
  int count = 0;
86
82
 
87
- int your_hand;
83
+ int user_hand[2];
88
84
 
89
- int cpu_hand;
85
+ int user_point[2] = {0,0};
90
86
 
91
87
  int result_num;
92
88
 
93
- int your_point = 0;
94
-
95
- int cpu_point = 0;
96
-
97
89
  int result;
98
90
 
99
- srand(time(NULL));
91
+
100
-
101
-
102
92
 
103
93
  while(1){
104
94
 
@@ -106,51 +96,45 @@
106
96
 
107
97
  printf("Rock : 0 , Scissors: 1, Paper : 2\n");
108
98
 
109
- do{
99
+ for(i = 0; i < 2; i++){
110
100
 
111
- fgets(buf,sizeof(buf),stdin);
101
+ do{
112
102
 
113
- your_hand = atoi(buf);
103
+ fgets(buf,sizeof(buf),stdin);
114
104
 
115
- if(your_hand < 0 || your_hand > 2){
105
+ user_hand[i] = atoi(buf);
116
106
 
117
- printf("再入力してください。\n");
107
+ if(user_hand[i] < 0 || user_hand[i] > 2){
118
108
 
119
- }
109
+ printf("再入力してください。\n");
120
110
 
121
- }while(your_hand < 0 || your_hand > 2);
111
+ }
122
112
 
123
- cpu_hand = rand() % 3;
113
+ }while(user_hand[i] < 0 || user_hand[i] > 2);
124
114
 
125
- result = (your_hand - cpu_hand + 3) % 3;
115
+ }
126
-
127
- printf("あなた:%s cpu:%s",hand[your_hand],hand[cpu_hand]);
128
-
129
- printf("%s\n",result_text[result]);
130
116
 
131
117
 
132
118
 
133
- switch(result){
119
+ result = (user_hand[0] - user_hand[1] + 3) % HAND;
134
120
 
135
- case 1:
121
+ printf("user1:%s user2:%s\n",hand[user_hand[0]],hand[user_hand[1]]);
136
122
 
137
- cpu_point += (cpu_hand + 1) * 3;
123
+
138
124
 
139
- break;
125
+ printf("%s \n",result_text[result]);
140
126
 
141
- case 2:
127
+
142
128
 
143
- your_point += (your_hand + 1) * 3;
129
+ if(result != 0){
144
130
 
145
- break;
146
-
147
- default:
131
+ user_point[result - 1] += (user_hand[result - 1] + 1) * 3;
148
-
149
- break;
150
132
 
151
133
  }
152
134
 
135
+
136
+
153
- printf("あなた:%d cpu:%d\n",your_point,cpu_point);
137
+ printf("user1:%d user2:%d\n",user_point[0],user_point[1]);
154
138
 
155
139
  count++;
156
140
 
@@ -160,7 +144,7 @@
160
144
 
161
145
  }
162
146
 
163
- else if(your_point >= 21 || cpu_point >= 21){
147
+ else if(user_point[0] >= 21 || user_point[1] >= 21){
164
148
 
165
149
  break;
166
150
 
@@ -170,10 +154,14 @@
170
154
 
171
155
  printf("終了\n");
172
156
 
173
- printf("あなたの点数:%d cpuの点数:%d\n",your_point,cpu_point);
157
+ printf("user1の点数:%d user2の点数:%d\n",user_point[0],user_point[1]);
174
158
 
175
159
  return 0;
176
160
 
177
161
  }
178
162
 
163
+
164
+
165
+
166
+
179
167
  ```