Code:
/*
Name: D&D 3rd Ed Stat Roller.
Author: Eric Volovski
Description: A stat roller for 3rd edition Dungeons and Dragons.
Date Created: 5-2-02 (12:03 AM EST - 1:53 AM EST)
Copyright: Freeware
*/
//OK, first off im way too tired to put in functions for all the stat rolls tonight, so
// for now im just going to have to use goto's! Gasp!
// I should also make a function for finding the lowest number... actually there problly is one...
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
int race(int str, int con, int in, int wis, int cha, int dex);
int roll(int str, int con, int in, int wis, int cha, int dex);
int final(int st2, int co2, int in2, int wi2, int ch2, int de2);
int main()
{
int str=0, in=0, wis=0, con=0, dex=0, cha=0;
cout<<"Welcome to Eric's D&D character stat roller. (3rd Ed)"<<endl;
srand(time(NULL));
race(0,0,0,0,0,0);
}
// Makes necessary adjustments to stats depending on race.
int race(int str, int con, int in, int wis, int cha, int dex)
{
int menu;
cout<<"Please choose from the following races"<<endl;
cout<<"1, Human."<<endl;
cout<<"2, Dwarf."<<endl;
cout<<"3, Elf."<<endl;
cout<<"4, Gnome."<<endl;
cout<<"5, Half-Elf."<<endl;
cout<<"6, Half-Orc."<<endl;
cout<<"7, Halfling."<<endl;
cin>>menu;
switch(menu)
{
case 1:
cout<<"Human, no adjustments."<<endl;
roll(0,0,0,0,0,0);
break;
case 2:
cout<<"Dwarf, +2 Constitution & -2 Charisma."<<endl;
roll(0,2,0,0,-2,0);
break;
case 3:
cout<<"Elf, -2 Constitution & +2 Dexterity."<<endl;
roll(0,-2,0,0,0,2);
break;
case 4:
cout<<"Gnome, -2 Strength & +2 Constitution."<<endl;
roll(-2,2,0,0,0,0);
break;
case 5:
cout<<"Half-Elf, no adjustments."<<endl;
roll(0,0,0,0,0,0);
break;
case 6:
cout<<"Half Orc, +2 Strength, -2 Intelligence & -2 Charisma."<<endl;
roll(2,0,-2,0,-2,0);
break;
case 7:
cout<<"Halfling, +2 Dexterity & -2 Strength."<<endl;
roll(-2,0,0,0,0,-2);
break;
default:
cout<<"Bad input, returning to main."<<endl;
main();
break;
}
}
int roll(int str, int con, int in, int wis, int cha, int dex)
{
int r1, r2, r3, r4;
int st1, co1, in1, wi1, ch1, de1;
cout<<"Generating Stats..."<<endl;
//This is the Confusing part :)
//====================================================STR====================
r1 = 1 + rand() % 6;
r2 = 1 + rand() % 6;
r3 = 1 + rand() % 6;
r4 = 1 + rand() % 6;
if(r1 <= r2 && r1 <= r3 && r1 <= r4) //If the first roll is lowest
{
st1 = r2 + r3 + r4 + str; //Str = Highest three rolls + race modifier.
goto con;
}
if(r2 <= r1 && r2 <= r3 && r2 <= r4) //If the second roll is the lowest
{
st1 = r1 + r3 + r4 + str;
goto con;
}
if(r3 <= r1 && r3 <= r2 && r3 <= r4) //If the third roll is the lowest
{
st1 = r1 + r2 + r4 + str;
goto con;
}
if(r4 <= r1 && r4 <= r2 && r4 <= r3) //If the fourth roll is the lowest
{
st1 = r1 + r2 + r3 + str;
goto con;
}
else
{
main();
}
//Yeah i know i COULD use a loop, but thats just too damn confusing.
//I'd rather just make it longer :)
//====================================================CON====================
con:
r1 = 1 + rand() % 6;
r2 = 1 + rand() % 6;
r3 = 1 + rand() % 6;
r4 = 1 + rand() % 6;
if(r1 <= r2 && r1 <= r3 && r1 <= r4) //If the first roll is lowest
{
co1 = r2 + r3 + r4 + con;
goto in;
}
if(r2 <= r1 && r2 <= r3 && r2 <= r4) //If the second roll is the lowest
{
co1 = r1 + r3 + r4 + con;
goto in;
}
if(r3 <= r1 && r3 <= r2 && r3 <= r4) //If the third roll is the lowest
{
co1 = r1 + r2 + r4 + con;
goto in;
}
if(r4 <= r1 && r4 <= r2 && r4 <= r3) //If the fourth roll is the lowest
{
co1 = r1 + r2 + r3 + con;
goto in;
}
else
{
main();
}
//====================================================INT====================
in:
r1 = 1 + rand() % 6;
r2 = 1 + rand() % 6;
r3 = 1 + rand() % 6;
r4 = 1 + rand() % 6;
if(r1 <= r2 && r1 <= r3 && r1 <= r4) //If the first roll is lowest
{
in1 = r2 + r3 + r4 + in;
goto wis;
}
if(r2 <= r1 && r2 <= r3 && r2 <= r4) //If the second roll is the lowest
{
in1 = r1 + r3 + r4 + in;
goto wis;
}
if(r3 <= r1 && r3 <= r2 && r3 <= r4) //If the third roll is the lowest
{
in1 = r1 + r2 + r4 + in;
goto wis;
}
if(r4 <= r1 && r4 <= r2 && r4 <= r3) //If the fourth roll is the lowest
{
in1 = r1 + r2 + r3 + in;
goto wis;
}
else
{
main();
}
//====================================================WIS====================
wis:
r1 = 1 + rand() % 6;
r2 = 1 + rand() % 6;
r3 = 1 + rand() % 6;
r4 = 1 + rand() % 6;
if(r1 <= r2 && r1 <= r3 && r1 <= r4) //If the first roll is lowest
{
wi1 = r2 + r3 + r4 + wis;
goto cha;
}
if(r2 <= r1 && r2 <= r3 && r2 <= r4) //If the second roll is the lowest
{
wi1 = r1 + r3 + r4 + wis;
goto cha;
}
if(r3 <= r1 && r3 <= r2 && r3 <= r4) //If the third roll is the lowest
{
wi1 = r1 + r2 + r4 + wis;
goto cha;
}
if(r4 <= r1 && r4 <= r2 && r4 <= r3) //If the fourth roll is the lowest
{
wi1 = r1 + r2 + r3 + wis;
goto cha;
}
else
{
main();
}
//====================================================CHA====================
cha:
r1 = 1 + rand() % 6;
r2 = 1 + rand() % 6;
r3 = 1 + rand() % 6;
r4 = 1 + rand() % 6;
if(r1 <= r2 && r1 <= r3 && r1 <= r4) //If the first roll is lowest
{
ch1 = r2 + r3 + r4 + cha;
goto dex;
}
if(r2 <= r1 && r2 <= r3 && r2 <= r4) //If the second roll is the lowest
{
ch1 = r1 + r3 + r4 + cha;
goto dex;
}
if(r3 <= r1 && r3 <= r2 && r3 <= r4) //If the third roll is the lowest
{
ch1 = r1 + r2 + r4 + cha;
goto dex;
}
if(r4 <= r1 && r4 <= r2 && r4 <= r3) //If the fourth roll is the lowest
{
ch1 = r1 + r2 + r3 + cha;
goto dex;
}
else
{
main();
}
//====================================================DEX====================
dex:
r1 = 1 + rand() % 6;
r2 = 1 + rand() % 6;
r3 = 1 + rand() % 6;
r4 = 1 + rand() % 6;
if(r1 <= r2 && r1 <= r3 && r1 <= r4) //If the first roll is lowest
{
de1 = r2 + r3 + r4 + dex;
goto end;
}
if(r2 <= r1 && r2 <= r3 && r2 <= r4) //If the second roll is the lowest
{
de1 = r1 + r3 + r4 + dex;
goto end;
}
if(r3 <= r1 && r3 <= r2 && r3 <= r4) //If the third roll is the lowest
{
de1 = r1 + r2 + r4 + dex;
goto end;
}
if(r4 <= r1 && r4 <= r2 && r4 <= r3) //If the fourth roll is the lowest
{
de1 = r1 + r2 + r3 + dex;
goto end;
}
else
{
main();
}
//Well, that was pleasant :)
end:
final(st1, co1, in1, wi1, ch1, de1);
}
int final(int st2, int co2, int in2, int wi2, int ch2, int de2)
{
system("cls");
cout<<"You're stats are:"<<endl;
cout<<"Strength: "<<st2<<endl;
cout<<"Dexterity: "<<de2<<endl;
cout<<"Intelligence: "<<in2<<endl;
cout<<"Wisdom: "<<wi2<<endl;
cout<<"Charisma: "<<ch2<<endl;
cout<<"Constitution: "<<co2<<endl;
system("pause");
}
To all of those people who actually read all that, i am sorry.