自己写的简易版
//2024.07.17
import java.util.Scanner;
import java.util.Random;
public class GuessingGame {
public static void main(String[] args) {
Tom tm = new Tom();
System.out.println("==============================================");
for (int i = 0; i < 3; i++) {
Random r = new Random();
tm.comGuessNum = r.nextInt(3);
Scanner myScanner = new Scanner(System.in);
System.out.print("Tom, please enter your guess num:(0-stone,1-scissors,2-paper.)");
tm.tomGuessNum = myScanner.nextInt();
tm.guess();
tm.showInfo();
}
System.out.println("guessing game is over, tom's winer times is " + tm.winCount);
}
}
class Tom {
int tomGuessNum;
int comGuessNum;
int winCount;
public int guess(){
if (tomGuessNum == 0) {
if (comGuessNum == 1) {
winCount++;
System.out.println("\t\t\t\t\tTom is winner!");
}
}else if (tomGuessNum == 1) {
if (comGuessNum == 2) {
winCount++;
System.out.println("t\t\t\t\tTom is winner!");
}
}else {
if (comGuessNum == 0) {
winCount++;
System.out.println("t\t\t\t\tTom is winner!");
}
}
return winCount;
}
public void showInfo(){
System.out.println("tomGuessNum\tcomGuessNum");
System.out.println(tomGuessNum + "\t\t" + comGuessNum);
System.out.println("==============================================");
}
}
运行结果截图: