我需要一种使该代码正常工作而不会出错的方法

时间:2019-07-12 02:08:39

标签: java macos terminal compilation java-11

我正在尝试使用Java在终端上制作游戏,但是我不断遇到有关静态变量和内容的错误,无论我尝试给出什么新错误,有人可以给我一种方法来修复代码。

我不记得我做了什么(对不起)。

import java.util.Scanner;
import java.util.concurrent.TimeUnit;

class GameTest {

    Scanner user_input = new Scanner(System.in);

    //Variables
    String name;
    String gameChoice;
    int quizScore = 10;
    int quizLevel = 1;
    String quizX;

    public static void homeFunc() {

        System.out.println("Hello " + name + "!");
        System.out.println("Would you like to play:");
        System.out.println("(1) Quiz - Level " + quizLevel);
        gameChoice = user_input.next();
        if (gameChoice == "1") startQuiz();

    }

    public static void homeTeleFunc() {

        System.out.println("You will be teleported to base in...");
        System.out.println("3...");
        System.out.println("2...");
        System.out.println("1...");
        homeFunc();

    }

    public static String askQuestion(String question) {

        System.out.println(question);
        return user_input.next();

    }

    public static void checkAnswer(String answer, String correctAnswer) {

        if (answer == correctAnswer) {

            System.out.println("Correct!");

        } else {

            System.out.println("Incorrect");
            quizScore--;

        }

    }

    public static void quiz1() {

        quizScore = 10;

        // Question 1
        quizX = askQuestion("What's 1 + 1? (Decimal Format)");
        checkAnswer(quizX, "2");

        // Question 2
        quizX = askQuestion("Who was the first president of the U.S.A? (Case Sensitive)");
        checkAnswer(quizX, "George Washington");

        // Question 3
        quizX = askQuestion("What's 3 + 2? (Decimal Format)");
        checkAnswer(quizX, "5");

        // Question 4
        quizX = askQuestion("How many sides does a square have? (Decimal Format)");
        checkAnswer(quizX, "4");

        // Question 5
        quizX = askQuestion("What's 5 + 3? (Decimal Format)");
        checkAnswer(quizX, "8");

        // Question 6
        quizX = askQuestion("How many sides does a triangle have? (Decimal Format)");
        checkAnswer(quizX, "3");

        // Question 7
        quizX = askQuestion("What's 7 + 1? (Decimal Format)");
        checkAnswer(quizX, "8");

        // Question 8
        quizX = askQuestion("What color is the sky? (Case Sensitive)");
        checkAnswer(quizX, "Blue");

        // Question 9
        quizX = askQuestion("What's 2 + 4? (Decimal Format)");
        checkAnswer(quizX, "6");

        // Question 10
        quizX = askQuestion("How many hoops are used in a game of basketball? (Decimal Format)");
        checkAnswer(quizX, "2");


    }

    public static void startQuiz() {

        switch (quizLevel) {

            case 1:
                quiz1();


        }

    }

    public static void main(String args[]) {

        System.out.println("Welcome to Yerp World!");
        System.out.println("When you have a yes or no choice type \"Yes\" or \"No\" (Case Sensitive).");
        System.out.println("If you have a multiple choice choice to make type a number starting from 1 for the first choice, and you  get the point.");
        System.out.println("The object of the game is to collect as many coins as possible, to buy new games.");
        System.out.println("Would you like to begin?");
        String c1 = user_input.next();
        if (c1 == "Yes") {

            System.out.println("What is your name?");
            final String name = user_input.next();




        }

    }



}

我希望它从头开始,并根据用户的操作遵循路径。根据我的尝试,我遇到了各种错误。

0 个答案:

没有答案