所以我是新来的和一般的编程我一直在研究一个摇滚纸剪刀游戏,用户输入字母并与电脑对战,但我的输入有时被忽略,游戏重新开始其他时间播放我花了无数个小时试图弄清楚为什么会这样。这是代码
答案 0 :(得分:1)
添加else语句,并在其中打印输入和计算机的值。你会知道你没有处理的组合。
像...这样的东西。
}else if(input == 3 && computer == 3){
report(computer,"tie with the computer");
else {
System.out.println("input: " + input + "computer: " + computer);
}
答案 1 :(得分:0)
方法.nextInt(n)
生成一个整数,包括0
并包括n
(在您的情况下为0
至2
)。基本上,当计算机生成0
时,它始终“忽略”您的输入,因为没有if
条件成立。要解决您的问题并生成从1
到n
的号码,请使用.nextInt(n) + 1
。