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
draw.cpp
Go to the documentation of this file.
1/// @file draw.cpp
2/// Functions that handles the drawing and display of various elements
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#include "draw.h"
16
17#include "file_io.h"
18
19void drawLogo(int row, int col) {
20 const int wordWidth = 73; // Width of the longest word
21 const int wordHeight = 8; // Height for each word
22 std::vector<std::string> logo = parseLogo();
23
24 std::cout << textClear << setCursorPosition(0, 0);
25
26 // Will not print logo if terminal cannot fit
27 if (row > wordHeight && col > wordWidth) {
28 // Will use fileIO for this
29 for (int i = 0; i < 9; i++) {
30 std::cout << logo[i] << "\n";
31 }
33 std::cout << textClear << setCursorPosition(0, 0);
35 for (int i = 9; i < 18; i++) {
36 std::cout << logo[i] << "\n";
37 }
39 std::cout << textClear << setCursorPosition(0, 0);
41 for (int i = 18; i < 27; i++) {
42 std::cout << logo[i] << "\n";
43 }
45 }
46 else {
47 std::cout << "Welcome to Stock Market Simulator!\n";
48 }
49 std::cout << textClear << setCursorPosition(0, 0);
50}
51
53 int row, int col, int round, float balance, std::string player, float indexHSI) {
54 std::ignore = row; // Shutup compiler
55 std::cout << setCursorPosition(2, 5);
56 std::cout << "Round " << round;
57
58 if (player.size() > 15) {
59 std::cout << setCursorPosition(4, 0);
60 std::cout << player.erase(12) << "...";
61 }
62 else {
63 std::cout << setCursorPosition(
64 4, static_cast<int>((15 - player.size()) / 2 + 1));
65 std::cout << player;
66 }
67 std::cout << setCursorPosition(2, col - 10);
68 std::cout << "$" << balance;
69 std::cout << setCursorPosition(4, col - 12);
70 std::cout << " HSI: " << indexHSI;
71}
72
73void drawEventBar(int row, int col) {
74 std::ignore = row; // Shutup compiler
75 int width = col - 32;
76
77 std::cout << setCursorPosition(2, 16) << "\u250C";
78 for (int i = 0; i < width - 1; i++) {
79 std::cout << "\u2500";
80 }
81 std::cout << "\u2510" << setCursorPosition(3, 16) << "\u2502";
82 std::cout << setCursorPosition(3, width + 16) << "\u2502";
83 std::cout << setCursorPosition(4, 16) << "\u2514";
84 for (int i = 0; i < width - 1; i++) {
85 std::cout << "\u2500";
86 }
87 std::cout << "\u2518";
88}
89
90void listEvents(int row, int col, std::vector<Stock_event> events) {
91 int height;
92 int width = col - 20;
93
94 if (static_cast<int>(events.size()) < row - 10) {
95 if (static_cast<int>(events.size()) != 0) {
96 height = static_cast<int>(events.size()) + 2;
97 }
98 else {
99 height = 3;
100 }
101 }
102 else {
103 height = row - 10;
104 }
105
106 std::cout << setCursorPosition(6, 10) << "\u250C";
107 for (int i = 0; i < width - 1; i++) {
108 std::cout << "\u2500";
109 }
110 std::cout << "\u2510";
111 for (int i = 0; i < height; i++) {
112 std::cout << setCursorPosition(i + 7, 10);
113 std::cout << "\u2502";
114 std::cout << setCursorPosition(i + 7, width + 10);
115 std::cout << "\u2502";
116 }
117 std::cout << setCursorPosition(height + 7, 10) << "\u2514";
118 for (int i = 0; i < width - 1; i++) {
119 std::cout << "\u2500";
120 }
121 std::cout << "\u2518";
122
123 std::cout << setCursorPosition(7, 11);
124 for (int i = 0; i < width - 1; i++) {
125 std::cout << " ";
126 }
127 if (static_cast<int>(events.size()) == 0) {
128 std::cout << setCursorPosition(8, 11);
129 std::cout << "There are currently no events!";
130 for (int i = 0; i < width - 31; i++) {
131 std::cout << " ";
132 }
133 std::cout << setCursorPosition(9, 11);
134 for (int i = 0; i < width - 1; i++) {
135 std::cout << " ";
136 }
137 }
138 else {
139 for (int i = 1; i < static_cast<int>(events.size()) + 1; i++) {
140 std::cout << setCursorPosition(i + 7, 11);
141 std::cout << i << ". " << events[i - 1].text;
142 int digits = (((i) / 10) + 1);
143 for (int j = 0;
144 j < width - static_cast<int>(events[i - 1].text.size()) - 3 - digits;
145 j++) {
146 std::cout << " ";
147 }
148 }
149 std::cout << setCursorPosition(static_cast<int>(events.size()) + 8, 11);
150 for (int i = 0; i < width - 1; i++) {
151 std::cout << " ";
152 }
153 }
154}
155
156void drawButton(int row, int col) {
157 int width;
158 int buttons;
159
160 std::vector<std::string> options = {"[B] Buy", "[S] Sell", "[T] Toggle View",
161 "[E] Events", "[N] Next Round", "[X] Exit"}; // Add stuff here
162
163 buttons = options.size();
164 width = (col / buttons);
165
166 std::cout << textReset << setCursorPosition(row - 1, 3);
167 for (int i = 0; i < buttons; i++) {
168 i % 2 == 0 ? std::cout << bgWhite << textBlack
169 : std::cout << bgBlack << textWhite;
170 for (int j = 0; j < static_cast<int>((width - options[i].length()) / 2); j++) {
171 std::cout << " ";
172 }
173 std::cout << textBold << options[i] << "\x1b[22m";
174 for (int j = 0; j < static_cast<int>((width - options[i].length() -
175 (width - options[i].length()) / 2));
176 j++) {
177 std::cout << " ";
178 }
179 }
180 std::cout << textReset << "\n";
181}
static void sleep(int dur)
Definition format.cpp:52
void drawEventBar(int row, int col)
Definition draw.cpp:73
void listEvents(int row, int col, std::vector< Stock_event > events)
Definition draw.cpp:90
void drawButton(int row, int col)
Definition draw.cpp:156
void drawRoundInfo(int row, int col, int round, float balance, std::string player, float indexHSI)
Definition draw.cpp:52
void drawLogo(int row, int col)
Definition draw.cpp:19
Function declarations for drawing/display of various elements.
vector< string > parseLogo(void)
returns the game logo, which is hardcoded inside the function.
Definition file_io.cpp:34
Header files for file operation functions related to the game.
const int sleepShort
Definition format.cpp:48
const string textWhite
Definition format.cpp:36
const int sleepMedium
Definition format.cpp:49
const string textReset
Definition format.cpp:21
const string bgWhite
Definition format.cpp:46
string setCursorPosition(int offsetY, int offsetX)
Definition format.cpp:56
const string textClear
Definition format.cpp:20
const string bgBlack
Definition format.cpp:39
const string textBlack
Definition format.cpp:29
const string textBold
Definition format.cpp:23
float balance
Player's balance.
Definition main.cpp:68