質問編集履歴

7

コードの一般化

2020/12/14 04:57

投稿

garudain
garudain

スコア1

test CHANGED
File without changes
test CHANGED
@@ -338,27 +338,15 @@
338
338
 
339
339
  ### 試したこと
340
340
 
341
- ![イメージ説明](7a3ae396ad983398f1a4cefe10cdcc4b.png)
341
+
342
-
343
- 初期画面
342
+
344
-
345
-
346
-
347
-
348
-
349
-
350
-
351
-
352
-
353
-
354
-
355
- ![イメージ説明](6dee8fd8656586fe91a180844b7b123a.png)
343
+
356
-
357
- ここからウィンドウを閉じた際に初期の状態に戻したいです。
344
+
358
-
359
-
360
-
361
- ![イメージ説明](492e0d4dbd23fe4f4b973ce615acae59.png)
345
+
346
+
347
+
348
+
349
+
362
350
 
363
351
 
364
352
 

6

コードの修正

2020/12/14 04:57

投稿

garudain
garudain

スコア1

test CHANGED
File without changes
test CHANGED
@@ -20,604 +20,372 @@
20
20
 
21
21
  ```C#
22
22
 
23
+
24
+
25
+
26
+
23
- public partial class Form1 : Form
27
+ private void MatchStart(int my_hand)
24
-
28
+
25
- {
29
+ {
30
+
26
-
31
+ string message = "";
32
+
33
+ string mess = "";
34
+
35
+ string grades = "";
36
+
37
+
38
+
27
- Random r = new Random();
39
+ int cpu_hand = GetCpuHand();
40
+
41
+
42
+
28
-
43
+ this.picYou.Image = GetJankenImage(my_hand);
44
+
45
+ this.picCPU.Image = GetJankenImage(cpu_hand);
46
+
47
+
48
+
49
+ int judge = JadgeJanken(my_hand, cpu_hand);
50
+
51
+ int hantei = JadgeJanken(my_hand, cpu_hand);
52
+
53
+ int rate = JadgeJanken(my_hand, cpu_hand);
54
+
55
+
56
+
57
+
58
+
59
+ Array.Resize(ref array_match_result, array_match_result.Length + 1);
60
+
29
- int[] array_match_result = new int[0];
61
+ array_match_result[array_match_result.Length - 1] = judge;
62
+
63
+
64
+
65
+
66
+
30
-
67
+ int ret = ConvertVictoryMessage(judge, ref message);
68
+
69
+
70
+
31
-
71
+ int ret2 = ConvertVictory(hantei, ref mess);
72
+
73
+
74
+
32
-
75
+ int ret3 = Syouritu(rate, ref grades);
76
+
77
+
78
+
79
+
80
+
81
+
82
+
33
-
83
+ label2.Text = "あなたは";
84
+
34
-
85
+ label3.Text = "でわたしの";
86
+
87
+
88
+
89
+ if (ret == 0)
90
+
91
+ {
92
+
93
+ this.lblResult.Text = message;
94
+
95
+ }
96
+
97
+ else
98
+
99
+ {
100
+
101
+ this.lblResult.Text = "不正な結果が返ってきました。";
102
+
103
+ }
104
+
105
+
106
+
107
+ if(ret2 == 0)
108
+
109
+ {
110
+
111
+ this.label4.Text = mess;
112
+
113
+ }
114
+
115
+ else
116
+
117
+ {
118
+
119
+ this.label4.Text = "不正な結果が返ってきました。";
120
+
121
+ }
122
+
123
+
124
+
35
- public Form1()
125
+ if (ret3 == 0)
126
+
127
+ {
128
+
129
+ this.WinRate.Text = grades;
130
+
131
+ }
132
+
133
+ else
134
+
135
+ {
136
+
137
+ this.WinRate.Text = "不正な結果が返ってきました。";
138
+
139
+ }
140
+
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+
149
+ }
150
+
151
+
152
+
153
+ ...
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+ private int Syouritu(int rate, ref string grades)
36
162
 
37
163
  {
38
164
 
165
+
166
+
167
+ switch (rate)
168
+
169
+ {
170
+
171
+ case 0:
172
+
173
+ grades = "";
174
+
175
+ break;
176
+
177
+ case 1:
178
+
179
+ grades = "";
180
+
181
+ break;
182
+
183
+ case 2:
184
+
185
+ grades = "";
186
+
187
+ break;
188
+
189
+ default:
190
+
191
+ grades = "";
192
+
193
+ return -1;
194
+
195
+ }
196
+
197
+
198
+
199
+ int cnt_win = 0;
200
+
201
+ int cnt_lose = 0;
202
+
203
+ int cnt_draw = 0;
204
+
205
+
206
+
207
+ foreach (int res in array_match_result)
208
+
209
+ {
210
+
211
+ switch (res)
212
+
213
+ {
214
+
215
+ case 0:
216
+
217
+ ++cnt_draw;
218
+
219
+ break;
220
+
221
+ case 1:
222
+
223
+ ++cnt_lose;
224
+
225
+ break;
226
+
227
+ case 2:
228
+
229
+ ++cnt_win;
230
+
231
+ break;
232
+
233
+ default:
234
+
235
+ break;
236
+
237
+
238
+
239
+ }
240
+
241
+ }
242
+
243
+
244
+
245
+ grades += array_match_result.Length.ToString() + "戦中 "
246
+
247
+ + "あなた:" + cnt_win.ToString() + "勝 "
248
+
249
+ + "わたし:" + cnt_lose.ToString() + "勝 "
250
+
251
+ + "あいこ:" + cnt_draw.ToString();
252
+
253
+
254
+
255
+ WinRate.Text = grades.ToString();
256
+
257
+
258
+
259
+
260
+
261
+ if (cnt_win == 5)
262
+
263
+ {
264
+
265
+
266
+
267
+ MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_win.ToString() + "勝"
268
+
269
+ + cnt_lose.ToString() + "敗" + cnt_draw.ToString() + "分けであなたが勝ちました。", "勝敗決定");
270
+
271
+
272
+
273
+ array_match_result = new int[0];
274
+
275
+ this.label2.Text = "";
276
+
277
+ this.label3.Text = "";
278
+
279
+ this.label4.Text = "";
280
+
281
+ lblResult.ResetText();
282
+
39
- InitializeComponent();
283
+ WinRate.ResetText();
284
+
285
+ picYou.Image = null;
286
+
287
+ picCPU.Image = null;
288
+
289
+ }
290
+
291
+ else if (cnt_lose == 5)
292
+
293
+ {
294
+
295
+
296
+
297
+ MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_lose.ToString() + "勝"
298
+
299
+ + cnt_win.ToString() + "敗" + cnt_draw.ToString() + "分けでわたしが勝ちました。", "勝敗決定") ;
300
+
301
+
302
+
303
+ array_match_result = new int[0];
304
+
305
+ this.label2.Text = "";
306
+
307
+ this.label3.Text = "";
308
+
309
+ this.label4.Text = "";
310
+
311
+ lblResult.ResetText();
312
+
313
+ WinRate.ResetText();
314
+
315
+ picYou.Image = null;
316
+
317
+ picCPU.Image = null;
318
+
319
+
320
+
321
+ }
322
+
323
+
324
+
325
+ return 0;
326
+
327
+
40
328
 
41
329
  }
42
330
 
43
331
 
44
332
 
45
- private void Form1_Load(object sender, EventArgs e)
46
-
47
- {
48
-
49
- this.picCPU.Image = null;
50
-
51
- this.picYou.Image = null;
52
-
53
- this.lblResult.Text = "";
54
-
55
- }
56
-
57
-
58
-
59
- private void btnGoo_Click(object sender, EventArgs e)
60
-
61
- {
62
-
63
- MatchStart(0);
64
-
65
- }
66
-
67
-
68
-
69
- private void btnChoki_Click(object sender, EventArgs e)
70
-
71
- {
72
-
73
- MatchStart(1);
74
-
75
- }
76
-
77
-
78
-
79
- private void btnPar_Click(object sender, EventArgs e)
80
-
81
- {
82
-
83
- MatchStart(2);
84
-
85
- }
86
-
87
-
88
-
89
- private void MatchStart(int my_hand)
90
-
91
- {
92
-
93
- string message = "";
94
-
95
- string mess = "";
96
-
97
- string grades = "";
98
-
99
-
100
-
101
- int cpu_hand = GetCpuHand();
102
-
103
-
104
-
105
- this.picYou.Image = GetJankenImage(my_hand);
106
-
107
- this.picCPU.Image = GetJankenImage(cpu_hand);
108
-
109
-
110
-
111
- int judge = JadgeJanken(my_hand, cpu_hand);
112
-
113
- int hantei = JadgeJanken(my_hand, cpu_hand);
114
-
115
- int rate = JadgeJanken(my_hand, cpu_hand);
116
-
117
-
118
-
119
-
120
-
121
- Array.Resize(ref array_match_result, array_match_result.Length + 1);
122
-
123
- array_match_result[array_match_result.Length - 1] = judge;
124
-
125
-
126
-
127
-
128
-
129
- int ret = ConvertVictoryMessage(judge, ref message);
130
-
131
-
132
-
133
- int ret2 = ConvertVictory(hantei, ref mess);
134
-
135
-
136
-
137
- int ret3 = Syouritu(rate, ref grades);
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
- label2.Text = "あなたは";
146
-
147
- label3.Text = "でわたしの";
333
+
334
+
335
+ ```
336
+
337
+
338
+
339
+ ### 試したこと
340
+
341
+ ![イメージ説明](7a3ae396ad983398f1a4cefe10cdcc4b.png)
342
+
343
+ 初期画面
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+
354
+
355
+ ![イメージ説明](6dee8fd8656586fe91a180844b7b123a.png)
356
+
357
+ ここからウィンドウを閉じた際に初期の状態に戻したいです。
358
+
359
+
360
+
361
+ ![イメージ説明](492e0d4dbd23fe4f4b973ce615acae59.png)
362
+
363
+
364
+
365
+ ```
366
+
367
+ if (cnt_win == 5)
368
+
369
+ {
370
+
371
+ MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_win.ToString() + "勝"
372
+
373
+ + cnt_lose.ToString() + "敗" + cnt_draw.ToString() + "分けであなたが勝ちました。", "勝敗決定");
148
374
 
149
375
 
150
376
 
151
- if (ret == 0)
152
-
153
- {
154
-
155
- this.lblResult.Text = message;
156
-
157
- }
158
-
159
- else
160
-
161
- {
162
-
163
- this.lblResult.Text = "不正な結果が返ってきました。";
164
-
165
- }
166
-
167
-
168
-
169
- if(ret2 == 0)
170
-
171
- {
172
-
173
- this.label4.Text = mess;
174
-
175
- }
176
-
177
- else
178
-
179
- {
180
-
181
- this.label4.Text = "不正な結果が返ってきました。";
182
-
183
- }
184
-
185
-
186
-
187
- if (ret3 == 0)
188
-
189
- {
190
-
191
- this.WinRate.Text = grades;
192
-
193
- }
194
-
195
- else
196
-
197
- {
198
-
199
- this.WinRate.Text = "不正な結果が返ってきました。";
200
-
201
- }
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
- }
212
-
213
-
214
-
215
- private int GetCpuHand()
216
-
217
- {
218
-
219
- int cpu_hand = r.Next(3);
220
-
221
-
222
-
223
- if (cpu_hand < 0 && cpu_hand > 2)
224
-
225
- {
226
-
227
- return -1;
228
-
229
- }
230
-
231
-
232
-
233
- return cpu_hand;
234
-
235
- }
236
-
237
-
238
-
239
- private Image GetJankenImage(int index)
240
-
241
- {
242
-
243
- if (index < 0 && index > 2)
244
-
245
- {
246
-
247
- return null;
248
-
249
- }
250
-
251
-
252
-
253
- return imgJankenList.Images[index];
254
-
255
- }
256
-
257
-
258
-
259
- private int JadgeJanken(int my_hand, int cpu_hand)
260
-
261
- {
262
-
263
- return (my_hand - cpu_hand + 3) % 3;
264
-
265
- }
266
-
267
-
268
-
269
- private int ConvertVictoryMessage(int judge, ref string victory)
270
-
271
- {
272
-
273
- switch (judge)
274
-
275
- {
276
-
277
- case 0:
278
-
279
- victory = "";
280
-
281
- break;
282
-
283
- case 1:
284
-
285
- victory = "負け";
286
-
287
- break;
288
-
289
- case 2:
290
-
291
- victory = "勝ち";
292
-
293
- break;
294
-
295
- default:
296
-
297
- victory = "";
298
-
299
- return -1;
300
-
301
- }
302
-
303
- lblResult.Text = victory.ToString();
304
-
305
- return 0;
306
-
307
-
308
-
309
-
310
-
311
- }
312
-
313
-
314
-
315
- private int ConvertVictory(int hantei, ref string mess)
316
-
317
- {
318
-
319
- switch (hantei)
320
-
321
- {
322
-
323
- case 0:
324
-
325
- mess = "であいこ";
326
-
327
- break;
328
-
329
- case 1:
330
-
331
- mess = "であなたの";
332
-
333
- break;
334
-
335
- case 2:
336
-
337
- mess = "であなたの";
338
-
339
- break;
340
-
341
- default:
342
-
343
- mess = "";
344
-
345
- return -1;
346
-
347
- }
348
-
349
- label4.Text = mess.ToString();
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
-
365
-
366
-
367
- switch (rate)
368
-
369
- {
370
-
371
- case 0:
372
-
373
- grades = "";
374
-
375
- break;
376
-
377
- case 1:
378
-
379
- grades = "";
380
-
381
- break;
382
-
383
- case 2:
384
-
385
- grades = "";
386
-
387
- break;
388
-
389
- default:
390
-
391
- grades = "";
392
-
393
- return -1;
394
-
395
- }
396
-
397
-
398
-
399
- int cnt_win = 0;
400
-
401
- int cnt_lose = 0;
402
-
403
- int cnt_draw = 0;
404
-
405
-
406
-
407
- foreach (int res in array_match_result)
408
-
409
- {
410
-
411
- switch (res)
412
-
413
- {
414
-
415
- case 0:
416
-
417
- ++cnt_draw;
418
-
419
- break;
420
-
421
- case 1:
422
-
423
- ++cnt_lose;
424
-
425
- break;
426
-
427
- case 2:
428
-
429
- ++cnt_win;
430
-
431
- break;
432
-
433
- default:
434
-
435
- break;
436
-
437
-
438
-
439
- }
440
-
441
- }
442
-
443
-
444
-
445
- grades += array_match_result.Length.ToString() + "戦中 "
446
-
447
- + "あなた:" + cnt_win.ToString() + "勝 "
448
-
449
- + "わたし:" + cnt_lose.ToString() + "勝 "
450
-
451
- + "あいこ:" + cnt_draw.ToString();
452
-
453
-
454
-
455
- WinRate.Text = grades.ToString();
456
-
457
-
458
-
459
-
460
-
461
- if (cnt_win == 5)
462
-
463
- {
464
-
465
-
466
-
467
- MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_win.ToString() + "勝"
468
-
469
- + cnt_lose.ToString() + "敗" + cnt_draw.ToString() + "分けであなたが勝ちました。", "勝敗決定");
470
-
471
-
472
-
473
377
  array_match_result = new int[0];
474
378
 
475
- this.label2.Text = "";
379
+ this.Controls.Clear(); //画面コントロール削除
476
-
380
+
477
- this.label3.Text = "";
381
+ InitializeComponent(); //コントロール再設定
478
-
479
- this.label4.Text = "";
382
+
480
-
481
- lblResult.ResetText();
383
+
482
-
483
- WinRate.ResetText();
384
+
484
-
485
- picYou.Image = null;
486
-
487
- picCPU.Image = null;
488
-
489
- }
385
+ }
490
-
491
- else if (cnt_lose == 5)
492
-
493
- {
494
-
495
-
496
-
497
- MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_lose.ToString() + "勝"
498
-
499
- + cnt_win.ToString() + "敗" + cnt_draw.ToString() + "分けでわたしが勝ちました。", "勝敗決定") ;
500
-
501
-
502
-
503
- array_match_result = new int[0];
504
-
505
- this.label2.Text = "";
506
-
507
- this.label3.Text = "";
508
-
509
- this.label4.Text = "";
510
-
511
- lblResult.ResetText();
512
-
513
- WinRate.ResetText();
514
-
515
- picYou.Image = null;
516
-
517
- picCPU.Image = null;
518
-
519
-
520
-
521
- }
522
-
523
-
524
-
525
- return 0;
526
-
527
-
528
-
529
- }
530
-
531
-
532
-
533
- private void btnRse_Click(object sender, EventArgs e)
534
-
535
- {
536
-
537
- array_match_result = new int[0];
538
-
539
- this.label2.Text = "";
540
-
541
- this.label3.Text = "";
542
-
543
- this.label4.Text = "";
544
-
545
- lblResult.Text = "";
546
-
547
- WinRate.Text = "";
548
-
549
- picYou.Image = null;
550
-
551
- picCPU.Image = null;
552
-
553
-
554
-
555
- }
556
-
557
-
558
-
559
- }
560
-
561
- }
562
-
563
-
564
-
565
-
566
386
 
567
387
  ```
568
388
 
569
-
570
-
571
- ### 試したこと!
572
-
573
- ![イメージ説明](7a3ae396ad983398f1a4cefe10cdcc4b.png)
574
-
575
- 初期画面
576
-
577
-
578
-
579
-
580
-
581
-
582
-
583
-
584
-
585
-
586
-
587
- ![イメージ説明](6dee8fd8656586fe91a180844b7b123a.png)
588
-
589
- ここからウィンドウを閉じた際に初期の状態に戻したいです。
590
-
591
-
592
-
593
- ![イメージ説明](492e0d4dbd23fe4f4b973ce615acae59.png)
594
-
595
-
596
-
597
- ```
598
-
599
- if (cnt_win == 5)
600
-
601
- {
602
-
603
- MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_win.ToString() + "勝"
604
-
605
- + cnt_lose.ToString() + "敗" + cnt_draw.ToString() + "分けであなたが勝ちました。", "勝敗決定");
606
-
607
-
608
-
609
- array_match_result = new int[0];
610
-
611
- this.Controls.Clear(); //画面コントロール削除
612
-
613
- InitializeComponent(); //コントロール再設定
614
-
615
-
616
-
617
- }
618
-
619
- ```
620
-
621
389
  リセットボタンも作成したので、それと同じように行うのかと思いましたが、削除されたのは画像だけでした。
622
390
 
623
391
  ### 補足情報(FW/ツールのバージョンなど)

5

画像の追加

2020/12/02 06:58

投稿

garudain
garudain

スコア1

test CHANGED
File without changes
test CHANGED
@@ -568,7 +568,23 @@
568
568
 
569
569
 
570
570
 
571
+ ### 試したこと!
572
+
573
+ ![イメージ説明](7a3ae396ad983398f1a4cefe10cdcc4b.png)
574
+
575
+ 初期画面
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+
584
+
585
+
586
+
571
- ### 試したこと![イメージ説明](6dee8fd8656586fe91a180844b7b123a.png)
587
+ ![イメージ説明](6dee8fd8656586fe91a180844b7b123a.png)
572
588
 
573
589
  ここからウィンドウを閉じた際に初期の状態に戻したいです。
574
590
 

4

コードの修正

2020/11/30 07:01

投稿

garudain
garudain

スコア1

test CHANGED
File without changes
test CHANGED
@@ -462,11 +462,29 @@
462
462
 
463
463
  {
464
464
 
465
+
466
+
465
467
  MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_win.ToString() + "勝"
466
468
 
467
469
  + cnt_lose.ToString() + "敗" + cnt_draw.ToString() + "分けであなたが勝ちました。", "勝敗決定");
468
470
 
471
+
472
+
469
-
473
+ array_match_result = new int[0];
474
+
475
+ this.label2.Text = "";
476
+
477
+ this.label3.Text = "";
478
+
479
+ this.label4.Text = "";
480
+
481
+ lblResult.ResetText();
482
+
483
+ WinRate.ResetText();
484
+
485
+ picYou.Image = null;
486
+
487
+ picCPU.Image = null;
470
488
 
471
489
  }
472
490
 
@@ -474,11 +492,31 @@
474
492
 
475
493
  {
476
494
 
495
+
496
+
477
497
  MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_lose.ToString() + "勝"
478
498
 
479
- + cnt_win.ToString() + "敗" + cnt_draw.ToString() + "分けでわたしが勝ちました。", "勝敗決定");
499
+ + cnt_win.ToString() + "敗" + cnt_draw.ToString() + "分けでわたしが勝ちました。", "勝敗決定") ;
500
+
501
+
502
+
480
-
503
+ array_match_result = new int[0];
504
+
481
-
505
+ this.label2.Text = "";
506
+
507
+ this.label3.Text = "";
508
+
509
+ this.label4.Text = "";
510
+
511
+ lblResult.ResetText();
512
+
513
+ WinRate.ResetText();
514
+
515
+ picYou.Image = null;
516
+
517
+ picCPU.Image = null;
518
+
519
+
482
520
 
483
521
  }
484
522
 
@@ -498,19 +536,19 @@
498
536
 
499
537
  array_match_result = new int[0];
500
538
 
501
- label2.ResetText();
539
+ this.label2.Text = "";
502
-
540
+
503
- label3.ResetText();
541
+ this.label3.Text = "";
504
-
542
+
505
- label4.ResetText();
543
+ this.label4.Text = "";
506
-
544
+
507
- lblResult.ResetText();
545
+ lblResult.Text = "";
508
-
546
+
509
- WinRate.ResetText();
547
+ WinRate.Text = "";
510
-
548
+
511
- this.picYou.Image = null;
549
+ picYou.Image = null;
512
-
550
+
513
- this.picCPU.Image = null;
551
+ picCPU.Image = null;
514
552
 
515
553
 
516
554
 
@@ -520,6 +558,8 @@
520
558
 
521
559
  }
522
560
 
561
+ }
562
+
523
563
 
524
564
 
525
565
 

3

コードの修正

2020/11/30 06:51

投稿

garudain
garudain

スコア1

test CHANGED
File without changes
test CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  ```C#
22
22
 
23
- public partial class Form1 : Form
23
+ public partial class Form1 : Form
24
24
 
25
25
  {
26
26
 
@@ -300,169 +300,245 @@
300
300
 
301
301
  }
302
302
 
303
+ lblResult.Text = victory.ToString();
304
+
305
+ return 0;
306
+
307
+
308
+
309
+
310
+
311
+ }
312
+
313
+
314
+
315
+ private int ConvertVictory(int hantei, ref string mess)
316
+
317
+ {
318
+
319
+ switch (hantei)
320
+
321
+ {
322
+
323
+ case 0:
324
+
325
+ mess = "であいこ";
326
+
327
+ break;
328
+
329
+ case 1:
330
+
331
+ mess = "であなたの";
332
+
333
+ break;
334
+
335
+ case 2:
336
+
337
+ mess = "であなたの";
338
+
339
+ break;
340
+
341
+ default:
342
+
343
+ mess = "";
344
+
345
+ return -1;
346
+
347
+ }
348
+
349
+ label4.Text = mess.ToString();
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
+
365
+
366
+
367
+ switch (rate)
368
+
369
+ {
370
+
371
+ case 0:
372
+
373
+ grades = "";
374
+
375
+ break;
376
+
377
+ case 1:
378
+
379
+ grades = "";
380
+
381
+ break;
382
+
383
+ case 2:
384
+
385
+ grades = "";
386
+
387
+ break;
388
+
389
+ default:
390
+
391
+ grades = "";
392
+
393
+ return -1;
394
+
395
+ }
396
+
397
+
398
+
399
+ int cnt_win = 0;
400
+
401
+ int cnt_lose = 0;
402
+
403
+ int cnt_draw = 0;
404
+
405
+
406
+
407
+ foreach (int res in array_match_result)
408
+
409
+ {
410
+
411
+ switch (res)
412
+
413
+ {
414
+
415
+ case 0:
416
+
417
+ ++cnt_draw;
418
+
419
+ break;
420
+
421
+ case 1:
422
+
423
+ ++cnt_lose;
424
+
425
+ break;
426
+
427
+ case 2:
428
+
429
+ ++cnt_win;
430
+
431
+ break;
432
+
433
+ default:
434
+
435
+ break;
436
+
437
+
438
+
439
+ }
440
+
441
+ }
442
+
303
443
 
304
444
 
445
+ grades += array_match_result.Length.ToString() + "戦中 "
446
+
447
+ + "あなた:" + cnt_win.ToString() + "勝 "
448
+
449
+ + "わたし:" + cnt_lose.ToString() + "勝 "
450
+
451
+ + "あいこ:" + cnt_draw.ToString();
452
+
453
+
454
+
305
- lblResult.Text = victory.ToString();
455
+ WinRate.Text = grades.ToString();
456
+
457
+
458
+
459
+
460
+
461
+ if (cnt_win == 5)
462
+
463
+ {
464
+
465
+ MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_win.ToString() + "勝"
466
+
467
+ + cnt_lose.ToString() + "敗" + cnt_draw.ToString() + "分けであなたが勝ちました。", "勝敗決定");
468
+
469
+
470
+
471
+ }
472
+
473
+ else if (cnt_lose == 5)
474
+
475
+ {
476
+
477
+ MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_lose.ToString() + "勝"
478
+
479
+ + cnt_win.ToString() + "敗" + cnt_draw.ToString() + "分けでわたしが勝ちました。", "勝敗決定");
480
+
481
+
482
+
483
+ }
484
+
485
+
486
+
487
+ return 0;
488
+
489
+
490
+
491
+ }
492
+
493
+
494
+
495
+ private void btnRse_Click(object sender, EventArgs e)
496
+
497
+ {
498
+
499
+ array_match_result = new int[0];
500
+
501
+ label2.ResetText();
502
+
503
+ label3.ResetText();
504
+
505
+ label4.ResetText();
306
506
 
307
507
  lblResult.ResetText();
308
508
 
309
- return 0;
310
-
311
-
312
-
313
-
314
-
315
- }
316
-
317
-
318
-
319
- private int ConvertVictory(int hantei, ref string mess)
320
-
321
- {
322
-
323
- switch (hantei)
324
-
325
- {
326
-
327
- case 0:
328
-
329
- mess = "であいこ";
330
-
331
- break;
332
-
333
- case 1:
334
-
335
- mess = "であなたの";
336
-
337
- break;
338
-
339
- case 2:
340
-
341
- mess = "であなたの";
342
-
343
- break;
344
-
345
- default:
346
-
347
- mess = "";
348
-
349
- return -1;
350
-
351
- }
352
-
353
-
354
-
355
- label4.Text = mess.ToString();
356
-
357
- label4.ResetText();
358
-
359
- return 0;
360
-
361
-
362
-
363
- }
364
-
365
-
366
-
367
- private int Syouritu(int rate, ref string grades)
368
-
369
- {
370
-
371
-
372
-
373
- switch (rate)
374
-
375
- {
376
-
377
- case 0:
378
-
379
- grades = "";
380
-
381
- break;
382
-
383
- case 1:
384
-
385
- grades = "";
386
-
387
- break;
388
-
389
- case 2:
390
-
391
- grades = "";
392
-
393
- break;
394
-
395
- default:
396
-
397
- grades = "";
398
-
399
- return -1;
400
-
401
- }
402
-
403
-
404
-
405
- int cnt_win = 0;
406
-
407
- int cnt_lose = 0;
408
-
409
- int cnt_draw = 0;
410
-
411
-
412
-
413
- foreach (int res in array_match_result)
414
-
415
- {
416
-
417
- switch (res)
418
-
419
- {
420
-
421
- case 0:
422
-
423
- ++cnt_draw;
424
-
425
- break;
426
-
427
- case 1:
428
-
429
- ++cnt_lose;
430
-
431
- break;
432
-
433
- case 2:
434
-
435
- ++cnt_win;
436
-
437
- break;
438
-
439
- default:
440
-
441
- break;
442
-
443
-
444
-
445
- }
446
-
447
- }
448
-
449
-
450
-
451
- grades += array_match_result.Length.ToString() + "戦中 "
452
-
453
- + "あなた:" + cnt_win.ToString() + "勝 "
454
-
455
- + "わたし:" + cnt_lose.ToString() + "勝 "
456
-
457
- + "あいこ:" + cnt_draw.ToString();
458
-
459
-
460
-
461
- WinRate.Text = grades.ToString();
462
-
463
-
464
-
465
-
509
+ WinRate.ResetText();
510
+
511
+ this.picYou.Image = null;
512
+
513
+ this.picCPU.Image = null;
514
+
515
+
516
+
517
+ }
518
+
519
+
520
+
521
+ }
522
+
523
+
524
+
525
+
526
+
527
+ ```
528
+
529
+
530
+
531
+ ### 試したこと![イメージ説明](6dee8fd8656586fe91a180844b7b123a.png)
532
+
533
+ ここからウィンドウを閉じた際に初期の状態に戻したいです。
534
+
535
+
536
+
537
+ ![イメージ説明](492e0d4dbd23fe4f4b973ce615acae59.png)
538
+
539
+
540
+
541
+ ```
466
542
 
467
543
  if (cnt_win == 5)
468
544
 
@@ -474,86 +550,18 @@
474
550
 
475
551
 
476
552
 
553
+ array_match_result = new int[0];
554
+
555
+ this.Controls.Clear(); //画面コントロール削除
556
+
557
+ InitializeComponent(); //コントロール再設定
558
+
559
+
560
+
477
- }
561
+ }
478
-
479
- else if (cnt_lose == 5)
480
-
481
- {
482
-
483
-
484
-
485
- MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_lose.ToString() + "勝"
486
-
487
- + cnt_win.ToString() + "敗" + cnt_draw.ToString() + "分けでわたしが勝ちました。", "勝敗決定");
488
-
489
- }
490
-
491
-
492
-
493
- return 0;
494
-
495
-
496
-
497
- }
498
-
499
-
500
-
501
- private void btnRse_Click(object sender, EventArgs e)
502
-
503
- {
504
-
505
- array_match_result = new int[0];
506
-
507
- this.Controls.Clear(); //画面コントロール削除
508
-
509
- InitializeComponent(); //コントロール再設定
510
-
511
- }
512
-
513
-
514
-
515
- }
516
-
517
-
518
562
 
519
563
  ```
520
564
 
521
-
522
-
523
- ### 試したこと![イメージ説明](6dee8fd8656586fe91a180844b7b123a.png)
524
-
525
- ここからウィンドウを閉じた際に初期の状態に戻したいです。
526
-
527
-
528
-
529
- ![イメージ説明](492e0d4dbd23fe4f4b973ce615acae59.png)
530
-
531
-
532
-
533
- ```
534
-
535
- if (cnt_win == 5)
536
-
537
- {
538
-
539
- MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_win.ToString() + "勝"
540
-
541
- + cnt_lose.ToString() + "敗" + cnt_draw.ToString() + "分けであなたが勝ちました。", "勝敗決定");
542
-
543
-
544
-
545
- array_match_result = new int[0];
546
-
547
- this.Controls.Clear(); //画面コントロール削除
548
-
549
- InitializeComponent(); //コントロール再設定
550
-
551
-
552
-
553
- }
554
-
555
- ```
556
-
557
565
  リセットボタンも作成したので、それと同じように行うのかと思いましたが、削除されたのは画像だけでした。
558
566
 
559
567
  ### 補足情報(FW/ツールのバージョンなど)

2

コードの追加

2020/11/30 04:28

投稿

garudain
garudain

スコア1

test CHANGED
File without changes
test CHANGED
@@ -20,7 +20,303 @@
20
20
 
21
21
  ```C#
22
22
 
23
+ public partial class Form1 : Form
24
+
25
+ {
26
+
27
+ Random r = new Random();
28
+
29
+ int[] array_match_result = new int[0];
30
+
31
+
32
+
33
+
34
+
35
+ public Form1()
36
+
37
+ {
38
+
39
+ InitializeComponent();
40
+
41
+ }
42
+
43
+
44
+
45
+ private void Form1_Load(object sender, EventArgs e)
46
+
47
+ {
48
+
49
+ this.picCPU.Image = null;
50
+
51
+ this.picYou.Image = null;
52
+
53
+ this.lblResult.Text = "";
54
+
55
+ }
56
+
57
+
58
+
59
+ private void btnGoo_Click(object sender, EventArgs e)
60
+
61
+ {
62
+
63
+ MatchStart(0);
64
+
65
+ }
66
+
67
+
68
+
69
+ private void btnChoki_Click(object sender, EventArgs e)
70
+
71
+ {
72
+
73
+ MatchStart(1);
74
+
75
+ }
76
+
77
+
78
+
79
+ private void btnPar_Click(object sender, EventArgs e)
80
+
81
+ {
82
+
83
+ MatchStart(2);
84
+
85
+ }
86
+
87
+
88
+
89
+ private void MatchStart(int my_hand)
90
+
91
+ {
92
+
93
+ string message = "";
94
+
95
+ string mess = "";
96
+
97
+ string grades = "";
98
+
99
+
100
+
101
+ int cpu_hand = GetCpuHand();
102
+
103
+
104
+
105
+ this.picYou.Image = GetJankenImage(my_hand);
106
+
107
+ this.picCPU.Image = GetJankenImage(cpu_hand);
108
+
109
+
110
+
111
+ int judge = JadgeJanken(my_hand, cpu_hand);
112
+
113
+ int hantei = JadgeJanken(my_hand, cpu_hand);
114
+
115
+ int rate = JadgeJanken(my_hand, cpu_hand);
116
+
117
+
118
+
119
+
120
+
121
+ Array.Resize(ref array_match_result, array_match_result.Length + 1);
122
+
123
+ array_match_result[array_match_result.Length - 1] = judge;
124
+
125
+
126
+
127
+
128
+
129
+ int ret = ConvertVictoryMessage(judge, ref message);
130
+
131
+
132
+
133
+ int ret2 = ConvertVictory(hantei, ref mess);
134
+
135
+
136
+
137
+ int ret3 = Syouritu(rate, ref grades);
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+ label2.Text = "あなたは";
146
+
147
+ label3.Text = "でわたしの";
148
+
149
+
150
+
151
+ if (ret == 0)
152
+
153
+ {
154
+
155
+ this.lblResult.Text = message;
156
+
157
+ }
158
+
159
+ else
160
+
161
+ {
162
+
163
+ this.lblResult.Text = "不正な結果が返ってきました。";
164
+
165
+ }
166
+
167
+
168
+
169
+ if(ret2 == 0)
170
+
171
+ {
172
+
173
+ this.label4.Text = mess;
174
+
175
+ }
176
+
177
+ else
178
+
179
+ {
180
+
181
+ this.label4.Text = "不正な結果が返ってきました。";
182
+
183
+ }
184
+
185
+
186
+
187
+ if (ret3 == 0)
188
+
189
+ {
190
+
191
+ this.WinRate.Text = grades;
192
+
193
+ }
194
+
195
+ else
196
+
197
+ {
198
+
199
+ this.WinRate.Text = "不正な結果が返ってきました。";
200
+
201
+ }
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+ }
212
+
213
+
214
+
215
+ private int GetCpuHand()
216
+
217
+ {
218
+
219
+ int cpu_hand = r.Next(3);
220
+
221
+
222
+
223
+ if (cpu_hand < 0 && cpu_hand > 2)
224
+
225
+ {
226
+
227
+ return -1;
228
+
229
+ }
230
+
231
+
232
+
233
+ return cpu_hand;
234
+
235
+ }
236
+
237
+
238
+
239
+ private Image GetJankenImage(int index)
240
+
241
+ {
242
+
243
+ if (index < 0 && index > 2)
244
+
245
+ {
246
+
247
+ return null;
248
+
249
+ }
250
+
251
+
252
+
253
+ return imgJankenList.Images[index];
254
+
255
+ }
256
+
257
+
258
+
259
+ private int JadgeJanken(int my_hand, int cpu_hand)
260
+
261
+ {
262
+
263
+ return (my_hand - cpu_hand + 3) % 3;
264
+
265
+ }
266
+
267
+
268
+
269
+ private int ConvertVictoryMessage(int judge, ref string victory)
270
+
271
+ {
272
+
273
+ switch (judge)
274
+
275
+ {
276
+
277
+ case 0:
278
+
279
+ victory = "";
280
+
281
+ break;
282
+
283
+ case 1:
284
+
285
+ victory = "負け";
286
+
287
+ break;
288
+
289
+ case 2:
290
+
291
+ victory = "勝ち";
292
+
293
+ break;
294
+
295
+ default:
296
+
297
+ victory = "";
298
+
299
+ return -1;
300
+
301
+ }
302
+
303
+
304
+
305
+ lblResult.Text = victory.ToString();
306
+
307
+ lblResult.ResetText();
308
+
309
+ return 0;
310
+
311
+
312
+
313
+
314
+
315
+ }
316
+
317
+
318
+
23
- private int ConvertVictory(int hantei, ref string mess)
319
+ private int ConvertVictory(int hantei, ref string mess)
24
320
 
25
321
  {
26
322
 
@@ -58,7 +354,9 @@
58
354
 
59
355
  label4.Text = mess.ToString();
60
356
 
357
+ label4.ResetText();
358
+
61
- return 0;
359
+ return 0;
62
360
 
63
361
 
64
362
 
@@ -160,8 +458,6 @@
160
458
 
161
459
 
162
460
 
163
-
164
-
165
461
  WinRate.Text = grades.ToString();
166
462
 
167
463
 
@@ -176,6 +472,8 @@
176
472
 
177
473
  + cnt_lose.ToString() + "敗" + cnt_draw.ToString() + "分けであなたが勝ちました。", "勝敗決定");
178
474
 
475
+
476
+
179
477
  }
180
478
 
181
479
  else if (cnt_lose == 5)
@@ -188,74 +486,74 @@
188
486
 
189
487
  + cnt_win.ToString() + "敗" + cnt_draw.ToString() + "分けでわたしが勝ちました。", "勝敗決定");
190
488
 
489
+ }
490
+
491
+
492
+
493
+ return 0;
494
+
495
+
496
+
497
+ }
498
+
499
+
500
+
501
+ private void btnRse_Click(object sender, EventArgs e)
502
+
503
+ {
504
+
505
+ array_match_result = new int[0];
506
+
507
+ this.Controls.Clear(); //画面コントロール削除
508
+
509
+ InitializeComponent(); //コントロール再設定
510
+
511
+ }
512
+
513
+
514
+
515
+ }
516
+
517
+
518
+
519
+ ```
520
+
521
+
522
+
523
+ ### 試したこと![イメージ説明](6dee8fd8656586fe91a180844b7b123a.png)
524
+
525
+ ここからウィンドウを閉じた際に初期の状態に戻したいです。
526
+
527
+
528
+
529
+ ![イメージ説明](492e0d4dbd23fe4f4b973ce615acae59.png)
530
+
531
+
532
+
533
+ ```
534
+
535
+ if (cnt_win == 5)
536
+
537
+ {
538
+
539
+ MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_win.ToString() + "勝"
540
+
541
+ + cnt_lose.ToString() + "敗" + cnt_draw.ToString() + "分けであなたが勝ちました。", "勝敗決定");
542
+
191
543
 
192
544
 
545
+ array_match_result = new int[0];
546
+
547
+ this.Controls.Clear(); //画面コントロール削除
548
+
549
+ InitializeComponent(); //コントロール再設定
550
+
551
+
552
+
193
- }
553
+ }
194
-
195
- return 0;
196
-
197
-
198
-
199
-
200
-
201
- }
202
-
203
-
204
-
205
- private void btnRse_Click(object sender, EventArgs e)
206
-
207
- {
208
-
209
- array_match_result = new int[0];
210
-
211
- this.Controls.Clear(); //画面コントロール削除
212
-
213
- InitializeComponent(); //コントロール再設定
214
-
215
- }
216
-
217
-
218
-
219
- }
220
554
 
221
555
  ```
222
556
 
223
-
224
-
225
- ### 試したこと![イメージ説明](6dee8fd8656586fe91a180844b7b123a.png)
226
-
227
- ここからウィンドウを閉じた際に初期の状態に戻したいです。
228
-
229
-
230
-
231
- ![イメージ説明](492e0d4dbd23fe4f4b973ce615acae59.png)
232
-
233
-
234
-
235
- ```
236
-
237
- if (cnt_win == 5)
238
-
239
- {
240
-
241
- MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_win.ToString() + "勝"
242
-
243
- + cnt_lose.ToString() + "敗" + cnt_draw.ToString() + "分けであなたが勝ちました。", "勝敗決定");
244
-
245
-
246
-
247
- array_match_result = new int[0];
248
-
249
- this.Controls.Clear(); //画面コントロール削除
250
-
251
- InitializeComponent(); //コントロール再設定
252
-
253
-
254
-
255
- }
256
-
257
- ```
258
-
259
557
  リセットボタンも作成したので、それと同じように行うのかと思いましたが、削除されたのは画像だけでした。
260
558
 
261
559
  ### 補足情報(FW/ツールのバージョンなど)

1

コードの追加

2020/11/30 03:26

投稿

garudain
garudain

スコア1

test CHANGED
File without changes
test CHANGED
@@ -230,6 +230,32 @@
230
230
 
231
231
  ![イメージ説明](492e0d4dbd23fe4f4b973ce615acae59.png)
232
232
 
233
+
234
+
235
+ ```
236
+
237
+ if (cnt_win == 5)
238
+
239
+ {
240
+
241
+ MessageBox.Show(array_match_result.Length.ToString() + "戦中 " + cnt_win.ToString() + "勝"
242
+
243
+ + cnt_lose.ToString() + "敗" + cnt_draw.ToString() + "分けであなたが勝ちました。", "勝敗決定");
244
+
245
+
246
+
247
+ array_match_result = new int[0];
248
+
249
+ this.Controls.Clear(); //画面コントロール削除
250
+
251
+ InitializeComponent(); //コントロール再設定
252
+
253
+
254
+
255
+ }
256
+
257
+ ```
258
+
233
259
  リセットボタンも作成したので、それと同じように行うのかと思いましたが、削除されたのは画像だけでした。
234
260
 
235
261
  ### 補足情報(FW/ツールのバージョンなど)