Site icon

Create Text Based Adventure Game in Java

What is Text Based Adventure Game?

Adventure Game

How to create Text Based Adventure Game?

Develop: Play Text Based Adventure Game in Java

import java.util.Scanner;

public class EnhancedAdventureGame {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Welcome to the Adventure Game!");
        System.out.println("You're in a futuristic city...");
        System.out.println("To your left, a high-tech lab; right, an ancient library; ahead, a cyberpunk marketplace.");
        System.out.println("Where to? (left/right/straight)");

        String choice = scanner.nextLine();

        switch (choice.toLowerCase()) {
            case "left":
                exploreHighTechLab();
                break;
            case "right":
                exploreAncientLibrary();
                break;
            case "straight":
                visitCyberpunkMarket();
                break;
            default:
                System.out.println("Invalid choice. Try again.");
        }
    }

    public static void exploreHighTechLab() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("You enter the high-tech lab...");
        System.out.println("Find gadgets, cutting-edge tech.");
        System.out.println("Experiment with a new gadget? (yes/no)");

        String choice = scanner.nextLine();

        if (choice.equalsIgnoreCase("yes")) {
            experimentWithGadget();
        } else {
            System.out.println("You decide not to experiment. Game Over!");
        }
    }

    public static void experimentWithGadget() {
        System.out.println("You experiment with a gadget...");
        System.out.println("Discover hidden features, gain special abilities!");
        System.out.println("Congratulations, you unlocked powers and won!");
    }

    public static void exploreAncientLibrary() {
        System.out.println("Step into the ancient library...");
        System.out.println("Find ancient scrolls, mysterious texts.");
        System.out.println("Decipher secret code, unveil forgotten prophecy!");
        System.out.println("Congratulations, you decoded the prophecy and won!");
    }

    public static void visitCyberpunkMarket() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Explore the cyberpunk marketplace...");
        System.out.println("Spot an AI-powered phone booth.");
        System.out.println("AI challenges you to a virtual sports game. Accept? (yes/no)");
        
        String answer = scanner.nextLine();
        
        if (answer.equalsIgnoreCase("yes")) {
            playVirtualSportsGame();
        } else {
            System.out.println("You decline the challenge. Game Over!");
        }
    }

    public static void playVirtualSportsGame() {
        System.out.println("Accept the AI's challenge...");
        System.out.println("In a thrilling virtual sports match, emerge victorious!");
        System.out.println("Congratulations, you won the game and emerged triumphant!");
    }
}

Output: Created Text Based Adventure Game in Java

Welcome to the Adventure Game!
You're in a futuristic city...
To your left, a high-tech lab; right, an ancient library; ahead, a cyberpunk marketplace.
Where to? (left/right/straight)
left

You enter the high-tech lab...
Find gadgets, cutting-edge tech.
Experiment with a new gadget? (yes/no)
yes

You experiment with a gadget...
Discover hidden features, gain special abilities!
Congratulations, you unlocked powers and won!
Exit mobile version