creating game character using class

Hello! I'm making a turn-based battle RPG battle program. Some feature of my game is choosing what type of character (warrior, wizard and archer) and choosing either easy, normal and insane. The problem is i don't know how to create using class so that I can get their hp, mp and attack in one. I'm new to class. Can someone show the snippet of the codes?
Last edited on
Why don't you have a look around in the forum.
It's so common there must be plenty of examples:
http://www.cplusplus.com/search.do?q=rpg
you want a constructor that assigns the value, so you can do this

character joebob(wizard, 1000, insane); //creates the new guy with these settings.
where wizard and insane are likely pulled from enums.

you may want to disable the default constructor so they are forced to do the above, or not, as you see fit. If you disable it, you need a setup method to fill them in after the fact and if enabled the default should assign some default values.

Last edited on
thanks.
Here is some sample code to get you going...
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
#include <iostream>
#include<string>

using namespace std;

class player {

	string playerClass;
	int level, attack;

public:
	int hp, mp, experience;

	player(int choice) {
		if (choice == 1) {
			playerClass = "Warrior";
			level = 1;
			attack = 60;
			hp = 100;
			mp = 10;
			experience = 0;
		}//if 1
		if (choice == 2) {
			playerClass = "Wizard";
			level = 1;
			attack = 20;
			hp = 100;
			mp = 100;
			experience = 0;
		}//if 2
		if (choice == 3) {
			playerClass = "Archer";
			level = 1;
			attack = 40;
			hp = 100;
			mp = 30;
			experience = 0;
		}//if 3
	}

	string printClass() {
		return playerClass;
	}
};

int main() {

	cout << "Choose your character class. \n[1] Warrior [2] Wizard [3] Archer : ";
	int choice;
	cin >> choice;

	while (!cin >> choice || choice > 3 || choice < 1) {
		cout << "Not a valid choice. \nChoose your character class. \n[1] Warrior [2] Wizard [3] Archer : ";
		cin >> choice;
	}

	player character(choice);
	
	cout << "\nWelcome " << character.printClass() << ". Let's begin your adventure." << endl;



	cin.ignore();
	cin.get();
	return 0;
}
Last edited on
Topic archived. No new replies allowed.