Jump to content
  • Advertisement
Sign in to follow this  
andyhall89

Help with an arena game

This topic is 2612 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

Hi everyone, i'm building a small arena game where the player fights enemies etc. It's just for personal interest really. Anywhere here's all the code:


// Arena.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
#include "time.h"
#include "string"

using namespace std;


int PlayerHealth = 40;
int PlayerDamage = ((rand() % 30) + 1);
int PlayerArmour = 10;
int PlayerExp = 0;
int PlayerLevel = 1;


class Enemy
{
public:
Enemy(int health = (PlayerLevel * (PlayerHealth - PlayerArmour)) * 0.75, int damage = ((rand() % 20) + 1), int exp = );
void virtual enemyAttack() const;
int virtual enemyIsAttacked() const;
void virtual enemyDied() const;
int m_Health;
int m_Damage;
int m_Exp;

private:

};

Enemy::Enemy(int health, int damage, int exp):
m_Health(health),
m_Damage(damage),
m_Exp(exp)
{}

void Enemy::enemyAttack() const
{
int PlayerDamage = (m_Damage % PlayerArmour + 1);
PlayerHealth = PlayerHealth - PlayerDamage;
--PlayerArmour;
}

int Enemy::enemyIsAttacked() const
{
m_Health - PlayerDamage;

if (m_Health <= 0)
{
PlayerWon();
}

return m_Exp;
}

void Enemy::enemyDied() const
{
// to do
}


void PlayerWon()
{
cout << "\n\nCongratulations! You've defeated an enemy!";
cout << "\n\nYou gained: " << m_Exp << " experience!";
PlayerExp + m_Exp;
while (PlayerExp >= 100){
PlayerExp - 100;
++PlayerLevel;
}


void _tmain(int argc, _TCHAR* argv[])
{
srand(time(0));

string playerName;

cout << "\n\nWelcome to the Arena!";
cout << "\n\nHere you will battle against the mightiest of foes!";
cout << "\n\nPlease tell us your name, mighty warrior: ";

cin >> playerName;

cout << "\n\nExcellent, a fine name for such a noble warrior!";

}


A lot of it, especially main, isn't fully finished. But i'm getting a problem where some of the functions regarding the enemy class aren't able to reference the exp, health and damage ints of the enemy. What am i doing wrong? The errors are something along the lines of 'm_Exp is undefined' or 'This non-static object is not modifiable'. What am i doing wrong?

Thanks.

Share this post


Link to post
Share on other sites
Advertisement
First of all: write the following around your code (but without spaces):
[ c o d e ]
[ / c o d e ]

I think the problem is that you wrote PlayerWon instead of Enemy::PlayerWon.

Share this post


Link to post
Share on other sites

First of all: write the following around your code (but without spaces):
[ c o d e ]
[ / c o d e ]

I think the problem is that you wrote PlayerWon instead of Enemy::PlayerWon.


Oh so i need to make playerWon() a member of the Enemy class? What happens if i have a function outsie of Enemy but want to access some of the data inside there?

Thanks.

Share this post


Link to post
Share on other sites
You should have something like this:

Enemy mEnemy;

Then you can access its data:

mEnemy.m_Exp;

For calling e.g. enemyAttack from _tmain you will also need to do this:

mEnemy.enemyAttack()

Share this post


Link to post
Share on other sites
Oh okay, thanks :).

Also, when an enemy is killed, what do you think would be the best way to go about that? Would it to literally call up a new enemy as you just described?

Share this post


Link to post
Share on other sites
I can't really help you with it, because you will handle the death of an ememy differently in some situatations e.g. multiple enemies or not.

If you want the enemy to respawn when he dies then you can continue working with mEnemy.
You just have to recalculate its health and things like that and then you can fight it again.


I have noticed that u are using a class, but all the members of the class are public.
I suggest to work with a struct, because it has public members by default.

Share this post


Link to post
Share on other sites

I can't really help you with it, because you will handle the death of an ememy differently in some situatations e.g. multiple enemies or not.

If you want the enemy to respawn when he dies then you can continue working with mEnemy.
You just have to recalculate its health and things like that and then you can fight it again.


I have noticed that u are using a class, but all the members of the class are public.
I suggest to work with a struct, because it has public members by default.


Ah right okay. You see you can tell i'm new because i don't actually know what a struct is lol. :)

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!