C++ code:
#include <iostream>
#include <cmath>
#include <ctime>
#include <Windows.h>
#include <string>
#include <algorithm>
#include "enemys.h"
using namespace std;
int GuardAttack(int x, int b[])
{
int GuardChoose = rand() % 4;
if (GuardChoose == 0)
{
cout << "The Guard ordered you to co-operate!" << endl;
Sleep(1000);
} else if (GuardChoose == 1)
{
cout << "The Guard fumbled around for his weapons!" << endl;
Sleep(1000);
} else if (GuardChoose == 2)
{
int GCAttack = rand() % 2;
if (GCAttack = 0)
{
cout << "The Guard swung his bat!" << endl;
Sleep(750);
x = b[0];
int iRndDmg = rand() % 3 + 8;
b[0] -= (iRndDmg = b[3]);
cout << x - b[0] << " damage to Tom!" << endl;
Sleep(750);
} else if (GCAttack = 1)
{
cout << "The Guard shocked you with his tazer!" << endl;
Sleep(750);
x = b[0];
int iRndDmg1 = rand() % 6 + 15;
b[0] -= (iRndDmg1 - b[3]);
cout << x - b[0] << " damage to Tom!" << endl;
Sleep(750);
}
} else if (GuardChoose == 3)
{
cout << "The Guard charged at you!" << endl;
Sleep(750);
x = b[0];
int iRndDmg2 = rand() % 16 + 5;
b[0] -= iRndDmg2;
cout << x - b[0] << " damage to Tom!" << endl;
Sleep(750);
}
return 0;
}
bool cmp_fn(int a, int b)
{
return a > b;
}
int FirstGuard(int a, int b[])
{
if (b[0] > 999)
{
b[0] = 999;
}
if (b[1] > 99)
{
b[1] = 99;
}
system("cls");
system("color 0f");
time_t (t);
time(&t);
srand(t);
int GuardsHealth = 75 + a;
int GuardsSpeed = 8;
int iBattleLoop = 0;
do
{
system("cls");
GuardsSpeed = rand() % 3 + 9;
int SpeedCmp [] = {b[4], GuardsSpeed};
int elements = sizeof(SpeedCmp) / sizeof(SpeedCmp[0]);
sort(SpeedCmp, SpeedCmp + elements, cmp_fn);
cout << "___________" << endl;
cout << "| Guard |" << endl;
cout << "|---------|" << endl;
if (GuardsHealth >= 100)
{
cout << "|HP:" << GuardsHealth << " |" << endl;
} else
{
cout << "|HP:" << GuardsHealth << " |" << endl;
}
cout << "|_________|" << endl;
cout << endl;
cout << endl;
cout << "__________" << endl;
cout << "| Tom |" << endl;
cout << "|--------|" << endl;
if (b[0] >= 100)
{
cout << "|HP:" << b[0] << " |" << endl;
} else
{
cout << "|HP:" << b[0] << " |" << endl;
}
cout << "|PP:" << b[1] << " |" << endl;
cout << "|________|" << endl;
cout << "a = attack" << endl;
cout << "s = defend" << endl;
cout << "d = items" << endl;
cout << "w = power" << endl;
string sUserInput;
cin >> sUserInput;
if (sUserInput == "a")
{
int x = 0;
int c, d = 0;
if (SpeedCmp[0] == b[4])
{
cout << "Tom attacks!" << endl;
Sleep(750);
x = GuardsHealth;
GuardsHealth -= b[2];
cout << x - GuardsHealth << " damage to Guard!" << endl;
Sleep(750);
c = 1;
} else if (SpeedCmp[0] == GuardsSpeed)
{
GuardAttack(x, b);
d = 1;
}
if (c == 1 && d != 1)
{
GuardAttack(x, b);
} else if (d == 1 && c != 1)
{
cout << "Tom attacks!" << endl;
Sleep(750);
x = GuardsHealth;
GuardsHealth -= b[2];
cout << x - GuardsHealth << " damage to Guard!" << endl;
Sleep(750);
}
} else if (sUserInput == "s")
{
int x = 0;
int c, d = 0;
if (SpeedCmp[0] == b[4])
{
cout << "Tom defends!" << endl;
Sleep(750);
b[3] += 10;
c = 1;
} else if (SpeedCmp[0] == GuardsSpeed)
{
GuardAttack(x, b);
d = 1;
}
if (c == 1 && d != 1)
{
GuardAttack(x, b);
b[3] -= 10;
} else if (d == 1 && c != 1)
{
cout << "Tom defends!" << endl;
Sleep(750);
}
} else if (sUserInput == "d")
{
cout << "Coming soon!" << endl;
} else if (sUserInput == "w")
{
}
}while(iBattleLoop < 1);
return 0;
}