-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
177 lines (158 loc) · 5.62 KB
/
main.cpp
File metadata and controls
177 lines (158 loc) · 5.62 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
175
176
177
/**************************************************************
* Name : Project Name
* Author : Evan Bunnell
* Created : 00/00/0000
* Course : CIS 152 - Data Structures
* Version : 1.0
* OS : Windows 10
* Copyright : This is my own original work based on
* specifications issued by our instructor
* Description : This program overall description here
* Input: list and describe
* Output: list and describe
* Academic Honesty: I attest that this is my original work.
* I have not used unauthorized source code, either modified or
* unmodified. I have not given other fellow student(s) access to
* my program.
***************************************************************/
#include <algorithm>
#include <iostream>
#include "character.h"
#include "list.h"
using namespace std;
void menu();
void insertMenu();
void deleteMenu();
void displayRoster();
Character character;
List list;
int main() {
// prepopulating the list for testing/demonstration
character.build("Kards", "Rogue", "dps");
list.insert(character);
character.build("Melody", "Priest", "healer");
list.insert(character);
character.build("Kronkh", "Warrior", "tank");
list.insert(character);
character.build("Fergy", "Paladin", "tank");
list.insert(character);
character.build("Hohenheim", "Paladin", "healer");
list.insert(character);
character.build("Boomboom", "Mage", "dps");
list.insert(character);
menu();
return 0;
}
void menu() {
int input;
cout << "What would you like to do?\n"
<< "1. Add character to roster.\n"
<< "2. Delete character from roster.\n"
<< "3. Display roster.\n"
<< "0. Quit.\n";
cin >> input;
while (input != 0) {
if (input > 3 || input < 0) {
cout << "Invalid input.\n";
menu();
cin >> input;
}
if (input == 1) {
insertMenu();
}
else if (input == 2) {
deleteMenu();
}
else displayRoster();
}
exit(0);
}
void insertMenu() {
string name, Class, role;
char confirm;
cout << "\nPlease enter the name of the character:\n";
cin >> name;
while (name.length() > 12) {
cout << "Sorry, character names must be no longer than 12 characters.\n"
"Please re-enter the name:\n";
cin >> name;
}
cout << "\nPlease enter the character's in-game class:\n(Warrior, Paladin, Priest, Mage, or Rogue)\n";
cin >> Class;
transform(Class.begin(), Class.end(), Class.begin(), [](unsigned char c) {return tolower(c);});
while (Class != "warrior" && Class != "paladin" && Class != "priest" && Class != "rogue" && Class != "mage") {
cout << "Sorry, the character's class must be either Warrior, Paladin, Priest, Mage, or Rogue.\n"
"Please re-renter the class:\n";
cin >> Class;
transform(Class.begin(), Class.end(), Class.begin(), [](unsigned char c) {return tolower(c);});
}
if (Class == "rogue" || Class == "mage") {
role = "dps";
}
else {
cout << "\nAre you a tank, healer, or dps (damage per second)?\n";
cin >> role;
transform(role.begin(), role.end(), role.begin(), [](unsigned char c) {return tolower(c);});
if (Class == "warrior") {
while (role != "tank" && role != "dps") {
cout << "Warriors can only be tanks or dps.\n"
"Please re-enter your role.\n";
cin >> role;
transform(role.begin(), role.end(), role.begin(), [](unsigned char c) {return tolower(c);});
}
}
else if (Class == "paladin") {
while (role != "tank" && role != "dps" && role != "healer") {
cout << "The available roles are: Tank, Healer, or DPS.\n"
"Please re-enter your role.\n";
cin >> role;
transform(role.begin(), role.end(), role.begin(), [](unsigned char c) {return tolower(c);});
}
}
else if (Class == "priest") {
while (role != "dps" && role != "healer") {
cout << "Priests can only be healer or dps.\n"
"Please re-enter your role.\n";
cin >> role;
transform(role.begin(), role.end(), role.begin(), [](unsigned char c) {return tolower(c);});
}
}
}
cout << "\nYou have entered:\nName: " << name << "\nClass: " << Class << "\nRole: " << role << "\n\nIs this correct? (y/n)" << endl;
cin >> confirm;
confirm = tolower(confirm);
while (confirm != 'y') {
if (confirm == 'n') {
insertMenu();
}
else {
cout << "You have entered:\nName: " << name << "\nClass: " << Class << "\nRole: " << role << "\n\nIs this correct? (y/n)" << endl;
cin >> confirm;
confirm = tolower(confirm);
}
}
character.build(name, Class, role);
list.insert(character);
cout << endl;
menu();
}
void deleteMenu() {
string name;
cout << "\nWhat is the name of the character you would like to remove from the roster?\n";
cin >> name;
if (list.search(name)) {
list.Delete(name);
}
else {
cout << "Character " << name << " not found.\n";
deleteMenu();
}
cout << endl;
menu();
}
void displayRoster() {
list.sort();
list.display();
cout << endl;
menu();
}