Create Text Based Adventure Game in Java

What is Text Based Adventure Game?

  • Explore a city in a Java-based Text Adventure Game.
  • Navigate a high-tech lab, an ancient library, and a cyberpunk marketplace.
  • Choose paths:
    • experiment with gadgets
    • Unravel ancient secrets
    • Play virtual sports.
  • Each choice leads to unique adventures and hidden powers to discover.
  • Engage in an interactive narrative blending technology with ancient mysteries.
  • Shape your destiny and experience on thrilling Journey with this game.
Create or make Text Based Adventure Game in Java
Adventure Game

How to create Text Based Adventure Game?

  • Implement operations need to explore the city depending upon user inputs
    • exploreHighTechLab
    • exploreAncientLibrary
    • visitCyberpunkMarket
  • Use Java Scanner class to take inputs from User
    • Invoke respective location functions based on user selections.
  • Use switch-case statements to handle various user inputs choices.
  • Develop print statements to narrate outcomes and game progress.

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!
Scroll to Top