-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCDegrees.cpp
More file actions
175 lines (161 loc) · 5.26 KB
/
CDegrees.cpp
File metadata and controls
175 lines (161 loc) · 5.26 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "CDegrees.h"
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iostream>
#include "CAssessment.h"
#include "CExtraCurricular.h"
#include "CBogus.h"
#include "CBonus.h"
#include "CPlagiarismHearing.h"
#include "CAccusedOfPlagiarism.h"
void CDegrees::ReadSpaces(const std::string &filename)
{
try
{
std::ifstream file(filename);
if (file.is_open())
{
int type;
std::string name;
while (file >> type)
{
std::getline(file >> std::ws, name); // Read the rest of the line as name
switch (type)
{
case 1:
{
int cost, achievement, year;
std::string first, second;
std::istringstream iss(name);
iss >> first >> second >> cost >> achievement >> year;
name = first + " " + second;
mSpaces.push_back(std::make_unique<CAssessment>(type, name, cost, achievement));
break;
}
case 3:
{ // New case for ExtraCurricular
mSpaces.push_back(std::make_unique<CExtraCurricular>(type, name));
break;
}
case 4:
{
mSpaces.push_back(std::make_unique<CBonus>(type, name));
break;
}
case 5:
{
mSpaces.push_back(std::make_unique<CBogus>(type, name));
break;
}
case 6:
{
mSpaces.push_back(std::make_unique<CPlagiarismHearing>(type, name));
break;
}
case 7:
{
mSpaces.push_back(std::make_unique<CAccusedOfPlagiarism>(type, name));
break;
}
case 8:
{
mSpaces.push_back(std::make_unique<CPlagiarismHearing>(type, name));
break;
}
default:
{
mSpaces.push_back(std::make_unique<CSpace>(type, name));
}
}
}
file.close();
} else
{
throw std::runtime_error("Unable to open file: " + filename);
}
} catch (const std::exception &e)
{
std::cerr << e.what() << std::endl;
}
}
void CDegrees::AddPlayer(const std::string &name)
{
mPlayers.emplace_back(name);
}
void CDegrees::SimulatePlayerTurn(CPlayer ¤tPlayer)
{
currentPlayer.Spin();
int position = currentPlayer.GetPosition() - 1; // Adjust for 0-based indexing
CSpace *currentSpace = mSpaces[position].get();
std::cout << currentPlayer.GetName() << " lands on " << currentSpace->GetName() << std::endl;
currentSpace->PerformAction(currentPlayer);
currentPlayer.CheckAndHandleMotivation();
}
void CDegrees::Run()
{
std::cout << "Welcome to Scumbag College" << std::endl;
for (int round = 1; round <= 500; ++round)
{
std::cout << "\nRound " << round << std::endl;
for (auto &player: mPlayers)
{
if (!player.IsActive())
{
continue;
}
SimulatePlayerTurn(player);
}
for (const auto ¤tPlayer: mPlayers)
{
std::cout << currentPlayer.GetName() << "'s motivation is " << currentPlayer.GetMotivation()
<< " and success is " << currentPlayer.GetSuccess() << std::endl;
}
for (const auto &player: mPlayers)
{
if (player.HasGraduated())
{
std::cout << player.GetName() << " has graduated! Congratulations!" << std::endl;
GameOver();
return; // End the game
}
}
}
GameOver();
}
void CDegrees::GameOver()
{// Implement game over logic and winner determination
std::cout << "\n\nGame Over" << std::endl;
// Output final success for each player
for (const auto ¤tPlayer: mPlayers)
{
std::cout << currentPlayer.GetName() << " has achieved " << currentPlayer.GetSuccess() << std::endl;
}
for (const auto ¤tPlayer: mPlayers)
{
if (currentPlayer.HasGraduated())
{
std::cout << currentPlayer.GetName() << " has graduated and wins with " << currentPlayer.GetSuccess()
<< " achievements!" << std::endl;
return;
}
}
int maxSuccess = 0;
std::string winnerName;
for (const auto ¤tPlayer: mPlayers)
{
if (currentPlayer.GetSuccess() > maxSuccess)
{
maxSuccess = currentPlayer.GetSuccess();
winnerName = currentPlayer.GetName();
}
}
if (maxSuccess == 0)
{
std::cout << "No one wins. Everyone failed!" << std::endl;
} else
{
std::cout << winnerName << " wins with " << maxSuccess << " achievements!" << std::endl;
}
return;
}