-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdice.cpp
More file actions
283 lines (246 loc) · 5.57 KB
/
dice.cpp
File metadata and controls
283 lines (246 loc) · 5.57 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#include <iostream>
#include <ctime>
#include <limits>
int Dice(int side);
void Highest(int &total);
void Add(int &total);
int Side();
void Stats();
int Highest(int all,int highest,int side);
int main(){
srand(time(NULL));
int total{0}, choice{0};
std::cout << "Welcome to this BASIC AS BREAD dice function!\n";
//Menu
std::cout << "What would you like to do?\n\t1. Highest of a number of rolls\n\t2. Add a few die and subtract some\n\t3. Roll just one dice (BASIC)\n\t4. STAT rolling go brrrrr\n";
while(true)
{
if(std::cin >> choice && choice > 0 && choice < 5)
{
std::cout << "Ayt leggo->\n";
break;
}
else
{
std::cout << "Now that wasn't nice. Bad Input >:(\n";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Another one: ";
}
}
switch(choice)
{
case 1:
Highest(total);
break;
case 2:
Add(total);
break;
case 3:
Dice(Side());
break;
case 4:
Stats();
}
if(choice != 4)
std::cout << "Here's your result: " << total << std::endl;
std::cout << "Thanks :3\n";
return 0;
}
//Stat roll
void Stats(){
std::cout << "Hey you want some STATS???? I'll give you STATS!!!!\n";
for(int i{1}; i <= 6; i++)
{
std::cout << "STAT " << i << ": " << Highest(4, 3, 6) << '\n';
}
}
//Take highest X of Y rolls
void Highest(int &total){
total = 0;
int side = Side();
int all{0};
std::cout << "Ayt, how many die we rolling: ";
while(true)
{
if(std::cin >> all && all > 0)
{
std::cout << "Coolio!\n";
break;
}
else
{
std::cout << "Bruh... Only numbers, and not less than one...\n";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Now do it again: ";
}
}
int* rolls = new int[all];
for(int i{0}; i < all; i++)
{
rolls[i] = Dice(side);
}
int highest{0};
std::cout << "So how many we actually taking: ";
while(true)
{
if(std::cin >> highest && highest >= 0 && highest < all)
{
std::cout << "Coolio!\n";
break;
}
else
{
std::cout << "Bruh... Only numbers... and you cannot pick more die than you have\n";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Now do it again: ";
}
}
int temp{0};
for(int i{0}; i<(all-1); i++)
{
for(int j{i+1}; j < all; j++)
{
if(rolls[i] < rolls[j])
{
temp = rolls[i];
rolls[i] = rolls[j];
rolls[j] = temp;
}
}
}
for(int i{0}; i < highest; i++)
{
total += rolls[i];
}
delete[] rolls;
}
//Add and subtract
void Add(int &total){
total = 0;
int side = Side();
int add{0};
std::cout << "First enter how many dice you want to roll and add: ";
while(true)
{
if(std::cin >> add && add > 0)
{
std::cout << "Coolio!\n";
break;
}
else
{
std::cout << "Bruh... Only numbers, and not less than one...\n";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Now do it again: ";
}
}
for(int i{0}; i < add; i++)
{
total += Dice(side);
}
int minus{0};
std::cout << "Now, all you gotta do is tell me how many dice you wanna roll to subtract from the addition you just did: ";
std::cin >> minus;
while(true)
{
if(std::cin >> minus && minus < add && minus > 0)
{
std::cout << "Coolio!\n";
break;
}
else
{
std::cout << "Bruh... Only numbers, and not less than one... and for goodness' sake don't subtract more dice than you add :(\n";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Now do it again: ";
}
}
for(int i{0}; i < minus; i++)
{
total -= Dice(side);
}
}
int Side(){
int side{0};
std::cout << "Real quick how many sides are in the die: ";
while(true)
{
if(std::cin >> side)
{
switch (side)
{
case 4:
case 6:
case 8:
case 10:
case 12:
case 20:
case 100:
std::cout << "Arigatou!\n";
return side;
default:
std::cout << "There are no die with " << side << " sides\n AGAIN!: ";
}
}
else
{
std::cout << "You trying to crash this thing?\n";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Once more bugger: ";
}
}
}
//Dice function
int Dice(int side){
//result variable to output the result
int result{ 0 };
//Limit function to only allow 4, 6, 8, 10, 12, 20, 100 sided die
switch (side)
{
case 4:
case 6:
case 8:
case 10:
case 12:
case 20:
case 100:
result = ((rand() % side) + 1); //Add 1 to result since '0' is not a possible role
//std::cout << "Rolled " << side << "-sided die, result: " << result << std::endl;
return result;
default:
return 0;
}
}
int Highest(int all,int highest,int side){
int total{0};
int* rolls = new int[all];
for(int i{0}; i < all; i++)
{
rolls[i] = Dice(side);
}
int temp{0};
for(int i{0}; i<(all-1); i++)
{
for(int j{i+1}; j < all; j++)
{
if(rolls[i] < rolls[j])
{
temp = rolls[i];
rolls[i] = rolls[j];
rolls[j] = temp;
}
}
}
for(int i{0}; i < highest; i++)
{
total += rolls[i];
}
delete[] rolls;
return total;
}