Skip to content

u3640877/COMP2113_Group_Project

Repository files navigation

,---.    ,---.   ____     __ .-------.     .-''-. ,---------.         .--.      .--.    ,-----.    .-------.      .---.      ______
|    \  /    |   \   \   /  /\  _(`)_ \  .'_ _   \\          \        |  |_     |  |  .'  .-,  '.  |  _ _   \     | ,_|     |    _ `''.
|  ,  \/  ,  |    \  _. /  ' | (_ o._)| / ( ` )   '`--.  ,---'        | _( )_   |  | / ,-.|  \ _ \ | ( ' )  |   ,-./  )     | _ | ) _  \
|  |\_   /|  |     _( )_ .'  |  (_,_) /. (_ o _)  |   |   \           |(_ o _)  |  |;  \  '_ /  | :|(_ o _) /   \  '_ '`)   |( ''_'  ) |
|  _( )_/ |  | ___(_ o _)'   |   '-.-' |  (_,_)___|   :_ _:           | (_,_) \ |  ||  _`,/ \ _/  || (_,_).' __  > (_)  )   | . (_) `. |
| (_ o _) |  ||   |(_,_)'    |   |     '  \   .---.   (_I_)           |  |/    \|  |: (  '\_/ \   ;|  |\ \  |  |(  .  .-'   |(_    ._) '
|  (_,_)  |  ||   `-'  /     |   |      \  `-'    /  (_(=)_)          |  '  /\  `  | \ `"/  \  ) / |  | \ `'   / `-'`-'|___ |  (_.\.' /
|  |      |  | \      /      /   )       \       /    (_I_)           |    /  \    |  '. \_/``".'  |  |  \    /   |        \|       .'
'--'      '--'  `-..-'       `---'        `'-..-'     '---'           `---'    `---`    '-----'    ''-'   `'-'    `--------`'-----'`

MyPet World

Terminal-based virtual pet with minigames, shop, inventory, and coin-based victory. Built with ncurses.

This project received a perfect score in the Programming Technologies course at the University of Hong Kong.

Click the thumbnail below to watch the gameplay demo video on YouTube!

Watch the video

Table of Contents

Team

  • NG, Po Chun
  • YANG, Wonjun
  • REGANIT, Julianna Martina Mercado
  • KIM, Yekaterina

Overview & Goal

  • Win the game by earning the targeted coins through playing with your pet in MyPet world!
  • Pet start with maximum status (Health, Energy, Hunger) but decay over time (including offline). If Health drops below 0, you lose the game.
  • Earn coins through in-game minigames.
  • Maintain the pet status while earning them coins.
  • Difficulty affects status decay speed, rewards, sleep energy, and the coin goal. The HUD shows both current coins and the goal.

How to Play (step-by-step)

  1. Launch the game and pick New Game.
  2. Read the on-screen instructions, choose your difficulty (Dog or Cat).
  3. Name your pet.
  4. Use number keys to navigate between actions and minigames.
  5. Earned coins can be used to buy items from in-game store to boost pet status.
  6. Player comes with inventory to store foods, toys, and medicine bought from in-game store.
  7. Reach the coin goal in different modes (Dog: 100 coins | Cat: 150 coins) to win.

Quick Start

to start the game:

make
./myPet
  • Requires ncurses. No extra installs needed in HKU server.

In-game Controls

  • Actions: 1 Feed, 2 Shower, 3 Cuddle, 4 Sleep
  • Minigames: 5 Number Guess, 6 Trick Training, 7 Rock-Paper-Scissors
  • Shop/Inventory: 8 Shop, 9 Inventory to view items
  • Quit: q (from game screen) returns to main menu; q inside minigames exits that minigame.

Minigames

Energy Cost: -20 Energy per minigame

Difficulty-Based Rewards:

  • Dog (Easy): +20 happiness, +50 coins per win
  • Cat (Hard): +10 happiness, +30 coins per win

Mini Game 1: Number Guess (Press 5)

  • Guess a number between 1-100 in up to 7 tries
  • Type your guess and press ENTER after each attempt
  • Win rewards: Full pet bonus (coins + happiness)
  • Loss rewards: Half of pet bonus
  • Quit anytime with q + ENTER

Mini Game 2: Trick Training (Press 6)

  • Watch and memorize a growing sequence of tricks
  • Input trick numbers (1-5) in correct order
  • Coin rewards: +5 per correct sequence, plus half pet bonus if streak > 0
  • Happiness rewards: Full bonus if any streak, otherwise half (minimum +5)
  • Quit anytime with q + ENTER

Mini Game 3: Rock-Paper-Scissors (Press 7)

  • Press 1 (Rock), 2 (Paper), or 3 (Scissors) to choose your move
  • Your pet randomly chooses its move
  • Win rewards: Full pet bonus (coins + happiness), Energy -20
  • Tie/Loss rewards: Reduced rewards, Energy -10
  • Quit anytime with q

Shop & Inventory

Shop (Press 8)

  • Purchase items using coins earned from minigames
  • Items include food, toys, and medicine with various stat bonuses
  • Each item has a price and provides bonuses to Health, Hunger, Happiness, and/or Energy
  • Shop catalog is loaded from shop_items.txt (editable)
  • Purchases are automatically saved to your inventory

Inventory (Press 9)

  • View all items you've purchased from the shop
  • Shows item names and quantities
  • Use Feed action (Press 1) to consume items and apply their stat bonuses
  • Stats are capped at maximum values (100/100)
  • Consumed items are removed from inventory when quantity reaches 0
  • Inventory persists across game sessions via inventory.txt

Saving & Files

  • Autosave after actions/minigames and when random coin events trigger.
  • Offline decay applied on load based on last save time (capped so old saves still load safely).
  • To reset progress, delete data.txt and inventory.txt (defaults come from data_default.txt).
  • Files:
    • data.txt — stats, coins, cooldowns, last save, pet type, pet name.
    • inventory.txt — item names and quantities.
    • shop_items.txt — shop catalog (editable).

Coding Requirements Mapping

1. Generation of Random Events

  • Location: game.cpp - randomPetEvent() function
  • Random event system with 0.5% chance (1 in 200) per game loop cycle
  • Messages include flavor text and special coin events (+5 coins)
  • Random selection of death/victory messages using rand()
  • Example: "Your pet found a shiny coin! (+5 coins)"

2. Data Structures for Storing Data

  • Location: game_screen.h
  • Structs used:
    • PetStatus - stores health, hunger, happiness, energy, max values, timestamps
    • PlayerMoney - stores coin count
    • ShopItem - stores item name, price, stat bonuses
    • InventoryItem - stores item name and quantity
    • GameData - aggregates all game state data
  • Vectors used:
    • std::vector<ShopItem> for shop catalog
    • std::vector<InventoryItem> for player inventory
    • std::vector<std::string> for pet ASCII art and menu items

3. Dynamic Memory Management

  • Location: minigame1/minigame1.cpp
  • Dynamically allocates integer array for guess history tracking
  • Code snippet:
    int *guess_history = new int[MAX_ATTEMPTS];
    // ... game logic ...
    delete[] guess_history;  // Proper cleanup
  • Demonstrates proper allocation with new[] and deallocation with delete[]

4. File Input/Output

  • Location: file_io.cpp
  • Save functions:
    • saveGameData() - writes to data.txt
    • saveInventory() - writes to inventory.txt
  • Load functions:
    • loadGameData() - reads from data.txt
    • loadInventory() - reads from inventory.txt
    • loadShopItems() - reads from shop_items.txt
  • Files managed:
    • data.txt - game save (stats, coins, cooldowns, pet type, pet name)
    • data_default.txt - default template
    • inventory.txt - player inventory
    • shop_items.txt - shop configuration

5. Program Codes in Multiple Files

  • Header files (.h): config.h, display.h, file_io.h, format.h, game_screen.h, instructions.h, mode.h, minigame1.h, minigame2.h, minigame3.h
  • Implementation files (.cpp): game.cpp (main), display.cpp, file_io.cpp, format.cpp, instructions.cpp, mode.cpp, minigame1/minigame1.cpp, minigame2/minigame2.cpp, minigame3/minigame3.cpp
  • Total: 10+ header files, 10+ source files with clear separation of concerns

6. Multiple Difficulty Levels

  • Location: mode.cpp and config.h
  • Two difficulty levels:
    1. DOG (Easy):
      • Hunger decay: -5 every 45 seconds
      • Health decay: -10 every 60 seconds
      • Minigame coin reward: 50
      • Minigame happiness bonus: 20
      • Coin goal to win: 100
    2. CAT (Hard):
      • Hunger decay: -10 every 45 seconds (2x faster)
      • Health decay: -20 every 60 seconds (2x faster)
      • Minigame coin reward: 30
      • Minigame happiness bonus: 10
      • Coin goal to win: 150
  • Player selects difficulty when starting a new game via mode() function
  • Difficulty affects decay rates, rewards, and victory conditions throughout gameplay

Troubleshooting

  • If UI appears garbled, ensure your terminal supports ncurses and is large enough (~80x24+).
  • If loads feel off, remove data.txt and inventory.txt to start fresh with defaults.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors