Jump to content
  • Advertisement
Sign in to follow this  
ARC inc

RPG Battle System

This topic is 3051 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anyone know where I can find a decent RPG Battle system that I can take a look at to improve mine? Because mine doesn't work properly this should be in C++

Share this post


Link to post
Share on other sites
Advertisement
here is my battle system but it always says that my player does 0 damage etc.

	int x;


x = rand() %5;

if(x == 0)
{
c.str = c.dmg + 1;
m.health -= c.dmg;
cout << "Your attack deals\n" << c.dmg << "Damage\n";
}
if(x == 1)
{
c.str = c.dmg - 1;
m.health -= c.dmg;
cout << "Your attack deals\n" << c.dmg << "Damage\n";
}
if(x == 2)
{
c.str = c.dmg / 2;
m.health -= c.dmg;
cout << "Your attack deals\n" << c.dmg << "Damage\n";
}
if(x == 3)
{
c.str = c.dmg * 3;
m.health -= c.dmg;
cout << "Your attack deals\n" << c.dmg << "Damage\n";
}
if(x == 4)
{
c.dmg = 0;
cout << "Monster Blocked your attack!\n";
}
if(m.health <=0)
{
cout << "You killed the monster!!\n";
}
else
{
cout << "Leaving the monster with\n" << m.health << "Health Points\n" << m.monster_name << "Will now attack you!\n";

int y;
y = rand() % 5;
if (y == 0)
{
m.str = m.dmg;
}
else if (y == 1)
{
m.str = m.dmg - 1;
}
else if (y == 2)
{
m.str = m.dmg + 1;
}
else if (y == 3)
{
m.str = m.dmg*2;
}
else if (y == 4)
{
m.dmg = 0;
cout << "Miss\n" << endl;
}
c.health = c.health - m.dmg;
if(c.health <0)
{
cout << "Game Over\n";
}
}
monster_load.close();
load_account.close();


it also never lets the monster attack, it just skips over that part. Any ideas?

Share this post


Link to post
Share on other sites
Also
Quote:
x = rand() %5;
where rand() is [0, 1), which means modulo 5 will always return 0. I think you are wanting rand() * 5 which will give [0, 5) as a result.

Share this post


Link to post
Share on other sites
rand() returns an integer between 0 and RAND_MAX, so rand() % 5 returns an integer between 0 and 4 inclusive. It is correct, although not a perfect distribution.

Share this post


Link to post
Share on other sites
Sorry fellas didn't work I did get the monster to do damage an it's giving me weird amount of damage an def not showing up so I am thinking I did something wrong with code somewhere along the line idk though

Share this post


Link to post
Share on other sites
Are you seeding the random number generator?


#include <time.h>
int x;

srand(time(NULL)); //Seed the random number generator, or you'll always get the same number.
x = rand() % 5;
//The rest of your code.



I think you only need to seed it once, so probably in your main() function and not in your battle function.

Share this post


Link to post
Share on other sites
for some reason my rand keeps on landing on the same rand, and never changes any ideas?

srand(time_t(NULL));
int hit_miss;
hit_miss = rand() %4;

if(hit_miss == 0)
{
c.dmg = c.str+1;
m.health -=c.str;
cout << "(rand 0) You do\n" << c.dmg << "Damage Leaving\n" << m.monster_name << "With\n" << m.health << "Health points\n";
}

else if(hit_miss == 1)
{
c.dmg = c.str+1;
m.health -=c.str;
cout << "(rand 1)You do\n" << c.dmg << "Damage Leaving\n" << m.monster_name << "With\n" << m.health << "Health points\n";
}

else if(hit_miss == 2)
{
c.dmg = c.str*2;
m.health -=c.str;
cout << "(rand 2)You do\n" << c.dmg << "Damage Leaving\n" << m.monster_name << "With\n" << m.health << "Health points\n";
}
else if(hit_miss == 3)
{
c.dmg = 0;
cout << "(rand 3)You miss\n";
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!