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
|
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <string>
#include <time.h>
using namespace std;
int roll(int b, int v, int h, int e) {
/* b is die number, v is hit value, h is hits, e is used later in the program for special cases */
srand(time(0));
int x[6] = {};
int y;
h = 0;
int z = 0;
if (b == 0 or v == 0) {cout << "No Die\n";}
else {// For Attack numbers are b = 6, v = _4_, h = 0, e = 0
cout << "You Rolled: ";
while (z < 6) {
// Stores rand integers to x[6] and shows numbers rolled up to x[b]
x[z] = 1 + (rand() %8);
if (z < b) { // Displays Roll
cout << x[z] << ", ";
} // End if
z++;
} // End while1
cout << endl;
z = 0;
// Number of Hits
while (z < b) { // Totaling Hits
if (v - (x[z]) >= 0) {
h++;
} // End if
else {}
z++;
} // End while2
cout << "Hits: " << h << endl;
/*
….
Extraneous Code
….
*/
} // End else
z = 0;
x[6] = {};
cout << "Hits: " << h << endl;
return 0;
}
int combat() {
srand(time(0));
/*
….
Extraneous Code
….
*/
int av, bv, dv, exp, attack, exphit, block, defend, dexphit;
long dexp, dexpdie;
int SMtab[3][3] = {{1,0,-1}, {0,-1,-2}, {1,0,-1}};
int COtab[2] = {0,-1};
int RMtab[3] = {1,0,-1};
cout << "Enter Attack Value: ";
cin >> av;
int dieattack = (4 + SMtab[0][0] + RMtab[0] + COtab[0]);
// Equivalent to 4 + 1 + 1 + 0 = 6
int dieblock = (4 + SMtab[1][0] + RMtab[1] + COtab[0]);
cout << endl; // Clarity
cout << "Attack:\n";
roll(dieattack, av, attack, 0); // Attack Roll
cout << "Shots: " << attack << "\n" << endl;
/*
....
Extraneous Code
....
*/
}
int main()
{
combat();
return 0;
}
|