Beaverbutt8
Programmer
Hey guys,
I've been doing c++ for a few weeks now, and i have started to program a game (text game) called "Zalador". Well, i have written a function for the hero guy to fight an enemy, but i need a way to loop it until one of them dies, Here's the source code.
#include <iostream.h>
#include <cstdlib>
#include <ctime>
void fight();
void fight()
{
int hit(int health);
int hite(int healthe);
srand(time(0));
int randomNumber = rand();
int rnd = (randomNumber % 3) + 1;
int rnde = (randomNumber % 3) + 1;
//your health
int health = 80;
//enemy's health
int healthe = 80;
//tell
if ( rnd == 2 )
{
health = hit(health);
cout << "The monster takes a whack at you, and gets you -- Health: " << health << "\n\n";
}
else
{
cout << "The monster takes a whack at you, and misses -- Health: " << health << endl;
}
if ( rnde == 1 )
{
healthe = hite(healthe);
cout << "You strike the monster -- Monster Health: " << healthe << "\n\n";
}
else
{
cout << "You try to strike the monster, but miss -- MonsterHealth: " << healthe << endl;
}
if ( health == 0 )
{
cout << "Sadly, you are killed by the monster" << endl << endl << endl;
cout << " GAME OVER " << endl;
exit (0);
}
else
{
}
if ( healthe == 0 )
{
cout << "You have slain the monster!!!! Well done!" << endl;
}
else
{
}
system ("PAUSE");
}
inline int hit(int health)
{
return (health - 10);
}
inline int hite(int healthe)
{
return (healthe - 10);
}
As i said, i need a way to keep it going until one of them dies. I would greatly apprecaite it if someone could help me.
Thanks
Mike
I've been doing c++ for a few weeks now, and i have started to program a game (text game) called "Zalador". Well, i have written a function for the hero guy to fight an enemy, but i need a way to loop it until one of them dies, Here's the source code.
#include <iostream.h>
#include <cstdlib>
#include <ctime>
void fight();
void fight()
{
int hit(int health);
int hite(int healthe);
srand(time(0));
int randomNumber = rand();
int rnd = (randomNumber % 3) + 1;
int rnde = (randomNumber % 3) + 1;
//your health
int health = 80;
//enemy's health
int healthe = 80;
//tell
if ( rnd == 2 )
{
health = hit(health);
cout << "The monster takes a whack at you, and gets you -- Health: " << health << "\n\n";
}
else
{
cout << "The monster takes a whack at you, and misses -- Health: " << health << endl;
}
if ( rnde == 1 )
{
healthe = hite(healthe);
cout << "You strike the monster -- Monster Health: " << healthe << "\n\n";
}
else
{
cout << "You try to strike the monster, but miss -- MonsterHealth: " << healthe << endl;
}
if ( health == 0 )
{
cout << "Sadly, you are killed by the monster" << endl << endl << endl;
cout << " GAME OVER " << endl;
exit (0);
}
else
{
}
if ( healthe == 0 )
{
cout << "You have slain the monster!!!! Well done!" << endl;
}
else
{
}
system ("PAUSE");
}
inline int hit(int health)
{
return (health - 10);
}
inline int hite(int healthe)
{
return (healthe - 10);
}
As i said, i need a way to keep it going until one of them dies. I would greatly apprecaite it if someone could help me.
Thanks
Mike