Skip to content

Legion345/Text-based-adventure

Repository files navigation

Text-Based Adventure Game

CS50 Harvard - Final Project 2023

Description

This is a dungeon crawler text-based adventure game written in Java as my final project for CS50 (Harvard's Introduction to Computer Science) in 2023. The game features turn-based combat, health management, and random enemy encounters as you explore a dangerous dungeon.

Project Goals

This project was created to:

  • Learn Java fundamentals - Master core Java concepts including object-oriented programming principles, control flow, and user input handling
  • Understand game development concepts - Explore game loops, state management, random number generation, and player/enemy interaction systems
  • Build a complete application - Design and implement a fully functional game from start to finish

Features

  • Random Enemy Encounters - Face off against various enemies (Skeleton, Zombie, Warrior, Assassin)
  • Combat System - Engage in battles with randomized damage output
  • Health Management - Monitor your health and use health potions strategically
  • Item Drops - Defeat enemies for a chance to obtain health potions
  • Player Choices - Attack, drink potions, or flee from combat
  • Continuous Gameplay - Choose to continue fighting or exit the dungeon after each victory

Requirements

  • Java Development Kit (JDK) - Version 8 or higher

How to Run

  1. Navigate to the project directory:

    cd Text-based-adventure
  2. Compile the Java file:

    javac Main.java
  3. Run the game:

    java Main

How to Play

When you start the game, you'll be welcomed to the dungeon. Random enemies will appear, and you'll be presented with options:

  • 1. Attack - Deal random damage to the enemy (0-50 HP) and take damage in return (0-25 HP)
  • 2. Drink - Consume a health potion to restore 30 HP (if available)
  • 3. Run! - Flee from the current enemy and encounter a new one

After defeating an enemy:

  • You have a 20% chance to receive a health potion drop
  • Choose to continue fighting or exit the dungeon

The game ends when:

  • Your health drops below 1 (defeat)
  • You choose to exit the dungeon (victory)

Example Gameplay

Welcome to the Dungeon!
---------------------------------------

        # Skeleton appeared! #

        Your HP: 100
        Skeleton's HP: 100

        What would you like to do?
        1. Attack
        2. Drink
        3. Run!
1
        > You strike the Skeleton for 42 damage.
        > You have taken 18 damage in retaliation!

        Your HP: 82
        Skeleton's HP: 58

        What would you like to do?
        1. Attack
        2. Drink
        3. Run!
1
        > You strike the Skeleton for 35 damage.
        > You have taken 22 damage in retaliation!

        Your HP: 60
        Skeleton's HP: 23

        What would you like to do?
        1. Attack
        2. Drink
        3. Run!
1
        > You strike the Skeleton for 28 damage.
        > You have taken 15 damage in retaliation!

---------------------------------------
 # Skeleton was defeated! #
 # You have 45 HP left. #
 # The Skeleton dropped a health potion! #
 # You now have 4 health potion(s). #
---------------------------------------
What would you like to do now?
1. Continue fighting
2. Exit dungeon

Game Mechanics

Component Value
Player Starting Health 100 HP
Player Attack Damage 0-50 HP (random)
Starting Health Potions 3
Health Potion Heal Amount 30 HP
Enemy Max Health 100 HP
Enemy Attack Damage 0-25 HP (random)
Health Potion Drop Chance 20%

Project Structure

text-based-adventure/
└── Text-based-adventure/
    └── Main.java          # Main game logic and loop

Planned Features

Future enhancements outlined in the code:

  • Health bar visualization in command line
  • Backpack size system
  • Full inventory management
  • Additional items for pickup
  • True turn-based combat (enemy doesn't attack when drinking potions)
  • Multiple locations/rooms
  • Location-specific enemies
  • Weapons system with varied damage types

Development Notes

This project demonstrates understanding of:

  • Java syntax and structure - Classes, methods, and the main game loop
  • Control flow - While loops, if-else statements, and labeled breaks
  • User input handling - Scanner class for command-line interaction
  • Random number generation - Creating unpredictable game experiences
  • Arrays - Storing and randomly selecting enemy types
  • Game state management - Tracking health, potions, and game status
  • String manipulation - Formatting output for user feedback

Author

Created by Legion345 as a CS50 Harvard final project in 2023.


This project is part of my journey learning computer science and software development.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages