- Team Members
- Game Description
- How to Play
- Code Requirements
- Generation of random game sets or events
- Data structures for storing game status (e.g., arrays, STL containers)
- Dynamic memory management (e.g., dynamic arrays, linked lists, STL containers)
- File input/output (e.g., for loading/saving game status)
- Program codes in multiple files (recall separate compilation)
- Proper indentation and naming styles
- In-code documentation
- Credits
Name | UID | Profile |
---|---|---|
Cheng Ho Ming | 3036216734 | |
Chung Shing Hei | 3036216760 | |
Chow Yui Hei | 3036222446 | |
Chu Chun Yin | 3036270778 | |
Wong Sonny | 3036222458 |
"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.
Prerequisite:
- This repository.
- A working
g++
compiler that supportsC++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:
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.
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.
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 (or0
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. EnterT
again to hide the pop-up.E
: Display all ongoing events that affect the performance of stocks. EnterE
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 oftrading_fees_percent
.
Some additional columns are hidden, they served for debugging purposes only.
Generation of stock prices:
- We used normal distribution to generate the percentage change in the stock price for each new round.
comp2113-engg1340-group-project/src/random_price.cpp
Lines 114 to 128 in 1cd66bf
Generation of in-game events:
- In our game, we also included 99 events that will each have a possibility to happen in your gameplay.
- The (relative) probability of each event is determined by the
Stock_event.probability_permille
member variable.
- The (relative) probability of each event is determined by the
comp2113-engg1340-group-project/src/events.cpp
Lines 48 to 60 in 1cd66bf
In stock.h, we declared class Stock which utilizes STL vector
, list
and map
to store various game data.
comp2113-engg1340-group-project/include/stock.h
Lines 266 to 295 in 1cd66bf
The class Stock
itself represents an Stock object, which you can purchase, sell, generate a new price for it, etc.
comp2113-engg1340-group-project/include/stock.h
Lines 36 to 58 in 1cd66bf
Other than class Stock
, we have struct Stock_event that represents an in-game event.
comp2113-engg1340-group-project/include/events.h
Lines 104 to 176 in 1cd66bf
Dynamic memory management (e.g., dynamic arrays, linked lists, STL containers)
- Stock.history is an
std::vector<float>
that stores the history of the stock prices. - Stock.events is an
std::list<Stock_event>
that stores on-going events that applies to the stock itself. - Stock.attributes is an
std::map<stock_modifiers, float>
that stores the properties related to stock price generation.
comp2113-engg1340-group-project/include/stock.h
Lines 282 to 291 in 1cd66bf
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.
- 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.
To prevent loss of progress and prevent rollbacks, the game automatically saves the current state at the end of every round.
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.
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.
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):
-
snake_case: @eric15342335 stock.cpp stock.h events.h
-
camelCase: @Prismatiscence format.cpp format.h draw.cpp draw.h controls.cpp controls.h
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.
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.
The logo used in this game is generated with Text to ASCII.