i'm trying to make a simple c++ rpg to learn about classes. first thing im doing getting it to walk around a small town. when i enter n, s, e, or w it wont move me.
the map i walk around in is a char called seasidetown_map.
my position on that map is saved with int pos1 and pos2 in the class i made
its changed with the functions inside the class i made to store the player.
how bad did i screw up guys
Code:
#include <iostream>
#include <string>
using namespace std;
void main_menu();
void new_game();
void game_run();
char seasidetown_map[100][100]= {" x ",
" i--c-------c----------c----------c ",
" | | | | ",
" | | | | ",
" | | | | ",
" | | | | ",
" | | | | ",
" | | w | ",
" | | | ",
"s---c-------c-----c---------------c ",
" | | | | ",
" | | | | ",
" | c-----c---------------c ",
" | | ",
" | | ",
" t | ",
" x "};
class cplayer
{
public:
string name;
int mega_location;
int pos1, pos2;
int health, max_health;
int mana, max_mana;
int gold;
int experience;
void pos1plus()
{
pos1++;
}
void pos1minus()
{
pos1--;
}
void pos2plus()
{
pos2++;
}
void pos2minus()
{
pos2--;
}
} hero;
int main()
{
main_menu();
return 0;
}
void main_menu()
{
cout << "menu\n\n"
<< "\t1) new game\n"
<< "\t2) quit\n\n"
<< ">>";
string input;
getline(cin, input);
if(input == "1")
{
new_game();
}
if(input == "2")
{
exit(1);
}
}
void new_game()
{
cout << "\nname your character\n"
<< ">>";
string input;
getline(cin, input);
hero.name = input;
hero.health = 25;
hero.max_health = 25;
hero.mana = 10;
hero.max_mana = 10;
hero.mega_location = 0;
hero.gold = 100;
hero.pos1 = 5;
hero.pos2 = 23;
game_run();
}
void game_run()
{
jump_back:
if(hero.mega_location == 0)
{
cout << "Seaside Town\n"
<< "------------\n";
}
int flag_n, flag_e, flag_s, flag_w;
flag_n = 0;
flag_e = 0;
flag_s = 0;
flag_w = 0;
cout << "possible exits: \n";
if(seasidetown_map[hero.pos1+1][hero.pos2] == '|' || seasidetown_map[hero.pos1+1][hero.pos2] == 'c')
{
flag_n = 1;
cout << "north ";
}
if(seasidetown_map[hero.pos1-1][hero.pos2] == '|' || seasidetown_map[hero.pos1+1][hero.pos2] == 'c')
{
flag_s = 1;
cout << "south ";
}
if(seasidetown_map[hero.pos1][hero.pos2+1] == '-' || seasidetown_map[hero.pos1+1][hero.pos2] == 'c')
{
flag_e = 1;
cout << "east ";
}
if(seasidetown_map[hero.pos1][hero.pos2-1] == '-' || seasidetown_map[hero.pos1+1][hero.pos2] == 'c')
{
flag_w = 1;
cout << "west ";
}
cout << "\n------------\n"
<< "\n HP MP\n"
<< hero.health << "/" << hero.max_health
<< " " << hero.mana << "/" << hero.max_mana
<< "\n>>";
string input;
getline(cin, input);
if(input == "n" || flag_n == 1)
{
hero.pos1plus();
}
if(input == "e" || flag_e == 1)
{
hero.pos2plus();
}
if(input == "s" || flag_s == 1)
{
hero.pos1minus();
}
if(input == "w" || flag_w == 1)
{
hero.pos2minus();
}
goto jump_back;
}