我正在为一个ROCK PAPER SCISSORS项目工作,我正在尝试使用一种方法来打印谁赢得比赛,并且还返回一个我用来确定谁获胜最多的值。
然而在第一种方法中,当我将方法分配给一个值来使用它时,它打印出evaluate方法中的语句,是否有任何解决方法或者我是否必须创建另一个方法来执行相同的操作打印报表?
(userWins和computerWins在main()中声明并初始化)
main( ) {
int userWins = 0;
int computerWins = 0;
.....
int value = winEvaluation(userChoice, computerChoice);
if (value == 1){
userWins++;
} else if (value == 2){
computerWins++;
} else{
}
System.out.prinln("user wins: " + userWins + " computer wins: " + computerWins);
}
private static int evaluate(int userChoice, int computerChoice) {
int winValue = 0;
String win = "You win.";
String lose = "I win.";
String draw = "We picked the same thing! This round is a draw.";
if( userChoice == 1) {
if(computerChoice == 1){
System.out.println(draw);
winValue = 0;
}else if(computerChoice == 2){
System.out.print("PAPER covers ROCK." );
System.out.println(lose);
winValue = 2;
}else {
System.out.print("ROCK breaks SCISSORS.");
System.out.println(win);
winValue = 1;
}
}else if (userChoice == 2 ) {
if (computerChoice == 1){
System.out.print("PAPER covers ROCK.");
System.out.println(win);
winValue = 1;
}else if (computerChoice == 2){
System.out.println(draw);
winValue = 0;
}else {
System.out.print("SCISSORS cuts PAPER.");
System.out.println(lose);
winValue = 2;
}
}else if (userChoice == 3){
if (computerChoice == 1){
System.out.print("ROCK breaks SCISSORS.");
System.out.println(lose);
winValue = 2;
}else if (computerChoice == 2){
System.out.print("SCISSORS cuts PAPER.");
System.out.println(win);
winValue = 1;
}else {
System.out.println(draw);
winValue = 0;
}
}
return winValue;
}