C++ RPG Start tips please

Yo is this good code because im pretty proud on the start system i made for it
but any ideas to improve?
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
#include <iostream>
#include <stdlib.h>
#include <windows.h>

using namespace std;

string name; //name input seting
string gear; //invatory
string mf; //male / female

int Damage; //set damage from class
int HP; //set Health Points from class

int input;

//Classes data
int WarriorHp = 150;
int WarriorD = 75;
int theifHp = 70;
int theifD = 95;
int RedmageHp = 110;
int RedmageD = 80;
int FreelancerHp = 100;
int FreelancerD = 85;

int main() {
	while(true){
		//menu
		cout << "Welcome to the text based rpg by ByThePowerOfBeavers\n";
		cout << "\n";
		cout << "1)start\n"; //starts game
		cout << "2)Exit\n"; //break loop
		cin >> input;
		if(input == 2){
			break;
		}
		else if(input == 1){
		system("cls");
		cout << "what class do you choose?\n";
		cout << "\n";
		cout << "1)Warrior:\nHP: " << WarriorHp << "\nDamage: " << WarriorD << endl;
		cout << "\n";
		cout << "2)Theif:\nHP: " << theifHp << "\nDamage: " << theifD << endl;
		cout << "\n";
		cout << "1)Redmage:\nHP: " << RedmageHp << "\nDamage: " << RedmageD << endl;
		cout << "\n";
		cout << "2)Freelancer:\nHP: " << FreelancerHp << "\nDamage: " << FreelancerD << endl;
		cout << "\n";
		cout << "Please choose\n";
		cin >> input;
			if(input == 1){
				Damage = WarriorD;
				HP = WarriorHp;
			}
			else if(input == 2){
				Damage = theifD;
				HP = theifHp;
			}
			else if(input == 3){
				Damage = RedmageD;
				HP = RedmageHp;
			}
			else if(input == 4){
				Damage = FreelancerD;
				HP = FreelancerHp;
			}
			system("cls");
			cout << "what is your name?\n";
			cout << "Name:";
			cin >> name;
			system("cls");
			cout << "Are you male or female?\n";
			cout << "M / F : ";
			cin >> mf;
			system("cls");
			cout << name << " | " << HP << " | " << Damage << " | "            << mf << endl;
			cin >> input; // this is just here to hold the screen
		}	
	}
}
closed account (2UD8vCM9)
You should look into structs/classes.

Structs are basically classes where the data is public unless defined as private.

Classes are structs where the data is private by default unless defined as public.

Functions and Classes would help a ton, but just keep playing, it's the best way to learn!
i know about said classes and functions im reading a book. but i cant get anyone to help me out with them and i've benn reading up on it and im the only person in my school that codes in c++. my friend codes in python and java but isn't that good at ether :| . im going to try it out guys so any pointers for a vid or a fourm with a vid so i can read it?
If your friends code in java they can definitely help you with classes otherwise he is probably just copy/pasting his code. Anyways, we are always willing to help people who are trying to learn. So if you have any questions about classes just ask. Here are some links though that may help:
http://www.cplusplus.com/doc/tutorial/classes/ <--At the bottom check out the next few sections also - classes2, special members, friendship and inheritence, and polymorphism.
http://www.learncpp.com/ <-- chapter 8 -> 14
http://www.parashift.com/c++-faq/
thanks guys. i read those and make a new file soon but ill keep messing around with what i got :| but yeah. i knew i would need too sooner or laiter
I am by means NO expert, but I am also in the process of developing a RPG for fun. This is one of my classes that is in a seperate cpp file. Hope this maybe gives you some ideas to help develop!
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <fstream>
#include <iostream>
#include <cctype>
#include "map.h"


map::map(std::string text_file)
{
          std::ifstream load_map;
          load_map.open( text_file.c_str() );
          
          for ( int x = 0; x < height; x++ )
          {
              for ( int y = 0; y < width; y++ )
              {
                  load_map >> gameMap[x][y];
                  }
              }
              load_map.close();
              xCoord = 1;
              yCoord = 2;
              currentLocation = gameMap[xCoord][yCoord];
              vehicleBoat = false;
}

void map::goNorth()
{
     if ( gameMap[xCoord - 1][yCoord] != "WALL" && gameMap[xCoord - 1][yCoord] != "LAKE" )
     {
          xCoord--;
          lastLocation = currentLocation;
          currentLocation = gameMap[xCoord][yCoord];
          }

              else if ( gameMap[xCoord - 1][yCoord] == "WALL" )
              {
                   std::cout << "I shouldn't venture in that direction." << std::endl;
                   }
              else if ( gameMap[xCoord - 1][yCoord] == "LAKE" && vehicleBoat == false )
              {
                   std::cout << "I should find a boat if I want to venture out into the enormous lake." << std::endl;
                   }
              else if ( gameMap[xCoord - 1][yCoord] == "LAKE" && vehicleBoat == true )
              {
                   xCoord--;
                   }
}
          


void map::goSouth()
{
     if ( gameMap[xCoord + 1][yCoord] != "WALL" && gameMap[xCoord + 1][yCoord] != "LAKE" )
     {
          xCoord++;
          lastLocation = currentLocation;
          currentLocation = gameMap[xCoord][yCoord];
          }

              else if ( gameMap[xCoord + 1][yCoord] == "WALL" )
              {
                   std::cout << "I shouldn't venture in that direction." << std::endl;
                   }
              else if ( gameMap[xCoord + 1][yCoord] == "LAKE" && vehicleBoat == false )
              {
                   std::cout << "I should find a boat if I want to venture out into the enormous lake." << std::endl;
                   }
              else if ( gameMap[xCoord + 1][yCoord] == "LAKE" && vehicleBoat == false )
              {
                   xCoord++;
                   }
              
}

void map::goEast()
{
     if ( gameMap[xCoord][yCoord + 1] != "WALL" && gameMap[xCoord][yCoord + 1] != "LAKE" )
     {
          yCoord++;
          lastLocation = currentLocation;
          currentLocation = gameMap[xCoord][yCoord];
          }

              else if ( gameMap[xCoord][yCoord + 1] == "WALL" )
              {
                   std::cout << "I shouldn't venture in that direction." << std::endl;
                   }
              else if ( gameMap[xCoord][yCoord + 1] == "LAKE" && vehicleBoat == false )
              {
                   std::cout << "I should find a boat if I want to venture out into the enormous lake." << std::endl;
                   }
              else if ( gameMap[xCoord][yCoord + 1] == "LAKE" && vehicleBoat == true )
              {
                   yCoord++;
                   }
              
}

void map::goWest()
{
     if ( gameMap[xCoord][yCoord - 1] != "WALL" && gameMap[xCoord][yCoord - 1] != "LAKE" )
     {
          yCoord--;
          lastLocation = currentLocation;
          currentLocation = gameMap[xCoord][yCoord];
          }

              else if ( gameMap[xCoord][yCoord - 1] == "WALL" )
              {
                   std::cout << "I shouldn't venture in that direction." << std::endl;
                   }
              else if ( gameMap[xCoord][yCoord - 1] == "LAKE" && vehicleBoat == false )
              {
                   std::cout << "I should find a boat if I want to venture out into the enormous lake." << std::endl;
                   }
              else if ( gameMap[xCoord][yCoord - 1] == "LAKE" && vehicleBoat == true )
              {
                   yCoord--;
                   }
}

void map::getMove()
{
     std::string userInput = " ";
     std::cout << std::endl;
     std::cout << "What would you like to do?" << std::endl;
     getline(std::cin, userInput);
     for ( unsigned int i = 0; i < userInput.length(); i++ )
     {
         userInput[i] = tolower(userInput[i]);
         }
     checkCommand(userInput);
}

void map::checkCommand(std::string command)
{
     if ( command == "north" || command == "go north" || command == "move north" )
     {
          goNorth();
          }
          else if ( command == "south" || command == "go south" || command == "move south" )
          {
               goSouth();
               }
          else if ( command == "east" || command == "go east" || command == "move east" )
          {
               goEast();
               }
          else if ( command == "west" || command == "go west" || command == "move west" )
          {
               goWest();
               }
          else if ( command == "commands" )
          {
               displayCommands();
               }
          else
          {
         std::cout << "'" << command << "' is not a recognized command, for a available list of commands, type 'commands'." << std::endl;
         }
         
}

void map::displayCommands()
{
     std::cout << std::endl;
     std::cout << "When accessing some commands, for instance, south, you may use 'go south' or 'move south', or just 'south'." << std::endl;
     std::cout << "---List of Commands---" << std::endl << std::endl;
     std::cout << "North, South, East, or West" << std::endl;
     std::cout << "Grab <item>, get <item>." << std::endl;
     std::cout << "Examine, look around, and talk to." << std::endl;
          
}

void map::displayAreaDescription()
{
     std::ifstream load_description;
     load_description.open("description.txt");
     std::string description;
     std::string search = currentLocation;
     while (!load_description.eof() )
     {
     getline(load_description, description);
     if ( description.find(search) != std::string::npos )
     {
          std::cout << description;
          }
          load_description.close();
     }
     
}

void map::display()
{
     for ( int x = 0; x < height; x++ )
     {
         for ( int y = 0; y < width; y ++ )
         {
             std::cout << gameMap[x][y] << " ";
             }
             std::cout << std::endl;
         }
}


Below is the header.
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
#ifndef MAP_H
#define MAP_H


class map
{
	public:
		map(std::string text_file);
		
		const static int height = 8;
		const static int width = 8;
		
		std::string gameMap[height][width];
            /*VARIABLES FOR NAVIGATING THE MAP*/
            int xCoord, yCoord;
            std::string currentLocation, lastLocation;
            
            /*FUNCTIONS FOR NAVIGATING THE MAP*/
            void goNorth();
            void goSouth();
            void goEast();
            void goWest();
            void getMove();
            
            void checkCommand(std::string command);
            void displayCommands();
            
            void displayAreaDescription();
            
            void display();
            
            /*GAME OBJECTS THAT AFFECT MOVEMENT ON THE MAP*/
            bool vehicleBoat;

};

#endif 
Topic archived. No new replies allowed.