I'm back from slaying errors and only 23 deadly errors remain.

Pages: 12
shit, forgot i renamed the files to equipment but i'll repost to help.

Equipment.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#pragma once
#include <iostream>
#include <ctime>
#include <string>
#include "Combat.h"
#include "Combatant.h"
#include "Scenario.h"
#include "Dice.h"


using namespace std;

class Weapon
{
public:
	Weapon(string name, int attack, int damage);

	string _name;
	int _damageDice;
	int _attackDice;
};



Equipment.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <ctime>
#include <string>
#include "Combat.h"
#include "Combatant.h"
#include "Scenario.h"
#include "Dice.h"
#include "Equipment.h"

using namespace std;


Weapon::Weapon(string name, int attack, int damage)
{
	name = _name;
	damage = _damageDice;
	attack = _attackDice;
}

I see what is going wrong - you never assigned anything to _damageDice or _attackDice. You need to do _damageDice = damage; and _attackDice = attack;. You had it flipped the wrong way. When you never assign a value to an int but then try to read what its value is, you always get a wacky value. Remember you list what you want to assign to first, and put what you want to assign to it after the equals sign. You also need to flip around your name variable. That should fix the error with the uniform_int_distribution. Let us know what the next error is.
but i am assigning them values ( or am i not understanding hat you're saying). in the Weapon "Club", im assigning those int variables 4 and 10 respectively, but they go into the weapon func as that and come out as really high numbers.


from Combatant.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
void Combatant::attack(Combatant target)
{
	//Initialize Weapon
	Weapon club("Club", 4, 10);

	int aTotal;
	int dTotal;
	int iTotal;

	//Roll dice for Attack and Damage "ranges"
	Dice ATTACK;
	Dice DAMAGE;

	int attackDiceResults = ATTACK.diceRoller(club._attackDice);
	int damageDiceResults = DAMAGE.diceRoller(club._damageDice);

	//Add dice results with player stats.
	aTotal = _attack + attackDiceResults;
	dTotal = _damage + damageDiceResults;

	if (aTotal >= target._defense) {
		iTotal = dTotal - 5;
		target._health = iTotal;
		cout << "You have been dealt " << iTotal << "damage to!" << endl;
		target._health -= iTotal;
	}
	else {
		cout << _name << "has missed!" << endl;
	}
}



edit!!! nevermind, i reread what you were saying and re looked at my other situations i did that kind of func and switch the variables. it now works perfectly. thank you so much.
Last edited on
You're welcome. Good luck with your future projects.
haha, thanks, I've ran into a new problem now though. I'm trying to have my program compute whether a target is alive or dead.

combatant.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Combatant::Combatant(int level, int health, int defense, int speed, int damage, int attack, int stamina, int mana, int armor, int magicResist)
{
	string _name;
	bool _alive = true;
	_level = level;
	_health = health;
	_currentHealth = health;
	_defense = defense;
	_speed = speed;
	_damage = damage;
	_attack = attack;
	_stamina = stamina;
	_mana = mana;
	_armor = armor;
	_magicResist = magicResist;
}


part of 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
73
74
75
76
77
78
79
80
81
82
83
84
85
bool Combat::runCombat()
{
	Combatant kyle(1, 10, 10, 3, 5, 6, 15, 12, 500, 1000);
	Combatant one(1, 10, 10, 2, 5, 6, 15, 12, 500, 1000);
	Combatant two(1, 10, 10, 1, 5, 6, 15, 12, 500, 1000);
	Combatant three(1, 10, 10, 4, 5, 6, 15, 12, 500, 1000);

	kyle._name = "Kyle";
	one._name = "Orrin";
	two._name = "Braedon";
	three._name = "Brent";

	bool cbat = true;

	while (cbat == true)
	{
		int turn = checkSpeed(kyle._speed, one._speed, two._speed, three._speed);

		if (turn == 1) {
			int choice = kyle.pickAction();
			if (choice == 1) {
				//Pick target
				cout << "Please pick a target" << endl;
				cout << "1)." << one._name << "   " << one._currentHealth << endl;
				cout << "2)." << two._name << "   " << two._currentHealth << endl;
				cout << "3)." << three._name << "   " << three._currentHealth << endl;
				int choice;
				cin >> choice;

				//Check is attack beats target defense, then subtract armor from damage total and inflict to health.
				switch (choice)
				{
				case 1: 
					if (one._alive == true) {
						one._currentHealth -= kyle.attack(one);
						if (one._currentHealth <= 0) {
							cout << one._name << " has been slain!!" << endl;
							one._alive = false;
						}
					}
					else {
						cout << "Please pick another target. " << one._name << " has had enough!" << endl;
					}
					break;
				case 2:
					if (two._alive == true) {
						two._currentHealth -= kyle.attack(two);
						if (two._currentHealth <= 0) {
							cout << two._name << " has been slain!!" << endl;
							two._alive = false;
						}
					}
					else {
						cout << "Please pick another target. " << two._name << " has had enough!" << endl;
					}
					break;
				case 3:
					if (three._alive == true) {
						three._currentHealth -= kyle.attack(three);
						if (three._currentHealth <= 0) {
							cout << three._name << " has been slain!!" << endl;
							three._alive = false;
						}
					}
					else {
						cout << "Please pick another target. " << three._name << " has had enough!" << endl;
					}
					break;
				}
				
			}
		}
		else if (turn == 2) {
			one.attack(kyle);
		}
		else if (turn == 3) {
			two.attack(kyle);
		}
		else {
			three.attack(kyle);
		}
	}
	return true;

}


i've checked the debugger and at every state, all the _alive variables equal true but it never when as if it were true. It immediately says each target is dead right as I declare it without any info about whether is died or not or took damage. my combatants are playing opossum.

edit: and as i was typing that reply i had an idea and tried it after posting, it worked, problem resolved. I needed to switch the if else statements.
Last edited on
Topic archived. No new replies allowed.
Pages: 12