我剛剛做了一個搖滾,剪刀,紙張遊戲,直到現在有點遠。我不再真正瞭解(嘗試了一段時間),當用戶或計算機首先擊中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();
}
}
請將這段代碼翻譯爲中文,只粘貼必要的代碼,而不能整個程序。 – Niemand 2014-11-03 10:57:51
好的就做吧!等一下。 – Thrillofit123 2014-11-03 10:58:49