-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.hpp
More file actions
109 lines (98 loc) · 4.06 KB
/
player.hpp
File metadata and controls
109 lines (98 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once
#include <string>
#include <vector>
#include <iostream>
#include <limits>
#include <ostream>
#include <random>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
typedef struct player{
int playerId;
std::string symbol;
std::string name;
bool jailed;
int money;
int currentPosition;
std::vector<int> ownedStreets;
ColorGroup color;
int jailCounter;
int jailFreeCard;
bool bankrupt;
} player;
std::vector<player> initializePlayers() {
// Get number of players
std::cout<<"Please enter a number for players between 2 and 6:"<<std::endl;
int playersCount;
while (!(std::cin>>playersCount) || playersCount < 2 || playersCount > 6) {
std::cout<<"Invalid input. Please enter a number for players between 2 and 6:"<<std::endl;
clearInputBuffer();
}
// Vectors to track used symbols and colors
std::vector<std::string> usedSymbols;
std::vector<ColorGroup> usedColors;
// initialize Players
std::vector<player> initPlayers;
for (int i = 0; i < playersCount; i++){
std::cout << "\n==============================================================================" << std::endl;
player p;
std::cout<<"Please enter the name of player "<< i+1 <<":"<<std::endl;
std::cin>>p.name;
p.jailed = false;
p.money = 1500;
p.currentPosition = 0;
p.playerId = i;
p.ownedStreets = {};
p.jailCounter = 0;
p.jailFreeCard = 0;
p.bankrupt = false;
// Symbol Selection
std::cout << "\nChoose your symbol:\n";
// Display available symbols
for (size_t j = 0; j < availableSmybols.size(); ++j) {
if (std::find(usedSymbols.begin(), usedSymbols.end(), availableSmybols[j]) == usedSymbols.end())
std::cout << j << ": " << availableSmybols[j] << " ";
}
std::cout << "\nEnter the number of your choice: ";
// Get valid choice
int choice = -1;
while (!(std::cin >> choice) || choice < 0 || choice >= (int)availableSmybols.size() ||
std::find(usedSymbols.begin(), usedSymbols.end(), availableSmybols[choice]) != usedSymbols.end()) {
std::cout<<"Invalid choice, please pick another: ";
clearInputBuffer();
}
// Assign and mark as used
std::string playerSymbol = availableSmybols[choice];
usedSymbols.push_back(playerSymbol);
p.symbol = playerSymbol;
std::cout << "You chose symbol: " << p.symbol << "\n";
// Color Selection
std::cout << "\nChoose your color:\n";
for (size_t j = 1; j < availableColors.size(); ++j) {
if (std::find(usedColors.begin(), usedColors.end(), availableColors[j].second) == usedColors.end()) {
std::cout << j - 1 << ": "
<< colorCodes[j].first << p.symbol << RESET_COLOR
<< " (" << availableColors[j].first << ") ";
}
}
std::cout << "\nEnter the number of your choice: ";
// Get valid choice
int colorChoice = -1;
while (!(std::cin >> colorChoice) || colorChoice < 0 || colorChoice >= (int)availableColors.size() ||
std::find(usedColors.begin(), usedColors.end(), availableColors[colorChoice + 1].second) != usedColors.end()) {
std::cout<<"Invalid choice, please pick another: ";
clearInputBuffer();
}
// Assign and mark as used
ColorGroup playerColor = availableColors[colorChoice + 1].second; // .second to get ColorGroup from pair (mapping)
p.color = playerColor;
usedColors.push_back(playerColor);
// usage of colorCodes vector to get ANSI code, then reset after symbol
std::cout << "You chose color: " << colorCodes[colorChoice + 1].first << p.symbol << RESET_COLOR << " (" << availableColors[colorChoice + 1].first << ")" << std::endl;
// Add player to the list
initPlayers.push_back(p);
}
return initPlayers;
}