Stock Market Simulator main e8c3612
A game that provides a realistic stock buying experience with unpredictable trends to test investment strategies.
Loading...
Searching...
No Matches
Stock Market Simulator

C++ Linux

CI CodeFactor Coverage Status

Menu

  1. Team Members
  2. Game Description
  3. How to Play
  4. Code Requirements
    1. Generation of random game sets or events
    2. Data structures for storing game status (e.g., arrays, STL containers)
    3. Dynamic memory management (e.g., dynamic arrays, linked lists, STL containers)
    4. File input/output (e.g., for loading/saving game status)
    5. Program codes in multiple files (recall separate compilation)
    6. Proper indentation and naming styles
    7. In-code documentation
  5. Credits
    1. Logo
    2. Non-standard Libraries Used

Team members

Name UID Profile
Cheng Ho Ming 3036216734 Cheng Ho Ming
Chung Shing Hei 3036216760 Chung Shing Hei
Chow Yui Hei 3036222446 Chow Yui Hei
Chu Chun Yin 3036270778 Chu Chun Yin
Wong Sonny 3036222458 Wong Sonny

Game Description

"Stock Market Simulator" is a game that attempts to introduce a realistic stock buying experience to players. The game utilizes the random number generation capability of the operating system to mimic real-life stock unpredictable trends while giving players breathing room to better think about their investing strategies.

How to Play

Demo gameplay video

Compilation

Prerequisite:

  • This repository.
  • A working g++ compiler that supports C++17
  • make
  • A terminal that supports ANSI escape codes

To compile:

make

To run the game:

./stocksim

Or if you prefer one step:

make all

To ensure an optimal gaming experience, please adopt the following recommendations before running the game:

Terminal Size

Maximize your terminal window to its fullest extent.

On Windows, you can achieve this by pressing the Alt+Enter key combination, which will toggle the terminal to fullscreen mode.

Font Size Adjustment

Reduce your terminal's font size initially.

Unsuitably large font sizes may cause the table displaying stock information and data to be cut off or misaligned within the terminal window.

Start with a smaller font size, such as 10, to ensure the stock table displays correctly, and then increase the size if needed.

Tutorial

After displaying the ASCII game logo, you will be prompted by this screen:

Please enter.
0 for new save,
1 for loading old save(s),
2 for deleting save,
3 to quit:

Type 0 and press Enter. Type your preferred name and press Enter again.

Now you should enter the game's main menu.

Some user inputs the game receives (case-insensitive):

  • B: Buy a stock.
  • S: Sell a stock.
  • T: Select a stock (or 0 for Happy Stock Index) to display a corresponding price history graph, which shows the historical performance of a stock and the fluctuations in stock price. Enter T again to hide the pop-up.
  • E: Display all ongoing events that affect the performance of stocks. Enter E again to hide the pop-up.
  • N: Proceed to the next round. The game will generate new stock prices and events.
  • X: Exit the game.

You may wonder why there is no save button. The answer is — you don't need it!

Each time when you enter N: Next Round, the game data is saved automatically in the saves/ folder. See more information on File I/O part.

Table column explanation:

  • #: The index of the stock. You will enter it when you are purchasing/selling a stock.
  • Category: The respective categories a stock corresponds to. Some events are applied to a specific category only!
  • Name: Self-explainatory.
  • $Price: The current price (per unit) of the stock.
  • Change: The change in the stock price compared to the last round.
  • Change: The percentage change of stock price.
  • #Has: Number of stocks that you can sell.
  • #Max: Number of stocks that you can buy. This takes account of trading_fees_percent.

Some additional columns are hidden, they served for debugging purposes only.

Code Requirements

Generation of random game sets or events

Generation of stock prices:

  • We used normal distribution to generate the percentage change in the stock price for each new round.

https://github.com/eric15342335/comp2113-engg1340-group-project/blob/1cd66bfd883a18577a4b8d5d246b4aff21e000f6/src/random_price.cpp#L114-L128

Generation of in-game events:

  • In our game, we also included 99 events that will each have a possibility to happen in your gameplay.

https://github.com/eric15342335/comp2113-engg1340-group-project/blob/1cd66bfd883a18577a4b8d5d246b4aff21e000f6/src/events.cpp#L48-L60

Data structures for storing game status (e.g., arrays, STL containers)

In stock.h, we declared class Stock which utilizes STL vector, list and map to store various game data.

https://github.com/eric15342335/comp2113-engg1340-group-project/blob/1cd66bfd883a18577a4b8d5d246b4aff21e000f6/include/stock.h#L266-L295

The class Stock itself represents an Stock object, which you can purchase, sell, generate a new price for it, etc.

https://github.com/eric15342335/comp2113-engg1340-group-project/blob/1cd66bfd883a18577a4b8d5d246b4aff21e000f6/include/stock.h#L36-L58

Other than class Stock, we have struct Stock_event that represents an in-game event.

https://github.com/eric15342335/comp2113-engg1340-group-project/blob/1cd66bfd883a18577a4b8d5d246b4aff21e000f6/include/events.h#L104-L176

Dynamic memory management (e.g., dynamic arrays, linked lists, STL containers)

https://github.com/eric15342335/comp2113-engg1340-group-project/blob/1cd66bfd883a18577a4b8d5d246b4aff21e000f6/include/stock.h#L282-L291

File input/output (e.g., for loading/saving game status)

This game provides players with the ability to create a new save file, load an existing save, or delete a save upon starting the game. The save files are distinguished by the std::string playerName variable.

Save File Structure

  • Each stock in the game has a separate .save file.
  • Basic player information is stored in the playerstatus.save file.
  • The Happy Stock Index (HSI) is stored in the hsi.save file.

Automatic Saving

To prevent loss of progress and prevent rollbacks, the game automatically saves the current state at the end of every round.

File Management

The game heavily relies on the <filesystem> library introduced in C++17 to maintain file organization. This library enables the game to:

  • Obtain a list of available save files.
  • Create new folders for save files.
  • Delete existing save files.

Note for macOS and Linux Users

If you are running the game on macOS or Linux and not from the terminal, the saves folder will be located in the root directory.

Program codes in multiple files (recall separate compilation)

We split our program codes into multiple files according to their functionality and purpose. Click me to see the details of each file.

Proper indentation and naming styles

We enforce our code formatting style via the use of clang-format tool. You can see our configuration file here.

For naming styles, different members of our group has different preferences. Some notable examples (list may not include all styles and files):

In-code documentation

We place a strong emphasis on code documentation in our project. We utilize the JavaDoc format to write our comments, which enables seamless integration with third-party documentation auto-generation tools like Doxygen.

If you've noticed the numerous hyperlinks throughout this README.md file, they are pointing to the automatically generated documentation hosted on our GitHub Pages site. You can access this documentation by clicking here.

Credits

Non-standard libraries used

External Libraries

For printing prettified tables in our code, we used the VariadicTable library. VariadicTable is a third-party header-only library licensed under LGPL-2.1.

Logo

The logo used in this game is generated with Text to ASCII.

Back to top