Human-computer interactions functions.
More...
Go to the source code of this file.
|
void | advanceConfirmation (int row, int col, bool &advance, bool &flush) |
|
void | buyStocks (int row, int col, float &balance, float tax, std::vector< Stock > &stocks, bool &flush) |
|
int | integerInput (int row, int col, const std::string &message) |
|
void | optionsInput (int row, int col, float &balance, float tax, std::vector< Stock > &stocks, const std::vector< Stock_event > &events, bool &viewMode, bool &advance, bool &overlayEvent, bool &flush, bool &gameQuit) |
|
void | quitConfirmation (int row, int col, bool &flush, bool &gameQuit) |
|
void | sellStocks (int row, int col, float &balance, float tax, std::vector< Stock > &stocks, bool &flush) |
|
void | toggleView (bool &viewMode, bool &flush) |
|
Human-computer interactions functions.
Definition in file controls.cpp.
◆ advanceConfirmation()
void advanceConfirmation |
( |
int | row, |
|
|
int | col, |
|
|
bool & | advance, |
|
|
bool & | flush ) |
Definition at line 154 of file controls.cpp.
154 {
155 std::ignore = col;
156 char input = 'x';
158 std::cout << "Press [Y] to confirm: ";
159 std::cin >> input;
160 if (input == 'Y' || input == 'y') {
161 advance = true;
162 flush = true;
163 }
164}
References setCursorPosition().
Referenced by optionsInput().
◆ buyStocks()
void buyStocks |
( |
int | row, |
|
|
int | col, |
|
|
float & | balance, |
|
|
float | tax, |
|
|
std::vector< Stock > & | stocks, |
|
|
bool & | flush ) |
Definition at line 90 of file controls.cpp.
91 {
92 int index;
93 int amount;
94
95 index =
integerInput(row, col,
"Enter the index of the stock as shown: ");
96 while (index < 1 || index > static_cast<int>(stocks.size())) {
98 std::cout << "Index out of range!";
100 index =
integerInput(row, col,
"Enter the index of the stock as shown: ");
101 }
102 amount =
integerInput(row, col,
"Enter the amount to buy (0 to skip): ");
103 while (amount < 0) {
105 std::cout << "You cannot purchase negative amounts!";
107 index =
integerInput(row, col,
"Enter the amount to buy (0 to skip): ");
108 }
109 while (amount >
110 static_cast<int>(stocks[index - 1].num_stocks_affordable(
balance, tax))) {
112 std::cout << "Cannot afford!";
114 amount =
integerInput(row, col,
"Enter the amount to buy (0 to skip): ");
115 }
116 stocks[index - 1].purchase(
balance, amount, tax);
117 flush = true;
118}
static void sleep(int dur)
int integerInput(int row, int col, const std::string &message)
float balance
Player's balance.
References balance, integerInput(), setCursorPosition(), time::sleep(), and sleepMedium.
Referenced by optionsInput().
◆ integerInput()
int integerInput |
( |
int | row, |
|
|
int | col, |
|
|
const std::string & | message ) |
Definition at line 71 of file controls.cpp.
71 {
72 std::ignore = col;
73 int num;
74 while (true) {
76 std::cout << message;
77 std::cin >> num;
78 if (!std::cin) {
79 std::cin.clear();
81 std::cout << "don't";
82 std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
84 continue;
85 }
86 return num;
87 }
88}
References setCursorPosition(), time::sleep(), and sleepMedium.
Referenced by buyStocks(), main(), and sellStocks().
◆ optionsInput()
void optionsInput |
( |
int | row, |
|
|
int | col, |
|
|
float & | balance, |
|
|
float | tax, |
|
|
std::vector< Stock > & | stocks, |
|
|
const std::vector< Stock_event > & | events, |
|
|
bool & | viewMode, |
|
|
bool & | advance, |
|
|
bool & | overlayEvent, |
|
|
bool & | flush, |
|
|
bool & | gameQuit ) |
Definition at line 17 of file controls.cpp.
20 {
21 char input = '.';
22 while (true) {
24 std::cout << "Choose an option from the bar above: ";
25 std::cin >> input;
26 switch (input) {
27 case 'B':
28 case 'b':
30 break;
31 case 'S':
32 case 's':
34 break;
35 case 'T':
36 case 't':
38 break;
39 case 'E':
40 case 'e':
41 if (!overlayEvent) {
42 overlayEvent = true;
44 }
45 else {
46 flush = true;
47 }
48 break;
49 case 'N':
50 case 'n':
52 break;
53
54
55
56 case 'X':
57 case 'x':
59 break;
60 default:
62 std::cout << "nope";
63 std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
65 continue;
66 }
67 break;
68 }
69}
void buyStocks(int row, int col, float &balance, float tax, std::vector< Stock > &stocks, bool &flush)
void sellStocks(int row, int col, float &balance, float tax, std::vector< Stock > &stocks, bool &flush)
void advanceConfirmation(int row, int col, bool &advance, bool &flush)
void toggleView(bool &viewMode, bool &flush)
void quitConfirmation(int row, int col, bool &flush, bool &gameQuit)
void listEvents(int row, int col, std::vector< Stock_event > events)
References advanceConfirmation(), balance, buyStocks(), listEvents(), quitConfirmation(), sellStocks(), setCursorPosition(), time::sleep(), sleepMedium, and toggleView().
Referenced by main().
◆ quitConfirmation()
void quitConfirmation |
( |
int | row, |
|
|
int | col, |
|
|
bool & | flush, |
|
|
bool & | gameQuit ) |
Definition at line 166 of file controls.cpp.
166 {
167 std::ignore = col;
168 char input = 'x';
170 std::cout << "Press [Y] to confirm: ";
171 std::cin >> input;
172 if (input == 'Y' || input == 'y') {
173 gameQuit = true;
174 flush = true;
175 }
176}
References setCursorPosition().
Referenced by optionsInput().
◆ sellStocks()
void sellStocks |
( |
int | row, |
|
|
int | col, |
|
|
float & | balance, |
|
|
float | tax, |
|
|
std::vector< Stock > & | stocks, |
|
|
bool & | flush ) |
Definition at line 120 of file controls.cpp.
121 {
122 int index;
123 int amount;
124
125 index =
integerInput(row, col,
"Enter the index of the stock as shown: ");
126 while (index < 1 || index > static_cast<int>(stocks.size())) {
128 std::cout << "Index out of range!";
130 index =
integerInput(row, col,
"Enter the index of the stock as shown: ");
131 }
132 amount =
integerInput(row, col,
"Enter the amount to sell (0 to skip): ");
133 while (amount < 0) {
135 std::cout << "You cannot sell negative amounts!";
137 index =
integerInput(row, col,
"Enter the amount to sell (0 to skip): ");
138 }
139 while (amount > static_cast<int>(stocks[index - 1].get_quantity())) {
141 std::cout << "You do not have this many stocks!";
143 amount =
integerInput(row, col,
"Enter the amount to sell (0 to skip): ");
144 }
145 stocks[index - 1].sell(
balance, amount, tax);
146 flush = true;
147}
References balance, integerInput(), setCursorPosition(), time::sleep(), and sleepMedium.
Referenced by optionsInput().
◆ toggleView()
void toggleView |
( |
bool & | viewMode, |
|
|
bool & | flush ) |