ok, i'll try getting rid of the system stuff, but then how do I make the screen clear(system("cls")) and how do i make the program wait for any key(system("PAUSE")). I'll post my code:
Code:
#include <iostream.h>
#include <stdlib.h>
#include <iomanip.h>
#include <string>
int choice;
int quantity;
string text;
class sector
{
private:
unsigned int credits;
unsigned int power;
unsigned int metal;
unsigned int crew;
unsigned int jets;
unsigned int starships;
unsigned int days;
unsigned int jettime[2];
unsigned int startime[2];
unsigned int minetime[2];
unsigned int traintime[2];
public:
sector();
int timer();
int retrieve(int);
int attack(int,int);
int build();
int mine();
int train();
int stats();
int next();
};
sector::sector() //Constructor
{
credits = 1000000;
power = 100;
metal = 100;
crew = 50;
jets = 0;
starships = 1;
days = 1;
jettime[0] = 0;
startime[0] = 0;
minetime[0] = 0;
traintime[0] = 0;
jettime[1] = 0;
startime[1] = 0;
minetime[1] = 0;
traintime[1] = 0;
}
int sector::timer() //TIMER
{
system("cls");
days++;
power = power + 20;
if (jettime[0] == days)
{
jets = jets + jettime[1];
cout<<"Alas, your jets are complete!"<<endl;
jettime[0] = 0;
jettime[1] = 0;
}
if (startime[0] == days)
{
starships = starships + startime[1];
cout<<"Alas, your StarShips are complete!"<<endl;
startime[0] = 0;
startime[1] = 0;
}
if (minetime[0] == days)
{
metal = metal + (minetime[1]* 10);
cout<<"Alas, your mining team has returned!"<<endl;
minetime[0] = 0;
minetime[1] = 0;
}
if (traintime[0] == days)
{
crew = crew + traintime[1];
cout<<"Alas, your crew training is complete!"<<endl;
traintime[0] = 0;
traintime[1] = 0;
}
system("PAUSE");
if (days == 10)
{
text = "Scouts have reported an attack on the asteroid.\n5 jets and 1 StarShip!";
if (attack(5,1) == 1)
{
text = "PPP";
return 0;
}
else
return 0;
}
else if (days == 25)
{
text = "Scouts have reported an attack on the asteroid.\n12 jets and 3 StarShips!";
attack(12,3);
return 0;
}
else if (days == 30)
{
text = "Sir! Intruders are attacking the outpost. If we don't do something quick,\nWe're done for!\n30 jets and 8 StarShips!";
attack(30,8);
return 0;
}
else if (days == 42)
{
text = "OOO";
return 0;
}
else
{return 0;}
return 0;
}
int sector::attack(int a,int b)
{
int quantjet;
int quantstar;
cout<<"\n\n"<<text<<endl;
do
{
cout<<"\n\nHow many Jets will you send? ";
cin>>quantjet;
cin.ignore();
}while (quantjet > jets);
jets = jets - quantjet;
do
{
cout<<"\n\nHow many StarShips will you send? ";
cin>>quantstar;
cin.ignore();
}while (quantstar > starships);
starships = starships - quantstar;
if (quantjet > a && quantstar > b)
{
cout<<"\n\n"<<setw(10)<<"You are victorious!\n"<<endl;
system("PAUSE");
return 0;
}
else if (quantjet == a && quantstar == b)
{
cout<<"\n\nThat was suicidal!GAME OVER!!\n"<<endl;
system("PAUSE");
return 1;
}
else
{
cout<<"\n\nYou lost!GAME OVER!!\n"<<endl;
system("PAUSE");
return 1;
}
}
int sector::build() //BUILD
{
if ((jettime[1] != 0) || (startime[1] != 0))
{return 0;}
else
quantity = 0;
int cred;
int pow;
int met;
int cre;
cred = 0;
pow = 0;
met = 0;
cre = 0;
system("cls");
cout<<"Credits: "<<retrieve(1)<<setw(15)<<"Power: "<<retrieve(2)<<setw(15)<<"Metal: "<<retrieve(3)<<setw(15)<<"Day "<<retrieve(7)<<endl;
cout<<"Crew: "<<retrieve(4)<<setw(15)<<"Jets: "<<retrieve(5)<<setw(15)<<"Starships: "<<retrieve(6)<<endl;
cout<<"\nWhat are your building orders, Admiral?"<<endl;
cout<<"\n[1] Jets"
<<"\n[2] StarShips"
<<"\n[0] Back\n"<<endl;
cout<<"Order: ";
cin>>choice;
cin.ignore();
if (choice == 1)
{
cout<<"\nThis costs 100 credits, 10 power, 10 metal, and 2 crew. Quantity: ";
cin>>quantity;
cin.ignore();
cred = quantity * 100;
pow = quantity * 10;
met = quantity * 10;
cre = quantity * 2;
if ((retrieve(1) >= cred) && (retrieve(2) >= pow) && (retrieve(3) >= met) && (retrieve(4) >= cre))
{
cout<<"\n\n SUCCESS! Your ships will be built in "<<(quantity * 1)<<" days.\n"<<endl;
system("PAUSE");
credits = credits - cred;
power = power - pow;
metal = metal - met;
crew = crew - cre;
jettime[0] = days + (quantity * 1);
jettime[1] = quantity;
return 0;
}
else
{
cout<<"\n\nNOT ENOUGH SUPPLIES! Cannot build.\n"<<endl;
system("PAUSE");
return 0;
}
}
else if (choice == 2)
{
cout<<"\nThis costs 1000 credits, 50 power, 50 metal, and 8 crew. Quantity: ";
cin>>quantity;
cin.ignore();
cred = quantity * 1000;
pow = quantity * 50;
met = quantity * 50;
cre = quantity * 8;
if ((retrieve(1) >= cred) && (retrieve(2) >= pow) && (retrieve(3) >= met) && (retrieve(4) >= cre))
{
cout<<"\n\n SUCCESS! Your ships will be built in "<<(quantity * 5)<<" days.\n"<<endl;
system("PAUSE");
credits = credits - cred;
power = power - pow;
metal = metal - met;
crew = crew - cre;
startime[0] = days + (quantity * 5);
startime[1] = quantity;
return 0;
}
else
{
cout<<"\n\nNOT ENOUGH SUPPLIES! Cannot build.\n"<<endl;
system("PAUSE");
return 0;
}
}
else
{return 0;}
}
int sector::mine()
{
if (minetime[1] != 0)
{return 0;}
else
quantity = 0;
system("cls");
cout<<"Credits: "<<retrieve(1)<<setw(15)<<"Power: "<<retrieve(2)<<setw(15)<<"Metal: "<<retrieve(3)<<setw(15)<<"Day "<<retrieve(7)<<endl;
cout<<"Crew: "<<retrieve(4)<<setw(15)<<"Jets: "<<retrieve(5)<<setw(15)<<"Starships: "<<retrieve(6)<<endl;
cout<<"\n\nShall we mine, Admiral?"<<endl;
cout<<"\n How many crew members will you send? ";
cin>>quantity;
cin.ignore();
if (quantity > retrieve(4))
{
cout<<"\n\nNOT ENOUGH CREW! Cannot send.\n"<<endl;
system("PAUSE");
return 0;
}
else if (quantity == 0)
{return 0;}
else
{
cout<<"\n\nSUCCESS! "<<quantity<<" crew members have been sent to mine.\n"
<<"They will be back in 4 days.\n"<<endl;
system("PAUSE");
crew = crew - quantity;
minetime[0] = days + 4;
minetime[1] = quantity;
return 0;
}
}
int sector::train()
{
if (traintime[1] != 0)
{return 0;}
else
quantity = 0;
system("cls");
cout<<"Credits: "<<retrieve(1)<<setw(15)<<"Power: "<<retrieve(2)<<setw(15)<<"Metal: "<<retrieve(3)<<setw(15)<<"Day "<<retrieve(7)<<endl;
cout<<"Crew: "<<retrieve(4)<<setw(15)<<"Jets: "<<retrieve(5)<<setw(15)<<"Starships: "<<retrieve(6)<<endl;
cout<<"\n\nShall we train the crew, Admiral?"<<endl;
cout<<"\n How many men do you want to train into crew($10 each)? ";
cin>>quantity;
cin.ignore();
if ((quantity * 10) > retrieve(1))
{
cout<<"\n\nNOT ENOUGH CREDITS! Cannot train.\n"<<endl;
system("PAUSE");
return 0;
}
else if (quantity == 0)
{return 0;}
else
{
cout<<"\n\nSUCCESS! "<<quantity<<" crew members are being trained.\n"
<<"They will be ready in "<<(quantity / 10)<<" days."<<endl;
system("PAUSE");
credits = credits - (quantity * 10);
traintime[0] = days + (quantity / 10);
traintime[1] = quantity;
return 0;
}
}
int sector::stats()
{
system("cls");
cout<<"Credits: "<<retrieve(1)<<setw(15)<<"Power: "<<retrieve(2)<<setw(15)<<"Metal: "<<retrieve(3)<<setw(15)<<"Day "<<retrieve(7)<<endl;
cout<<"Crew: "<<retrieve(4)<<setw(15)<<"Jets: "<<retrieve(5)<<setw(15)<<"Starships: "<<retrieve(6)<<endl;
cout<<"\n\n Jets in Production | StarShips in Production | Miners Gone | Crew in Training"<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"#of| "<<setw(5)<<jettime[1]<<setw(20)<<startime[1]<<setw(20)<<minetime[1]<<setw(20)<<traintime[1]<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"Day| "<<setw(5)<<jettime[0]<<setw(20)<<startime[0]<<setw(20)<<minetime[0]<<setw(20)<<traintime[0]<<endl;
cout<<"-------------------------------------------------------------------------------"<<endl<<endl<<endl;
cout<<"\n\n[1]Cancel order"
<<"\n[0]Back\n"<<endl;
cin>>choice;
cin.ignore();
if (choice == 1)
{
cout<<"\n\nWhich order?"<<endl;
cout<<"\n[1]Jets"
<<"\n[2]StarShips"
<<"\n[3]Crew"
<<"\n[0]Back\n"<<endl;
choice = 0;
cin>>choice;
if (choice == 1)
{
jettime[0] = 0;
jettime[1] = 0;
return 0;
}
else if (choice == 2)
{
startime[0] = 0;
startime[1] = 0;
return 0;
}
else if (choice == 3)
{
traintime[0] = 0;
traintime[1] = 0;
return 0;
}
else
{
return 0;
}
}
else
{
return 0;
}
}
int sector::retrieve(int a)
{
switch (a)
{
case 1:
return (credits);
break;
case 2:
return (power);
break;
case 3:
return (metal);
break;
case 4:
return (crew);
break;
case 5:
return (jets);
break;
case 6:
return (starships);
break;
case 7:
return (days);
break;
default:
break;
}
}
int main()
{
cout<<setw(30)<<"Defender 1.0"
<<"\nBy Adam Lesinski"<<endl;
cout<<"\n[1]Play"
<<"\n[0]Quit\n"<<endl;
cin>>choice;
cin.ignore();
if (choice == 0)
return 0;
else if (choice != 0 && choice != 1)
return 0;
else
system("cls");
string name; //define name
sector account; //define object
cout<<"Good day, Admiral... My apologies, what was your name again?"<<endl;
cin>>name;
cin.ignore();
cout<<"\nRight! Welcome to this sector Admiral "<<name<<"."
<<"\nI am Grand Admiral Drugor of the Authority. "
<<"I have called you here this evening\nto discuss your defection to the Authority. "
<<"It is very rare that defects such asyourself maintain their previous ranks, but you are an "
<<"exception. Your skill is\namazing!\n\nI want you to protect an outpost situated in the Senex sector,\norbiting the "
<<"planet Kraul. We cannot spare any ships, because of the pressing\nwar, but I will supply you with a limited amount "
<<"of ressources to begin with,\nalong with one hundred thousand credits. The rest you will have to obtain on\nyour "
<<"own. My scouts have reported that a large asteroid full of raw metal ore\ntravels in a loose orbit around Kraul. "
<<"You could harvest some materials from\nthere. I trust a man with your talent could accomplish this quite easily."
<<"\nI want a full report 6 standard weeks from your arrival at the Senex sector.\nGood luck!\n"<<endl;
system("PAUSE");
do {
system("cls");
cout<<"Credits: "<<account.retrieve(1)<<setw(15)<<"Power: "<<account.retrieve(2)<<setw(15)<<"Metal: "<<account.retrieve(3)<<setw(15)<<"Day "<<account.retrieve(7)<<endl;
cout<<"Crew: "<<account.retrieve(4)<<setw(15)<<"Jets: "<<account.retrieve(5)<<setw(15)<<"Starships: "<<account.retrieve(6)<<endl;
cout<<"\nWelcome Admiral "<<name<<endl;
cout<<"------"
<<"\nOrders"
<<"\n------"<<endl;
cout<<"\n[1]Build"
<<"\n[2]Mine"
<<"\n[3]Train"
<<"\n[4]Stats"
<<"\n[5]Next"
<<"\n[0]Quit"<<endl;
cout<<"\nOrder: ";
cin>>choice;
cin.ignore();
switch (choice)
{
case 0:
return 0;
break;
case 1:
account.build();
break;
case 2:
account.mine();
break;
case 3:
account.train();
break;
case 4:
account.stats();
break;
case 5:
account.timer();
if (text == "OOO")
{
system("cls");
cout<<"\n\n\n"<<setw(10)<<"Well done Admiral "<<name<<". You have proven yourself well.\nCan I Interest you in a position among my battalion..."<<endl;
cout<<"\n"<<setw(20)<<"YOU ARE VICTORIOUS!!!!\n\n\n";
system("PAUSE");
return 0;
}
else if (text == "PPP")
{
system("cls");
cout<<"\n\n\n"<<setw(10)<<"You disappoint me... 'Private' "<<name<<"!"<<endl;
cout<<"\n"<<setw(20)<<"GAME OVER!!!!!!!!\n\n\n";
system("PAUSE");
return 0;
}
else
break;
default:
break;
}
}while (choice != 99);
return 0;
}