Help in making a very simple rpg game

Hi guys. I want to make a very simple rpg game, which gives me the choice to attack or use a weapon against two objects (rock and log) that have lives, but one at a time. When I use my weapon, I can equip one out of the five that I have. After which, I attack and the object loses it's life (strength) slowly ( though the object does not attack, it's like a training dummy). I need to make classes for my name, MP (mana points), HP (Health Points), and make functions for the damage inflicted, special skill (which removes 10 HP) and mana skill (which removes 10 MP). :) So far, if you compile this code, you get the output:


Name: Adriel
HP:50
MP:50

Name: Rock
Strength: 50

Name: Log
Strength: 40

What do you want to attack first?
1. Rock 2. Log



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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
       #include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>


using namespace std;




class character{

public:

void name(string Name= "Adriel")
{
cout << "Name: " << Name << endl;
}



public:
void hp (int IHP=50)
{

cout << "HP: " << IHP << endl;
}



public:
void mp (int IMP=50)
{
cout << "MP: " << IMP << endl;
}




public:
void rock(string Name= "Rock", int Strength= 50)
{
cout << "\nName: " << Name << endl;
cout << "Strength: "<< Strength << endl;
}


public:
void log(string Name= "Log", int Strength= 40)
{
cout << "\nName: " << Name << endl;
cout << "Strength: "<< Strength << endl;
}


	

};




void main ()
{
	int number;

character first;
first.name();


character second;
second.hp();


character third;
third.mp();


character fourth;
fourth.rock();

character fifth;
fifth.log();

cout << "\nWhat do you want to attack first?\n 1. Rock     2. Log" << endl;
cin >>number;



getch();
}




Your character class needs some state data and some getter/setter functions, like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class character
{
private:
    int m_hp;
    int m_mp;
    string m_sName;
    int m_strength;

public:
   character(); // default constructor
   character (string sName, int strength, int mp, int hp);

   int getHP();
   void setHP(int newHP);
   int getMP();
   void setMP(int newMP);
   int getStrength();
   void setStrength(int newStrength);
   string getName();
   void setName(string newName);
};


then you can create character like this;
1
2
3
character rock("rock", 50, 0,0);
character log("log", 30, 0,0);
character player("fred", 50, 20,20);


you can then start adding functions to modify the characters properties;

1
2
3
4
character::damage(int damage)
{
    m_hp -= damage;
}


and use them like this;
 
rock.damage(10);


that should get you started, there's nothing better than a good text based rpg :)
Topic archived. No new replies allowed.