質問編集履歴

3

コードの修正

2020/11/27 06:27

投稿

garudain
garudain

スコア1

test CHANGED
File without changes
test CHANGED
@@ -26,15 +26,15 @@
26
26
 
27
27
  ```
28
28
 
29
- public partial class Form1 : Form
29
+ public partial class Form1 : Form
30
30
 
31
31
  {
32
32
 
33
- System.Random r = new System.Random();
33
+ Random r = new Random();
34
34
 
35
35
  int[] array_match_result = new int[0];
36
36
 
37
-
37
+
38
38
 
39
39
 
40
40
 
@@ -476,6 +476,14 @@
476
476
 
477
477
  return 0;
478
478
 
479
+
480
+
481
+
482
+
483
+ }
484
+
485
+
486
+
479
487
  ```
480
488
 
481
489
  ここに言語名を入力

2

コードの追加

2020/11/27 06:27

投稿

garudain
garudain

スコア1

test CHANGED
File without changes
test CHANGED
@@ -26,10 +26,342 @@
26
26
 
27
27
  ```
28
28
 
29
+ public partial class Form1 : Form
30
+
31
+ {
32
+
33
+ System.Random r = new System.Random();
34
+
29
- private int Syouritu(int rate, ref string grades)
35
+ int[] array_match_result = new int[0];
36
+
37
+
38
+
39
+
40
+
41
+ public Form1()
30
42
 
31
43
  {
32
44
 
45
+ InitializeComponent();
46
+
47
+ }
48
+
49
+
50
+
51
+ private void Form1_Load(object sender, EventArgs e)
52
+
53
+ {
54
+
55
+ this.picCPU.Image = null;
56
+
57
+ this.picYou.Image = null;
58
+
59
+ this.lblResult.Text = "";
60
+
61
+ }
62
+
63
+
64
+
65
+ private void btnGoo_Click(object sender, EventArgs e)
66
+
67
+ {
68
+
69
+ MatchStart(0);
70
+
71
+ }
72
+
73
+
74
+
75
+ private void btnChoki_Click(object sender, EventArgs e)
76
+
77
+ {
78
+
79
+ MatchStart(1);
80
+
81
+ }
82
+
83
+
84
+
85
+ private void btnPar_Click(object sender, EventArgs e)
86
+
87
+ {
88
+
89
+ MatchStart(2);
90
+
91
+ }
92
+
93
+
94
+
95
+ private void MatchStart(int my_hand)
96
+
97
+ {
98
+
99
+ string message = "";
100
+
101
+ string mess = "";
102
+
103
+ string grades = "";
104
+
105
+
106
+
107
+ int cpu_hand = GetCpuHand();
108
+
109
+
110
+
111
+ this.picYou.Image = GetJankenImage(my_hand);
112
+
113
+ this.picCPU.Image = GetJankenImage(cpu_hand);
114
+
115
+
116
+
117
+ int judge = JadgeJanken(my_hand, cpu_hand);
118
+
119
+ int hantei = JadgeJanken(my_hand, cpu_hand);
120
+
121
+ int rate = JadgeJanken(my_hand, cpu_hand);
122
+
123
+
124
+
125
+
126
+
127
+ Array.Resize(ref array_match_result, array_match_result.Length + 1);
128
+
129
+ array_match_result[array_match_result.Length - 1] = judge;
130
+
131
+
132
+
133
+
134
+
135
+ int ret = ConvertVictoryMessage(judge, ref message);
136
+
137
+
138
+
139
+ int ret2 = ConvertVictory(hantei, ref mess);
140
+
141
+
142
+
143
+ int ret3 = Syouritu(rate, ref grades);
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+ label2.Text = "あなたは";
152
+
153
+ label3.Text = "でわたしの";
154
+
155
+
156
+
157
+ if (ret == 0)
158
+
159
+ {
160
+
161
+ this.lblResult.Text = message;
162
+
163
+ }
164
+
165
+ else
166
+
167
+ {
168
+
169
+ this.lblResult.Text = "不正な結果が返ってきました。";
170
+
171
+ }
172
+
173
+
174
+
175
+ if(ret2 == 0)
176
+
177
+ {
178
+
179
+ this.label4.Text = mess;
180
+
181
+ }
182
+
183
+ else
184
+
185
+ {
186
+
187
+ this.label4.Text = "不正な結果が返ってきました。";
188
+
189
+ }
190
+
191
+
192
+
193
+ if (ret3 == 0)
194
+
195
+ {
196
+
197
+ this.WinRate.Text = grades;
198
+
199
+ }
200
+
201
+ else
202
+
203
+ {
204
+
205
+ this.WinRate.Text = "不正な結果が返ってきました。";
206
+
207
+ }
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+ }
218
+
219
+
220
+
221
+ private int GetCpuHand()
222
+
223
+ {
224
+
225
+ int cpu_hand = r.Next(3);
226
+
227
+
228
+
229
+ if (cpu_hand < 0 && cpu_hand > 2)
230
+
231
+ {
232
+
233
+ return -1;
234
+
235
+ }
236
+
237
+
238
+
239
+ return cpu_hand;
240
+
241
+ }
242
+
243
+
244
+
245
+ private Image GetJankenImage(int index)
246
+
247
+ {
248
+
249
+ if (index < 0 && index > 2)
250
+
251
+ {
252
+
253
+ return null;
254
+
255
+ }
256
+
257
+
258
+
259
+ return imgJankenList.Images[index];
260
+
261
+ }
262
+
263
+
264
+
265
+ private int JadgeJanken(int my_hand, int cpu_hand)
266
+
267
+ {
268
+
269
+ return (my_hand - cpu_hand + 3) % 3;
270
+
271
+ }
272
+
273
+
274
+
275
+ private int ConvertVictoryMessage(int judge, ref string victory)
276
+
277
+ {
278
+
279
+ switch (judge)
280
+
281
+ {
282
+
283
+ case 0:
284
+
285
+ victory = "";
286
+
287
+ break;
288
+
289
+ case 1:
290
+
291
+ victory = "負け";
292
+
293
+ break;
294
+
295
+ case 2:
296
+
297
+ victory = "勝ち";
298
+
299
+ break;
300
+
301
+ default:
302
+
303
+ victory = "";
304
+
305
+ return -1;
306
+
307
+ }
308
+
309
+ return 0;
310
+
311
+
312
+
313
+ }
314
+
315
+
316
+
317
+ private int ConvertVictory(int hantei, ref string mess)
318
+
319
+ {
320
+
321
+ switch (hantei)
322
+
323
+ {
324
+
325
+ case 0:
326
+
327
+ mess = "であいこ";
328
+
329
+ break;
330
+
331
+ case 1:
332
+
333
+ mess = "であなたの";
334
+
335
+ break;
336
+
337
+ case 2:
338
+
339
+ mess = "であなたの";
340
+
341
+ break;
342
+
343
+ default:
344
+
345
+ mess = "";
346
+
347
+ return -1;
348
+
349
+ }
350
+
351
+
352
+
353
+ return 0;
354
+
355
+
356
+
357
+ }
358
+
359
+
360
+
361
+ private int Syouritu(int rate, ref string grades)
362
+
363
+ {
364
+
33
365
 
34
366
 
35
367
  switch (rate)
@@ -144,15 +476,9 @@
144
476
 
145
477
  return 0;
146
478
 
147
-
148
-
149
-
150
-
151
- }
479
+ ```
152
-
153
-
154
-
480
+
155
- ```ここに言語名を入力
481
+ ここに言語名を入力
156
482
 
157
483
  ソースコード
158
484
 

1

コードの修正

2020/11/27 05:38

投稿

garudain
garudain

スコア1

test CHANGED
File without changes
test CHANGED
@@ -23,6 +23,8 @@
23
23
 
24
24
 
25
25
  ### 該当のソースコード
26
+
27
+ ```
26
28
 
27
29
  private int Syouritu(int rate, ref string grades)
28
30
 
@@ -148,6 +150,8 @@
148
150
 
149
151
  }
150
152
 
153
+
154
+
151
155
  ```ここに言語名を入力
152
156
 
153
157
  ソースコード