Need help fixing a few errors in my program.

Pages: 12
xismn wrote:
Will edit this and give valuable feedback when I'm not so tired

Thanks, I have pretty much created this entire program looking at all of my old coding projects, and the way i tried to do it was how i thought i did it last time.

I want to do something similar to the following examples, without making all the global this time.

The following are examples from multiple files from another game. Deleted unimportant stuff to save space.
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
class Monster // Defines the existance of monsters
{	string Type;
    int Atk;
    int Def;
    int HP;
    int SpAtk;
    int SpDef;
    string Advantage;
    string Disadvantage;
    string MonsterName;
    int Speed;
    int Level;
    int Experience;
    Moves move;
	Moves move1;
	Moves move2;
	Moves move3;
	Moves move4;

public: 
	Monster();
	~Monster();
//... was more code
	void FireType();	//The Fire Type
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Moves
{	string Type;
	string Category;
	int Power;
	int Accuracy;
	int PP;
public:
Moves();
Moves::Moves (string t, string cat, int p, int acc, int pp); 
	~Moves();
	string GetType();
	void SetType(string x);
	string GetCategory();
	void SetCategory(string x);
	int GetPower(); 
	void SetPower(int x);
	int GetAccuracy();
	void SetAccuracy(int x);
	int GetPP();
	void SetPP(int x);
};
1
2
3
4
5
//global moves
Moves Punch ("Normal", "Physical", 20, 100, 10); 
Moves Kick ("Normal", "Physical", 25, 100, 10);
Moves Tackle ("Normal", "Physical", 30, 100, 10);
Moves FirePunch ("Fire", "Physical", 20, 100, 10); 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void Monster::FireType () //The Fire Type
{	Type = "Fire";
	Advantage = "Nature";
	Disadvantage = "Water";
	MonsterName = "FireType";
	Atk = 6;
	Def = 1;
	SpAtk = 6;
	SpDef = 1;
	HP = 40;
	Speed = 10;
	Level = 5;
	Experience = 1000;
	move1 = Punch;
	move2 = Kick;
	move3 = Tackle;
	move4 = FirePunch;
}
I'll just create a new post instead.
I think before you fix your errors/bugs, take some time to learn more about
inheritance and polymorphism.
Also, I'm a generally tired person, so my help might be in vain.
Just to back up my suggestion, however, here's a sloppy example I slapped together of what your classes could possibly look like :

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
#ifndef _MOB_H_
#define _MOB_H_
//I know, I know, don't gimme yo attitude.

#include <string>
#include <vector>

class Attribute {
public :
	Attribute() {/*code*/}
	/*
	Whatever you want attributes to be. Either skills (strength, endurance, magicka, etc.)
	or maybe modifiers of some kind (fire resistance, etc.)
	*/
	//methods and stuff goes here.
};

class Equipment {
public :
	Equipment() {}
	std::string name;
	int health;//quality or condition of equipment.
	int mod;//this is me not being smart. Could be used for different purposes depending on if it's a weapon or armor, etc.
	//other things for base class
};

class Weapon : public Equipment {
public :
	Weapon() {}
	//implicitly call base constructor if you need to.
	//weapon unique code here

};

class Armor : public Equipment {
public :
	Armor() {}
	//same deal

};

//class Move {
//too lazy forgive me


class Mob {
public: 
	Mob() {}
	std::string name;
	std::vector<Attribute> attributes;
	std::vector<Equipment> equipment;
	std::vector<Move> moves;

	//methods which iterate through each vector respectively and do things

};

#endif 


Sorry for the formatting.
Last edited on
Topic archived. No new replies allowed.
Pages: 12