-
Notifications
You must be signed in to change notification settings - Fork 1
/
Control.cc
111 lines (102 loc) · 3.8 KB
/
Control.cc
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
#include "Control.h"
#include "View.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <limits>
// Constructor for the Control object
Control::Control() {
}
// Destructor for the control object
Control::~Control() {
}
// Draw a participant from a selected school
void Control::drawParticipant(vector<Participant> candidates, string school) {
int candidateNum = rand() % candidates.size();
while (candidates[candidateNum].getSchool() != school) {
candidateNum = rand() % candidates.size();
}
candidates[candidateNum].displayInfo();
}
// Launch the user interface
void Control::launch(void) {
// Initialize the random seed
srand( (unsigned)time( NULL ) );
// Create a View object
View view;
// Declare and initialize the choice
int choice;
// Declare and initialize the student attributes: name, age, and school
std::string name;
int age;
std::string school;
// Declare and initialize has a school booleans
bool hasHogwarts = false;
bool hasDurmstrang = false;
bool hasBeauxbatons = false;
// Display the main menu
while (1) {
view.displayMenu(choice);
// Get out of the program
if (choice == 0) {
break;
}
// Add a participant to the Goblet of fire
else if (choice == 1) {
// Prompt the user to input their age.
cout << "You are at the age line. Please enter your age:" << endl;
cin >> age;
// Clear the buffer
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
// If the user is under 17, go back to the main menu
if (age < 17) {
cout << "You are not allowed to participate in the Triwizard Tournament. Even if you look older or are under the aging potion, you are still not allowed." << endl;
continue;
}
cout << endl;
// Prompt the user to add a name and school
cout << "Please enter your name:" << endl;
std::getline(std::cin,name);
if (name.empty()) {
cout << "You didn't enter a name" << endl;
continue;
}
cout << endl;
cout << "Please enter your school:" << endl;
std::getline(std::cin,school);
if (school.empty()) {
cout << "You didn't enter a school" << endl;
continue;
}
cout << endl;
// If there is a Hogwarts, Beauxbatons, or Durmstrang student added to the list, match the appropriate boolean variable to true
if (school == "Hogwarts") {
hasHogwarts = true;
}
else if (school == "Beauxbatons") {
hasBeauxbatons = true;
}
else if (school == "Durmstrang") {
hasDurmstrang = true;
}
// Statically allocate a participant object
Participant p = Participant(name, age, school);
// Add the participant object to the vector
participants.push_back(p);
}
// Drawing out characters
else if (choice == 2 && participants.size() >= 3 && (hasHogwarts && hasBeauxbatons && hasDurmstrang)) {
// Pick a student from Hogwarts
drawParticipant(participants, "Hogwarts");
// Pick a student from Beauxbatons
drawParticipant(participants, "Beauxbatons");
// Pick a student from Durmstrang
drawParticipant(participants, "Durmstrang");
// Mentioning Harry Potter
// cout << "Harry Potter, (14) from Hogwarts" << endl;
}
else if (choice == 2) {
cout << "Not enough participants" << endl;
}
} // while(1)
} // void Control::launch(void) {