We were trying our best to be a little creative and have an interactive game that's simple enough to make, because all of us are not very experienced when it comes to coding, especially java, but we wanted to learn so we decided to try it out.

The gist is the in the game (which we were planning to have in first person point of view), the player is trapped in a maze and needs to get out to live. But the player constantly runs into two doors at a time and needs to choose one door---one riddle---to move on. Each door is accompanied by a riddle and the player is allowed to choose which riddle to answer. If the player answers correctly, they move on in the maze. If not, they meet a certain fate.

A few challenges we ran into and we're still stuck in is getting the user to simply press 'enter' to move on in the game, but we figured that part out. The current issue is incorporating every option effectively into the program, but we were unable to fix the errors.

We learned how to use 'try and catch' methods, using 'enter' to move on in the game (which we found out was simply "input.nextLine();", and using text files so all the riddles and answers aren't in a single file.

What's next for our project is fixing the errors and incorporating the images we drew into our game. We want to make the game visually appealing and interesting as well, so that's another goal.

The game/code itself is not finished, but we are planning to finish it soon.

(Our program:)

import java.io.; import java.util.;

public class Door { public static List lines = new ArrayList(); public static int riddleCounter = 0; public static int i = 0; public static int responseCounter = 0; public static FileReader fileReader = null;

public static void main(String[] args) {
    promptEnterKey();
}

public static void promptEnterKey() {
    try {
        FileReader fileReader = new FileReader("files/Riddles.txt");
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        String line = null;
        while ((line = bufferedReader.readLine()) != null) {
            lines.add(line);
        }
        bufferedReader.close();
    } catch (IOException e) {
    }

    System.out.println("Hi there! Welcome to Doors. Press /ENTER/ to continue.");

    Scanner input = new Scanner(System.in);
    input.nextLine();
    System.out.println("Before we begin, enter your name, age, and gender please. \n\nName:  ");// \nAge:
                                                                                                // \nGender:

    String name = input.next();

    System.out.println("Age: ");
    int age = input.nextInt();
    System.out.println("Gender (Type out entire word please): ");
    String gender = input.next();

    System.out.println("Are you ready to play? (Yes/No)");
    String ans = input.next();

    if (ans.equalsIgnoreCase("yes")) {
        System.out.println("Excellant. Any questions on the objective? (Yes/No)");
    } else if (ans.equalsIgnoreCase("no")) {
        System.out.println("JUST TYPE 'YES'!");
    } else {
        System.out.println("Error. Please try again.");
    }

    String a = input.next();
    boolean b = true;

    if (a.equalsIgnoreCase("yes")) {
        System.out.println("Alright then. You are a " + age + " years old " + gender + " named " + name
                + " who is lost in a tunnel. \n(Don't ask how it happened, it just did).");
        input.nextLine();
        System.out.println("Your goal is to escape the tunnel with your life.");
        input.nextLine();
        System.out.println("However, at the end of each path, there will be two doors with two riddles.");
        input.nextLine();
        System.out.println(
                "Select one door and answer the riddle correctly or face a terrible end. You have no time limit, but don't cheat!");
        input.nextLine();
        System.out.println(
                "Let's begin. Remember, you will be presented with two riddles first before you can decide.");
        input.nextLine();

    } else if (a.equalsIgnoreCase("no")) {
        System.out.println(
                "Excellant. Let's begin. Remember, you will be presented with two riddles first before you can decide.\n");
        input.nextLine();
    }

    while (b == false) {

        System.out.println("Error. Please try again.");
    }

    try {
        System.out.println(lines.get(riddleCounter++));
        if (riddleCounter == lines.size())
            riddleCounter = 0;
        input.nextLine();
        System.out.println("Or...");
        input.nextLine();
        System.out.println(lines.get(riddleCounter++));
        if (riddleCounter == lines.size())
            riddleCounter = 0;
        System.out.println("You encounter two doors. One of the left and one on the right.");
        System.out.println("Type in '1' for left or '2' for right. Choose wisely.");
        i = input.nextInt();

        String answer;

        try {
            fileReader = new FileReader("files/Answers.txt");
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        BufferedReader bufferedReader = new BufferedReader(fileReader);
        String line = null;
        try {
            while ((line = bufferedReader.readLine()) != null) {
                lines.add(line);

                if (i == 1) {
                    System.out.println("Good choice. What is your answer?");
                    System.out.println("Here is the riddle: " + lines.get(0));
                    answer = input.next();
                    if (answer.equalsIgnoreCase(line)) {
                        System.out.println("Well done. Would you like to move on? (Yes/No)");
                        String blank = input.next();

                        if (blank.equalsIgnoreCase("yes")) {
                            System.out.println("Okay then. (Press /ENTER/ to continue).");
                            input.nextLine();
                            System.out.println("You continued down the long and narrow hall.");
                            input.nextLine();
                            System.out.println("Unfortunately, you ended up at two doors again.");
                            input.nextLine();
                            System.out.println("Which riddle will you choose this time?");
                            try {
                                System.out.println(lines.get(riddleCounter++));
                                if (riddleCounter == lines.size())
                                    riddleCounter = 2;
                                input.nextLine();
                                System.out.println("Or...");
                                input.nextLine();
                                System.out.println(lines.get(riddleCounter++));
                                if (riddleCounter == lines.size())
                                    riddleCounter = 2;
                                System.out
                                        .println("You encounter two doors. One of the left and one on the right.");
                                System.out.println("Type in '1' for left or '2' for right. Choose wisely.");
                                i = input.nextInt();

                                String bark;

                                try {
                                    fileReader = new FileReader("files/Answers.txt");
                                } catch (FileNotFoundException e1) {
                                    // TODO Auto-generated catch block
                                    e1.printStackTrace();
                                }
                                try {
                                    while ((line = bufferedReader.readLine()) != null) {
                                        lines.add(line);

                                        if (i == 1) {
                                            System.out.println("Good choice. What is your answer?");
                                            System.out.println("Here is the riddle: " + lines.get(0));
                                            answer = input.next();
                                            if (answer.equalsIgnoreCase(line)) {
                                                System.out.println("Well done. Would you like to move on? (Yes/No)");
                                                String bar = input.next();}
                                                else{
                                                    System.out.println("Error. Please try again.");}
                                        }
                             catch (InputMismatchException e) {
                                e.printStackTrace();}
                             catch(IOException e){
                                 e.printStackTrace();}
                                    }



                        else if (blank.equalsIgnoreCase("no")) {
                            System.out.println("Well, you gotta get out of here somehow. Let's keep going. (Press /ENTER/ to continue).");

                        }
                    } else if (responseCounter != lines.size()) {
                        System.out.println("How unfortunate. Good-bye.");
                    }
                }

            }
        } catch (IOException e) {

            e.printStackTrace();
        }

    } catch (InputMismatchException e) {
        e.printStackTrace();
    }

    // why? if(responseCounter!=lines.size()){
    // System.out.println("How unfortunate. Good-bye.");}

    if (i == 2) {
        System.out.println("Good choice. What is your answer?");
        System.out.println("Here is the riddle: " + lines.get(2));
        input.next();
        if (responseCounter == lines.size())
            responseCounter = 1;
        {
            System.out.println("Well done. Would you like to move on?");
        }
        if (responseCounter != lines.size()) {
            System.out.println("How unfortunate. Hope this riddle didn't BURN you out.");
        }
    }

    else {
        System.out.println("Error. Please type in your answer.");
    }
}

// System.out.println(lines.get(riddleCounter+=2));
// if(riddleCounter==lines.size())riddleCounter=0;
// System.out.println(lines.get(riddleCounter++));
// if(riddleCounter==lines.size())riddleCounter=0;
/*
 * catch (IOException e) { e.printStackTrace(); String
 * characterObjectToString = new Character('c').toString();}
 */

// filereader
        }

Built With

Share this project:

Updates