首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >BlueJ中的绞刑者

BlueJ中的绞刑者
EN

Stack Overflow用户
提问于 2018-05-10 04:59:41
回答 1查看 104关注 0票数 0

我正在尝试使用基于字符串的游戏板在BlueJ中编写hangman代码。我将游戏板作为字符串放在不同的类中,并尝试在我的主类中调用它,以便在输入所需的猜测单词后打印出来。每次我运行代码时,它都会打印带有随机数字和字母的游戏板@,而不是实际的绞刑者游戏板。在上面的代码中,我将void main放入Hangman类中,然后将游戏板的代码放入游戏板类中。

Hangman类:

代码语言:javascript
复制
`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;
        }
    }
}`

游戏板类:

代码语言:javascript
复制
public String board(String board)
{
    board = (" -------------" + "\n" + "|             |" + "\n" + "              |" + "\n" + "              |" + "\n" + "              |" + "\n" + "              |" + "\n" + "              |" + "\n" + "              |" + "\n" + "              |" + "\n" + "---------------"); 
    return board;
}
EN

回答 1

Stack Overflow用户

发布于 2018-06-10 02:13:42

在你的游戏板类中,它需要一个传递给它的参数(字符串板),但是当它被调用时,却没有参数被传递。删除所需的参数,一切都将正常。如果失败,请将类变量重命名为gameBoard并返回它,而不是board。:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50261964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档