CS50 Harvard - Final Project 2023
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.
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
- 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
- Java Development Kit (JDK) - Version 8 or higher
-
Navigate to the project directory:
cd Text-based-adventure -
Compile the Java file:
javac Main.java
-
Run the game:
java Main
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)
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
| 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% |
text-based-adventure/
└── Text-based-adventure/
└── Main.java # Main game logic and loop
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
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
Created by Legion345 as a CS50 Harvard final project in 2023.
This project is part of my journey learning computer science and software development.