Ok, here is where I am up to. The code will ask for the numbers of attacking and defending units, and will request the Tech Level of the attackers and defenders. It then will work out what die type to assign to the attackers and defenders, and assign how many of that die type they get.
You may think it's all crap, but I'm pretty damn chuffed with it. My first programming in 20 years
My problem now is that I don't know how to sort the arrays ATTACKERARRAY and DEFENDERARRAY so I can compare the rolls. I appreciate the response I got above, but don't actually understand what it said (Still a total newb)
I'm using the DEV-C++ compiler 4.9.9.2.
Cheers,
Andrew Campbell.
Code:
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int ATMAX;
int ATTL;
int DEMAX;
int DETL;
int ATINITNUM;
int DEINITNUM;
int ROUNDNUM;
float COMPARISONAT; //the comparison of force sizes. This is a float, as it is derived by division.
float COMPARISONDE; //the comparison of force sizes. This is a float, as it is derived by division.
int DEADDDICE; //the additional dice that the defenders get due to force size
int ATADDDICE; //the add dice that the attackers get due to force size
int DEDICE; // this is the number of defending dice (normally 3), but modified by DEADDDICE
int ATDICE; // this is the number of attacking dice (normally 3), but modified by ATADDDICE
int STARTUP()
{
cout<<"Enter the Tech Level of the attacking force. \n";
cin>> ATTL;
switch ( ATTL ){
case 1:
cout<<"You chose TL1. Attacker will be rolling D6. \n";
ATMAX = 6;
cin.get ();
break;
case 2:
cout<<"You chose TL2. Attacker will be rolling D8. \n";
ATMAX = 8;
cin.get ();
break;
case 3:
cout<<"You chose TL3. Attacker will be rolling D10. \n";
ATMAX = 10;
cin.get ();
break;
case 4:
cout<<"You chose TL4. Attacker will be rolling D12. \n";
ATMAX = 12;
cin.get ();
break;
default:
cout<<"Non valid TL number entered, smartass. Exiting. \n";
cin.get ();
break;
}
cout<<"Enter the Tech Level of the defending force. \n";
cin>> DETL;
switch ( DETL ){
case 1:
cout<<"You chose TL1. Defender will be rolling D6. \n";
DEMAX = 6;
cin.get ();
break;
case 2:
cout<<"You chose TL2. Defender will be rolling D8. \n";
DEMAX = 8;
cin.get ();
break;
case 3:
cout<<"You chose TL3. Defender will be rolling D10. \n";
DEMAX = 10;
cin.get ();
break;
case 4:
cout<<"You chose TL4. Defender will be rolling D12. \n";
DEMAX = 12;
cin.get ();
break;
default:
cout<<"Non valid TL number entered, smartass. Exiting. \n";
cin.get ();
break;
}
cout<<"\n The ATMAX variable, the max die roll, is set at ("<<ATMAX <<")\n";
cout<<"\n The DEMAX variable, the max die roll, is set at ("<<DEMAX <<")\n";
cout<<"\n Enter the number of attacking units. \n";
cin>> ATINITNUM;
cout<<"\n Enter the number of defending units. \n";
cin>> DEINITNUM;
cin.get ();
cout<<"\n You have entered (" <<ATINITNUM <<") Attacking Units, and (" << DEINITNUM <<") Defending Units.\n";
cin.get ();
}
int DICENUMBERS()
{
COMPARISONAT = ATINITNUM/DEINITNUM;
COMPARISONDE = DEINITNUM/ATINITNUM;
cout<<"\n The Attacking Force Divided by the Defending Force returns("<<COMPARISONAT<<")\n";
cout<<"\n The Defending Force Divided by the Attacking Force returns("<<COMPARISONDE<<")\n";
if (COMPARISONAT>COMPARISONDE)
{
if (COMPARISONAT >=2)
{
if (COMPARISONAT <3)
{
ATADDDICE = 1;
}
else
{
ATADDDICE = 2;
}
}
else
{
ATADDDICE = 0;
}
}
else
{if (COMPARISONDE >=2)
{
if (COMPARISONDE <3)
{
DEADDDICE = 1;
}
else
{
DEADDDICE = 2;
}
}
else
{
DEADDDICE = 0;
}
}
cout<<"The Attacking force gets ("<<ATADDDICE<<") Extra Dice for this round!\n";
cout<<"The Defending force gets ("<<DEADDDICE<<") Extra Dice for this round!\n";
}
int ATTACKERROLLS() // this is the program that rolls the correct no of dice and pops them in an array.
{
ATDICE = 3+ATADDDICE;
cout<<"The Attacker will get a total of ("<<ATDICE<<")x("<<ATMAX<<")Sided Dice for this round.\n";
int ATTACKERARRAY[ATDICE]; // This sets the size of the Attacker array equal to the Attacker dice.
int p;
int q;
const int LOW=1;
const int ATHIGH = ATMAX;
for ( p=0; p<ATDICE; p++ )
{
cin.get ();
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
ATTACKERARRAY[p] = rand() % (ATHIGH-LOW+1) +LOW;
q=(p+1);
cout<<"Roll number "<<q<<" is "<<ATTACKERARRAY[p]<<" ! \n";
}
}
int DEFENDERROLLS() // this is the program that rolls the correct no of dice and pops them in an array.
{
DEDICE = 3+DEADDDICE;
cout<<"The Defender will get a total of ("<<DEDICE<<")x("<<DEMAX<<") Sided Dice for this round.\n";
int DEFENDERARRAY[DEDICE]; // This sets the size of the defender array equal to the defender dice.
int x;
int y;
const int LOW=1;
const int DEHIGH = DEMAX;
for ( x=0; x<DEDICE; x++ )
{
cin.get ();
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
DEFENDERARRAY[x] = rand() % (DEHIGH-LOW+1) +LOW;
y=(x+1);
cout<<"Roll number "<<y<<" is "<<DEFENDERARRAY[x]<<" ! \n";
}
}
int main ()
{
cout<<"Colony Dice rolling program, version Beta 0.3\n\n";
ROUNDNUM = 1;
STARTUP();
DICENUMBERS();
cout<<"\n Battle Commences!!, Round ("<<ROUNDNUM<<")\n";
ATTACKERROLLS();
cin.get ();
DEFENDERROLLS();
cin.get ();
}