我试图使用基于字符串的游戏板在BlueJ中编写hangman代码。我把游戏板作为一个不同类的字符串,我试图在我的主类中调用它,以便在输入所需的猜测词之后打印。每次运行代码时,都会使用随机数字和字母而不是实际的刽子手游戏板来打印Gameboard @。在上面的代码中,我将从我的Hangman类中取出void main,然后从我的Gameboard类中输入游戏板的代码。
Hangman Class:
`public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Player 1, enter a word! ");
word = in.nextLine();
wordTwo = word;
System.out.println("Your word is " + wordTwo);
System.out.println("Press (p) when you're ready to continue!");
start = in.nextLine();
wordChars = wordTwo.toCharArray();
if (start.equals("p"))
{
CLS();
}
else
{
System.out.println("Wait what? Restart the program and try typing
the key that ACTUALLY STARTS THE GAME!");
}
Gameboard board = new Gameboard(); //Line of code that's supposed to
call the game board.
System.out.println(board); //Line of code to print game board.
while ( trap == 1)
{
System.out.println("Player 2, will you guess a word(w) or a
character(c)?");
System.out.println("Type 'e' to exit");
wordOrChar = in.nextLine();
if (wordOrChar.equals("w"))
{
guessWord(guessWord);
}
else if(wordOrChar.equals("c"))
{
guessChar(guessChar);
}
exit = in.nextLine();
if (exit.equals("e"))
{
trap = 2;
}
}
}`
游戏板类:
public String board(String board)
{
board = (" -------------" + "\n" + "| |" + "\n" + " |" + "\n" + " |" + "\n" + " |" + "\n" + " |" + "\n" + " |" + "\n" + " |" + "\n" + " |" + "\n" + "---------------");
return board;
}
答案 0 :(得分:0)
在你的gameboard类上,它期望传递给它的参数(String board),但是当它被调用时,没有传递参数。删除所需的参数,一切都应该没问题。如果做不到这一点,请将您的类变量重命名为gameBoard并将其返回,而不是将其返回。 :)