我应该在写nim的游戏。我无法找出如何修复编译错误
找不到符号 - 方法 getPlayer()
另外,这是您看到的唯一问题吗?或者是否有其他问题会导致该程序无法编译或正常工作。
import java.util.Scanner;
import java.util.Random;
public class Nim {
private int n;
private int compMode;
private int numberLeft;
private int numberTaken;
private boolean whoseTurn;
private String inputName;
private String name;
private String play;
private boolean yes;
Scanner in = new Scanner(System.in);
Random num = new Random();
public void setState() {
numberLeft = 100;
numberTaken = numberLeft;
}
public String getPlayer() {
inputName = in.next("");
inputName = name;
return name;
}
public void getCompPlay() {
compMode = num.nextInt(2);
if (compMode == 0) System.out.println("The computer is in smart mode");
if (compMode == 1) System.out.println("The computer is in random mode");
}
public void playGame() {
if (whoseTurn == true) {
System.out.println(name + "It is your turn...");
System.out.printf("Please enter the number you wish to take from the pile (Must be less than " + (numberLeft / 2) + "): ");
numberTaken = in.nextInt();
numberLeft -= numberTaken;
System.out.println("The number left is " + numberLeft);
whoseTurn = false;
}
if (whoseTurn == false) {
System.out.println("It is the computer's turn...");
if (compMode == 0) {
numberLeft = smartComputer(numberLeft);
System.out.println("The number left is " + numberLeft);
}
if (compMode == 1) {
numberLeft -= num.nextInt(numberLeft / 2);
System.out.println("The number left is " + numberLeft);
}
whoseTurn = true;
return;
}
if (yes == true) {
}
if (numberLeft <= 1) {
if (whoseTurn = false) {
System.out.println("You Win!");
} else {
System.out.println("You're horrible...you lost to a computer.");
}
}
if (numberLeft <= 1) {
if (whoseTurn = false) {
System.out.println("You Win!");
} else {
System.out.println("you lost to a computer.");
}
}
}
public static int smartComputer(int num) {
int power = 2;
while (power < num) {
power *= 2;
}
power /= 2;
num = power - 1;
return num;
}
public boolean playAnother() {
System.out.println("/nPlay Again? (y/n)");
play = in.next("");
if (play.equalsIgnoreCase("y")) return true;
else return false;
}
public void displayTotals() {}
}
这是我的测试仪
public class NimTester {
public static void header() {
System.out.println("Eric Magnusson");
System.out.println("AP Comp Sci");
System.out.println("Game of Nim (P6.16)");
}
public static void main() {
Nim nim = new Nim(getPlayer(), getCompPlay());
do {
nim.setState();
nim.playGame();
nim.printWinner();
} while (playAnother());
nim.displayTotals();
}
}