multi-dimensional array rpg map

Hey guys, would just like a small amount of help please.

At the moment I have a 2d array which displays a map (made up of numbers), I was just wondering how I would put an X onto it and make it so the player can input coordinates and move to a specified location.

My final aim is to make quite a complex text rpg.

Here is my code so far, nothing too complex:

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
#include <iostream>

using namespace std;

int main()
{

int GameMap [3][3] = {0, 0, 0,
0, 1, 0,
0, 0, 0};

for(int x=0; x < 3; x++){
    cout << endl;
    for( int y = 0; y < 3; y++){
    cout << " ";
    cout << GameMap[x][y] ;


    }


cout << endl;


}




}


Any help, even just small suggestions, would be greatly appreciated :D
Also one other quick question.

Does anyone know why this isn't working?


1
2
3
4
5
6
7
string playergender;

cout << "Please enter your gender: ";
cin >> playergender;
if(( playergender != "Male") || ("male") || ("Female") || ("female")){
cout << "Invalid Input.";
}


Even when I type 'Male' in the program it still says Invalid Input.
Last edited on
I tested your code.

This one works:
1
2
3
4
5
6
7
8
9
10
11
12
	string playergender;

cout << "Please enter your gender: ";
cin >> playergender;
if(playergender == "Male" || playergender == "male" || playergender == "Female" || playergender == "female")
{
cout << "Continue";
}
else
{
	cout << "Invalid Input.";
}


I'm not quite sure as to why it works... It just does.
if(( playergender != "Male") || ("male") || ("Female") || ("female")) should be if(( playergender != "Male") && (playergender !="male") && (playergender !="Female") & (playergender !="female")). What you said was equivalant to if(condition1 || "male" || condition2 || condition3) That will always be true, because "male" is a non 0 value, so it evaluates to true.
Ah ok, I get it now, thanks so much Intrexa especially for your explanation at the end. :D

Also thankyou Ben Duncan, it did work! However, I went the other route due to it being easier for me to structure.
*bump about the array*

Sorry :(
Not to be a downer, but making a game in the command isn't a good idea if your starting off. It would be -way- easier to do a simple 2d game.

It will just get bigger and bigger and more confusing with every line. At least this is what happens to everyone I knew who tried it (including myself).

oh ok, I just thought it would be a good way of enforcing the c++ fundamentals. So you think I should just skip ahead to SDL and just begin from there?
That's what I did (I like allegro wayy more though). Very big user base, and all the SDL tut's I see are just old. At least, what I see.

If you want to do Game Development, I would try making a simple 2d game, while learning the basic's of C++. Then you can work your way up, while learning everything at once. That's what I did (Well, still doing).

If you choose to do Allegro, I could help you personally.

Happy Coding~!
Already started SDL :(

They are pretty much similar, found this great website:

http://lazyfoo.net/SDL_tutorials/index.php

Which highlights the basic syntax and so on.

Wishing you the best too, maybe one day you and I should make a game together :D

May be quite fun.
Mhmm, lol. I'm trying to find someone to do it with. Secretly bringing people to Allegro.

Oh well, maybe some day!
Topic archived. No new replies allowed.