回答編集履歴
4
説明文修正
test
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Player や Rondom の生成は 1回だけにしましょう。
|
2
2
|
actionPerformedメソッドからは即座に復帰しないといけません。
|
3
3
|
actionPerformedはボタンが押されたときの1回分の処理を書きましょう。
|
4
|
-
win, lose の回数はコンストラクタで初期化し、actionPerformed で 3回勝
|
4
|
+
win, lose の回数はコンストラクタで初期化し、actionPerformed で 3回勝負がついたら処理を終わらせればいいです。
|
5
5
|
|
6
6
|
```java
|
7
7
|
public class Player implements ActionListener {
|
3
勝利判定を先にする
test
CHANGED
@@ -71,10 +71,10 @@
|
|
71
71
|
|
72
72
|
void finish() {
|
73
73
|
String judge;
|
74
|
-
if
|
74
|
+
if( win >= 3) {
|
75
|
+
judge = "Congratulations!!<br>You Win!!";
|
76
|
+
} else if ( lose >= 3) {
|
75
77
|
judge = "You Lose...";
|
76
|
-
} else if( win >= 3) {
|
77
|
-
judge = "Congratulations!!<br>You Win!!";
|
78
78
|
} else {
|
79
79
|
judge = "Wow...<br>You Drew...";
|
80
80
|
}
|
2
長い行を改行
test
CHANGED
@@ -80,7 +80,10 @@
|
|
80
80
|
}
|
81
81
|
|
82
82
|
Panel.headerLabel.setText("Game Over !!");
|
83
|
-
Panel.contentsLabel.setText("<html><body><center>" + judge +
|
83
|
+
Panel.contentsLabel.setText("<html><body><center>" + judge +
|
84
|
+
"<br>You:" + win + " vs Computer:" + lose +
|
85
|
+
"</center></body></html>");
|
86
|
+
}
|
84
87
|
}
|
85
88
|
```
|
86
89
|
|
1
もう一つの質問に合わせて表示内容を変更
test
CHANGED
@@ -35,11 +35,10 @@
|
|
35
35
|
}
|
36
36
|
|
37
37
|
public void actionPerformed(ActionEvent e) {
|
38
|
-
String command = e.getActionCommand();
|
39
|
-
|
40
|
-
if (
|
38
|
+
if (isFinish()) return;
|
41
39
|
|
42
40
|
int playerHand = 0;
|
41
|
+
String command = e.getActionCommand();
|
43
42
|
if (command.equals("Rock")) playerHand = 0;
|
44
43
|
else if (command.equals("Scissors")) playerHand = 1;
|
45
44
|
else if (command.equals("Paper")) playerHand = 2;
|
@@ -61,10 +60,27 @@
|
|
61
60
|
lose++;
|
62
61
|
}
|
63
62
|
|
64
|
-
if (
|
63
|
+
if (isFinish()) {
|
65
|
-
|
64
|
+
finish();
|
66
65
|
}
|
67
66
|
}
|
67
|
+
|
68
|
+
boolean isFinish() {
|
69
|
+
return win >= 3 || lose >= 3;
|
70
|
+
}
|
71
|
+
|
72
|
+
void finish() {
|
73
|
+
String judge;
|
74
|
+
if ( lose >= 3) {
|
75
|
+
judge = "You Lose...";
|
76
|
+
} else if( win >= 3) {
|
77
|
+
judge = "Congratulations!!<br>You Win!!";
|
78
|
+
} else {
|
79
|
+
judge = "Wow...<br>You Drew...";
|
80
|
+
}
|
81
|
+
|
82
|
+
Panel.headerLabel.setText("Game Over !!");
|
83
|
+
Panel.contentsLabel.setText("<html><body><center>" + judge + "<br>You:" + win + " vs Computer:" + lose + "</center></body></html>"); }
|
68
84
|
}
|
69
85
|
```
|
70
86
|
|