Combat simulator game problem.

okay forums, i need your help once again. I have a few snippets of codes, one is a function to access the speed of a player.

Player.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  void Player::init(int level, int health, int defense, int speed, int damage, int attack, int stamina, int mana, int gold, int experience)
{
	_level = level;
	_health = health;
	_defense = defense;
	_speed = speed;
	_damage = damage;
	_attack = attack;
	_stamina = stamina;
	_mana = mana;
	_gold = gold;
	_experience = experience;
}

int Player::accessSpeed()
{
	return _speed;
}



Combat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include "Combat.h"
#include "Player.h"
#include "Monster.h"

using namespace std;



Combat::Combat()
{
}


bool Combat::runCombat()
{
	Player kyle;
	Monster bigger;
	int speed1;

	kyle.init(1, 10, 10, 3, 5, 6, 15, 12, 500, 1000);
	bigger.init(1, 10, 10, 2, 5, 6, 15, 12, 500, 1000);
	
	kyle.accessSpeed();

	


	char turn = 'a';



}

void Combat::pickAction()
{
	int actionChoice;

	cout << "please pick an action!" << endl;
	cout << "1). Attack!" << endl;
	cout << "2). Cast Spell!" << endl;

	cin >> actionChoice;


	if (actionChoice == 1) {
		makeAttack();
	} 
	else if (actionChoice == 2) {
		//Spell function
	}
	else {
		//Need to make this loop for invalid choice.
		cout << "You cannot do that now!" << endl;
	}

}

void Combat::makeAttack()
{
	
}

int Combat::checkSpeed(int crea1, int crea2)
{
	if (crea1 > crea2) {
		return 1;
	}
	else {
		return 2;
	}
}


the main hurdle i have right now is access player class and monster class and comparing them so i can determine which one should act first. but when i type:

 
kyle.accessSpeed() = speed1;


it give me an error relating to lvalues. Thanks in advance.

also if you're wondering, i'm not even in my main() function yet, trying to get a basic version of runCombat going first.
Last edited on
The lvalues error means that functions return a value to the left side, not the right, so to access the speed you would type;

1
2
3
speed = kyle.accessSpeed();
// variable = function();
// variable = value; 

Last edited on
If you want to be able to get kyle's speed, and you want to be able to set it too, then make the _speed member public and access it directly:
kyle.speed = speed1;
and comparing them

You need to use ==, not just a single =
Topic archived. No new replies allowed.