【发布时间】:2014-11-03 10:42:29
【问题描述】:
我刚做了一个石头、剪刀、纸游戏,到目前为止已经走了一点路。我真的不知道(尝试了一段时间)当用户或计算机首先达到 3 分时让游戏停止。
我有一些想法来做一个 if 语句 == 3 = 获胜。但如果我这样做,那么按钮也应该被禁用..我在想类似的事情,但我不能再明白了!所以想法会很棒!
public void actionPerformed(ActionEvent e) {
int Choice= 0;
if(e.getSource() == exit) {
this.dispose();
System.exit(0);
}
else if(e.getSource() == newgame) {
this.dispose();
new RockScissorsPaper();
}
else if (e.getSource() == Rock) {
Choice= Rock;
}
else if (e.getSource() == Scissors) {
Choice= Scissors;
}
else {
Choice= Paper;
}
calculate(Choice);
}//actionPerformed
/ **
* Computer game selection is randomized and compared with the user
* Choice (method arguments). The game result is stored and displayed
* UI.
* /
public void calculate(int val){
//Get user choise
UserChoose= val;
// randomise the computer's choice and typing on the integer
ComputerChoose = (int)(Math.random() * 3);
//show result
resultatLabel.setHorizontalAlignment(0);
infoLabel.setHorizontalAlignment(0);
infoLabel.setText("Result round " + ++round +":");
if (UserChoose == ComputerChoose)
resultatLabel.setText("Tie!");
else if (UserChoose == Rock && ComputerChoose == Scissors ||
UserChoose == Scissors && ComputerChoose == Paper||
UserChoose == Paper && ComputerChoose == Rock) {
resultatLabel.setText("You win! One more game?");
användarResultat.setText(" Your wins: " + ++UserWins+ "st");
}
else {
resultatLabel.setText(" You Lose! Try again!");
datorResultat.setText(" Computer wins: " + ++computerWins + "st");
}
}
public static void main(String[] args) {
new RockScissorsPaper();
}
}
【问题讨论】:
-
请将这段代码翻译成英文并只粘贴必要的代码,而不是整个程序。
-
好的,会的!等等。