CT30A1400
Rust Programming
FINAL PROJECT
Hung Nguyen
001736166
Source code is available at
https://github.com/peogway/rust_programming.git
Demo video:
https://youtu.be/1U6OYl0gjcw
AI Usage Declaration
- AI tools were used in the following ways:
- ChatGPT & Gemini assisted with:
o Syntax clarification and best practices in Rust
o Explaining library functions and usage
o Suggesting improvements in comments and styling
o Bug fixing and code refactoring
o Drafting and refining documentation (including this one)
-
🎮 Project Overview
This is a terminal-based single-player RPG game written in Rust. Players
select a difficulty level and a character class, then engage in battles with
random bosses while managing their stats, coins, and inventory. The player
can also shop for items between battles. The game includes leveling
mechanics, gear upgrades, and randomized encounters for replayability.
📁 Folder Structure
• main.rs or Game: main loop and game flow
• player/: Player struct and behavior
• gear/: Items and random loot
• monsters/: Bosses and encounters
🔧 How the Game Works
The game progresses in sequential steps:
- intro()
o Prints an ASCII-art game title to create an engaging start.
- greet()
o Asks the user for their name and greets them.
- mode()
o Prompts player to select a game difficulty:
▪ Easy : more health, easier enemies
▪ Normal : balanced
▪ Hard : less health, tougher enemies
- player_init()
o Asks the player to choose a character class:
▪ Warrior: high damage, low defense
▪ Mage: balanced
▪ Rogue: high defense, low damage
o Applies difficulty multiplier to starting HP.
- shopping_stage()
o The player can buy upgrades using coins:
▪ Potions for HP, damage, or defense
▪ Random weapon (changes player item)
▪ Extra life (expensive)
o If the player can’t afford an item, a message is shown.
- Combat (likely in Game module)
o The player faces random bosses.
o Damage is calculated based on player/boss stats.
o Player actions like attack or defense are based on typing speed,
using threads to enforce time limits. If the player types the
correct input fast enough, the action succeeds. Defeating
enemies rewards coins and EXP.
- Leveling Up
o Every 100 EXP, player levels up:
▪ +10 HP, +2 damage, +1 defense
▪ EXP is reset on level up.
- Game Loop
o After a boss fight, player returns to shopping or proceeds to the
next stage.
o Continues until death or game-ending condition.
🧍 Player
• Defined in player/Player.rs:
• Fields:
o name, hp, damage, defense
o lvl, exp, coins, item, lives
• Key Methods:
o get_attack(): calculates incoming damage
o add_exp(): handles XP and level ups
o heal(), add_damage(), add_defense(), add_coins() etc.
o set_item(): unequips old item, equips new one, updates stats
🧰 Items
• Defined in gear/:
• Item:
o Represents a single gear (name, damage, defense)
• Items:
o Holds a list of predefined items
o get_random_item() returns a new random item
• Used in shopping_stage() when the player buys a weapon
🧟 Bosses
• Defined in monsters/:
• Boss:
o Has name, emoji, hp, damage, defense
o Methods to heal, take damage, or get stats
• Bosses:
o Holds multiple bosses
o get_random_boss() returns one at random for fights
•
Example Game Flow
Start Game → Show intro → Ask name → Select mode → Pick character → Show
player stats → Fight Monster of Find Treasure -> Shop → Random boss fight →
Win or lose → Gain coins & XP → Shop again → Repeat
📦 Dependencies
• rand crate is used for:
o Randomly selecting items from inventory
o Randomly selecting bosses from the pool
o Randomly receive different items in treasure, or number of
treasures when defeating a boss