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
file_io.h
Go to the documentation of this file.
1/// @file file_io.h
2/// Header files for file operation functions related to the game.
3/*
4This program is free software: you can redistribute it and/or modify it under the
5terms of the GNU Lesser General Public License as published by the Free Software
6Foundation, either version 3 of the License, or (at your option) any later version.
7
8This program is distributed in the hope that it will be useful, but WITHOUT ANY
9WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
10PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
11
12You should have received a copy of the GNU Lesser General Public License along with this
13program. If not, see <https://www.gnu.org/licenses/>.
14*/
15
16#ifndef FILE_IO_H
17#define FILE_IO_H
18#include "stock.h"
19
20/// @brief The user save options
22 public:
23 static const std::string NEW_GAME;
24 static const std::string LOAD_GAME;
25 static const std::string DELETE_GAME;
26 static const std::string EXIT_GAME;
27};
28
29extern const std::string USER_SAVE_OPTION_PROMPT;
30
31/**
32 * @brief Check if the input is valid. The input is valid if it is one of the options
33 * in the USER_SAVE_OPTION class.
34 * @param input The input string
35 * @return true if the input is valid, false otherwise
36 */
37inline bool checkValidInput(const std::string & input) {
38 return input.compare(USER_SAVE_OPTION::NEW_GAME) == 0 ||
39 input.compare(USER_SAVE_OPTION::LOAD_GAME) == 0 ||
40 input.compare(USER_SAVE_OPTION::DELETE_GAME) == 0 ||
41 input.compare(USER_SAVE_OPTION::EXIT_GAME) == 0;
42}
43
44// The prefix of the save folder
45const std::string SAVE_FOLDER_PREFIX = "saves/";
46
47// The extension of the save file, in plain text format
48const std::string SAVE_FILE_EXTENSION_TXT = ".save";
49
50/**
51 * @brief returns the game logo, which is hardcoded inside the function.
52 * @return a vector of strings, each string is a line of the logo
53 */
54std::vector<std::string> parseLogo(void);
55
56/**
57 * @brief Create a player folder.
58 * @param playerName Pass the playerName by reference.
59 */
60void createplayer(std::string & playerName);
61
62/**
63 * @brief Save the game status into *.save files.
64 * @param rounds_played The number of rounds played
65 * @param stocks_list A vector of stocks
66 * @param balance The balance of the player
67 * @param playerName The name of the player also the folder name
68 */
69void savestatus(unsigned int rounds_played, std::vector<Stock> stocks_list,
70 float balance, const std::string & playerName);
71
72/**
73 * @brief Load an existing game status from .save files. Paramenters should be empty and
74 * values are returned by reference.
75 * @param rounds_played The number of rounds played
76 * @param stocks_list A vector of stocks
77 * @param balance The balance of the player
78 * @param playerName The name of the player also the folder name
79 * @param hsi_history A vector of HSI history
80 */
81void loadstatus(unsigned int & rounds_played, std::vector<Stock> & stocks_list,
82 float & balance, std::string & playerName, std::vector<float> & hsi_history);
83
84/**
85 * @brief Delete a save
86 * @param mode Return the mode choice (0,1,2,3) by reference for further control after
87 * deleting
88 */
89void delsave(std::string & mode);
90
91/**
92 * @brief Get the list of saves aka player folders.
93 * @return a vector containing the name all the player folders
94 */
95std::vector<std::string> get_saves(void);
96
97/**
98 * @brief Print the vector of saves aka player folders.
99 */
100void printvector(const std::vector<std::string> & avector);
101
102#endif
The user save options.
Definition file_io.h:21
static const std::string DELETE_GAME
Definition file_io.h:25
static const std::string EXIT_GAME
Definition file_io.h:26
static const std::string NEW_GAME
Definition file_io.h:23
static const std::string LOAD_GAME
Definition file_io.h:24
const std::string USER_SAVE_OPTION_PROMPT
Definition file_io.cpp:28
bool checkValidInput(const std::string &input)
Check if the input is valid.
Definition file_io.h:37
void savestatus(unsigned int rounds_played, std::vector< Stock > stocks_list, float balance, const std::string &playerName)
Save the game status into *.save files.
Definition file_io.cpp:104
std::vector< std::string > parseLogo(void)
returns the game logo, which is hardcoded inside the function.
Definition file_io.cpp:34
const std::string SAVE_FOLDER_PREFIX
Definition file_io.h:45
void loadstatus(unsigned int &rounds_played, std::vector< Stock > &stocks_list, float &balance, std::string &playerName, std::vector< float > &hsi_history)
Load an existing game status from .save files.
Definition file_io.cpp:120
void createplayer(std::string &playerName)
Create a player folder.
Definition file_io.cpp:69
void printvector(const std::vector< std::string > &avector)
Print the vector of saves aka player folders.
Definition file_io.cpp:222
const std::string SAVE_FILE_EXTENSION_TXT
Definition file_io.h:48
void delsave(std::string &mode)
Delete a save.
Definition file_io.cpp:158
std::vector< std::string > get_saves(void)
Get the list of saves aka player folders.
Definition file_io.cpp:214
mode
hiding mean/sd/uplim/lowlim/event_id columns in the table
Definition main.cpp:104
float balance
Player's balance.
Definition main.cpp:68
unsigned int rounds_played
Number of rounds played.
Definition main.cpp:70
std::string playerName
Player's name.
Definition main.cpp:73
Declaration of the Stock class.