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 File Reference

Functions that handles the drawing and display of various elements. More...

#include "draw.h"
#include "file_io.h"
Include dependency graph for draw.cpp:

Go to the source code of this file.

Functions

void drawButton (int row, int col)
 
void drawEventBar (int row, int col)
 
void drawLogo (int row, int col)
 
void drawRoundInfo (int row, int col, int round, float balance, std::string player, float indexHSI)
 
void listEvents (int row, int col, std::vector< Stock_event > events)
 

Detailed Description

Functions that handles the drawing and display of various elements.

Definition in file draw.cpp.

Function Documentation

◆ drawButton()

void drawButton ( int row,
int col )

Definition at line 156 of file draw.cpp.

156 {
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}
const string textWhite
Definition format.cpp:36
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 bgBlack
Definition format.cpp:39
const string textBlack
Definition format.cpp:29
const string textBold
Definition format.cpp:23

References bgBlack, bgWhite, setCursorPosition(), textBlack, textBold, textReset, and textWhite.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawEventBar()

void drawEventBar ( int row,
int col )

Definition at line 73 of file draw.cpp.

73 {
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}

References setCursorPosition().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawLogo()

void drawLogo ( int row,
int col )

Definition at line 19 of file draw.cpp.

19 {
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}
static void sleep(int dur)
Definition format.cpp:52
vector< string > parseLogo(void)
returns the game logo, which is hardcoded inside the function.
Definition file_io.cpp:34
const int sleepShort
Definition format.cpp:48
const int sleepMedium
Definition format.cpp:49
const string textClear
Definition format.cpp:20

References parseLogo(), setCursorPosition(), time::sleep(), sleepMedium, sleepShort, and textClear.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ drawRoundInfo()

void drawRoundInfo ( int row,
int col,
int round,
float balance,
std::string player,
float indexHSI )

Definition at line 52 of file draw.cpp.

53 {
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}
float balance
Player's balance.
Definition main.cpp:68

References balance, and setCursorPosition().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ listEvents()

void listEvents ( int row,
int col,
std::vector< Stock_event > events )

Definition at line 90 of file draw.cpp.

90 {
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}

References setCursorPosition().

Referenced by optionsInput().

Here is the call graph for this function:
Here is the caller graph for this function: