- Code: Select all
#include <cstdlib>
#include <iostream>
using namespace std;
class CSoldiers {
public:
int m_iCount;
char * m_szType;
//constructor
CSoldiers(int iCount, const char* szType) {
m_iCount=iCount;
m_szType=new char[strlen(szType)+1];
strcpy(m_szType, szType);
}
//deconstructor
~CSoldiers() {
delete [] m_szType;
}
//killer
void kill(int iDice) {
int lost = rand() % iDice;
if (lost > m_iCount) lost=m_iCount;
m_iCount -= lost;
cout << "lost " << lost << " " << m_szType;
}
//status
void status( void ) {
cout << m_iCount << " " << m_szType;
}
};
int main(int argc, char* argv[]) {
CSoldiers * army[5]; //our army has 5 types of soldiers:
army[0]= new CSoldiers(500, "Irish...");
army[1]= new CSoldiers(1000, "footman");
army[2]= new CSoldiers(100, "welch bowmen");
army[3]= new CSoldiers(1000, "french conscripts");
army[4]= new CSoldiers(1, "Mel Gibson");
int dices[] = { 100, 1000, 50, 10000, 2};
srand ( time(NULL) );
cout << "\nYou are the leader of the scots rebelling against england.";
cout << "\nYour army constists of\n";
for (int x=0;x<5;x++) {
army[x]->status();
cout << "\n";
}
cout << "\n===========================================\n";
int battles=-1;
while (army[4]->m_iCount!=0) {
cout << "\nYou did some fighting and \n";
for (int x=0;x<5;x++) {
army[x]->kill( dices[x] );
cout << "\n";
}
battles++;
if (army[4]->m_iCount!=0) cout << "\nYou defeated the army!!!!\n";
}
cout << "\nOh no, you lost Mel Gibson!";
cout << "\nThe scots lasted " << battles << " battles";
cout << "\nYou lost you twat";
system("pause");
return 1;
}














