Skip to the content.

Java Jungle Adventure

Java Jungle Adventure

import java.util.Scanner;
public class AdventureGame {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Welcome to the Adventure Game!");
        System.out.println("You are an explorer lost in the jungle. Your goal is to find your way out safely.");
        System.out.println("\nYou're standing at a crossroads. You can go left or right. What do you do? (type 'left' or 'right')");
        String choice1 = input.nextLine();
        if (choice1.equalsIgnoreCase("left")) {
            System.out.println("You walk down a narrow path and encounter a river. There's a small boat, but it looks old. Do you want to use the boat or swim across? (type 'boat' or 'swim')");
            String choice2 = input.nextLine();
            if (choice2.equalsIgnoreCase("boat")) {
                System.out.println("You manage to cross the river safely using the boat. You're getting closer to the jungle's edge.");
                System.out.println("You see a strange, glowing fruit on the ground. Do you eat it or ignore it? (type 'eat' or 'ignore')");
                String choice3 = input.nextLine();
                if (choice3.equalsIgnoreCase("eat")) {
                    System.out.println("The fruit gives you magical powers, and you fly out of the jungle! You win!");
                } else {
                    System.out.println("You ignore the fruit, but soon after, you get lost deeper in the jungle. You lose.");
                }
            } else {
                System.out.println("You try to swim across, but the current is too strong. You get swept away by the river. Game over.");
            }
        } else if (choice1.equalsIgnoreCase("right")) {
            System.out.println("You take the right path and encounter a wild animal. Do you fight or run? (type 'fight' or 'run')");
            String choice2 = input.nextLine();
            if (choice2.equalsIgnoreCase("fight")) {
                System.out.println("You bravely fight off the animal and continue your journey. You see a cave up ahead. Do you enter the cave or walk past it? (type 'enter' or 'walk')");
                String choice3 = input.nextLine();
                if (choice3.equalsIgnoreCase("enter")) {
                    System.out.println("Inside the cave, you find a hidden treasure! Congratulations, you win!");
                } else {
                    System.out.println("You walk past the cave, but get lost in the dense forest. You lose.");
                }
            } else {
                System.out.println("You run away, but trip and fall into a pit. Game over.");
            }
        } else {
            System.out.println("Invalid choice! Please restart the game and make a valid decision.");
        }
        
        input.close();
    }
}
AdventureGame.main(null);
Welcome to the Adventure Game!
You are an explorer lost in the jungle. Your goal is to find your way out safely.

You're standing at a crossroads. You can go left or right. What do you do? (type 'left' or 'right')
You walk down a narrow path and encounter a river. There's a small boat, but it looks old. Do you want to use the boat or swim across? (type 'boat' or 'swim')
You manage to cross the river safely using the boat. You're getting closer to the jungle's edge.
You see a strange, glowing fruit on the ground. Do you eat it or ignore it? (type 'eat' or 'ignore')
The fruit gives you magical powers, and you fly out of the jungle! You win!