Sign in to follow this  

2D Array Defined Maps

This topic is 3739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Right now i have a simple two player game, with a map. Its a simple console game that is compiled with dev-c++. The problem is that I'm currently using a 2D array for the bases of the map, & i cant seem to find a way to get a users input & from that select the map. I believe the way I'm doing it may be incorrect & I'm hoping for a new way, or a better way that can fix the problem. What i want : User To be able to choose from 1 of 3 maps to play.
#define X_SIZE 41
#define Y_SIZE 24
    unsigned char Maze[Y_SIZE][X_SIZE] =
{
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,2,2,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
};
template <typename T>
void textAt(int x, int y, int colour, T output) { 
    static const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD position = {x, y};
    SetConsoleCursorPosition(hConsole, position);
    SetConsoleTextAttribute(hConsole, colour);
    cout << output;
}
int main(){
    cout << " ____                              \n";
    cout << "/\\  _`\\                            \n";
    cout << "\\ \\ \\L\\ \\     __      ___     __   \n";
    cout << " \\ \\ ,  /   /'__`\\   /'___\\ /'__`\\ \n";
    cout << "  \\ \\ \\\\ \\ /\\ \\L\\.\\_/\\ \\__//\\  __/ \n";
    cout << "   \\ \\_\\ \\_\\ \\__/.\\_\\ \\____\\ \\____\\\n";
    cout << "    \\/_/\\/ /\\/__/\\/_/\\/____/\\/____/\n";
    cout << "Map 1/2 : ";      
    cin >> map;
if(map == 1){
                 // Either Redefine the map here 
                 // Or Set new map
            }
            else if(map ==2){
                 // Either Redefine the map here 
                 // Or Set new map
                 }
                 }
     else{
            cout << "Invalid Choice!\n";     
           system("pause");
           exit(1);}

     int WALL_y, WALL_x;
  for(WALL_y = 0; WALL_y < Y_SIZE /*Defined Up Above*/; WALL_y++)
  {
    for(WALL_x = 0; WALL_x < X_SIZE; WALL_x++) 
    {
      if(Maze[WALL_y][WALL_x] == 1)
        textAt(WALL_x, WALL_y, 8, char(177));        else if(Maze[WALL_y][WALL_x] == 2)
        textAt(WALL_x, WALL_y, 7, "+");
      else
        textAt(WALL_x, WALL_y, 0, ' ');
    }
  }
}
// Continues on with the actual game part.



I don't know a way to redefine the array, but if theres a way please post how. Any help appreciated. (Even if i didn't mention it above) Thanks, Crypt [Edited by - Crypt on September 18, 2007 10:42:07 PM]

Share this post


Link to post
Share on other sites
If I'm not mistaken, something like this should cut it :


int Maze[2][30][30]; // create a 3d array
Maze[0]={0}; // fill each 3rd dimmension with your chosen map
Maze[1]={1};
Maze[2]={2};

DrawMaze(&Maze[userinput_03]); // pass the reference to the beginning of 2d array
// which was chosen somewhere by the user

void DrawMaze(int **myMaze)
{
... //remember that myMaze is a pointer now

}

Share this post


Link to post
Share on other sites
Wow, i totally surpassed that >.<
Thanks

Hmm Wait i still got an error with this code. I don't see whats exactly wrong with it... (compiled in Dev-C++)

#include <iostream>
#include <windows.h>
#include <ctime>
#include <cstdlib>
using namespace std;

template <typename T>
void textAt(int x, int y, int colour, T output) {
static const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = {x, y};
SetConsoleCursorPosition(hConsole, position);
SetConsoleTextAttribute(hConsole, colour);
cout << output;
}
void DrawMaze(int **myMaze){
/*Target on the map???*/
int currtag = 0;
system("Title Two Player Race");
/*Player Coordinates*/
int player_x = 1;
int player_y = 1;
/*Player2 Coordinates*/
int player2_x = 39;
int player2_y = 22;
/*Prints Out Players Coordinates*/
int coor_x = 45;
int coor_y = 12;
/*target*/
int target_x = 0;
int target_y = 0;
/*Winner Message*/
const int message_x = 15;
const int message_y = 12;

int WALL_y, WALL_x;
for(WALL_y = 0; WALL_y < 25; WALL_y++)
{
for(WALL_x = 0; WALL_x < 46; WALL_x++)
{
if(myMaze[WALL_y][WALL_x] == 1)
textAt(WALL_x, WALL_y, 8, char(177));
else if(myMaze[WALL_y][WALL_x] == 2)
textAt(WALL_x, WALL_y, 7, "+");
else
textAt(WALL_x, WALL_y, 0, ' ');
}
}
textAt(coor_x, (coor_y-1), 4, "Coord 1 Coord 2");

int score01 = 0;
int score02 = 0;

while(1) {
if(currtag == 0){
srand((unsigned)time(0));
target_x = rand() % 41 + 1;
target_y = rand() % 21 + 1 ;
if(myMaze[target_y][target_x] == 0){
currtag = 1;
}
while(myMaze[target_y][target_x] == 1 || myMaze[target_y][target_x] == 2){
srand((unsigned)time(0));
target_x = rand() % 41 + 1;
target_y = rand() % 21 + 1 ;
if(myMaze[target_y][target_x] == 0){
currtag = 1;
}
}
}

Sleep(40);

if (GetAsyncKeyState(VK_DOWN) & 0x8000 && myMaze[player_y+1][player_x] != 1) {
textAt(player_x, player_y, 0, ' ');
player_y++;
textAt((coor_x + 5), coor_y, 4, " ");
textAt((coor_x + 5), coor_y, 4, player_y); }
else if (GetAsyncKeyState(VK_UP) & 0x8000 && myMaze[player_y-1][player_x] != 1) {
textAt(player_x, player_y, 0, ' ');
player_y--;
textAt((coor_x + 5), coor_y, 4, " ");
textAt((coor_x + 5), coor_y, 4, player_y);
}
else if (GetAsyncKeyState(VK_RIGHT) & 0x8000 && myMaze[player_y][player_x+1] != 1) {
textAt(player_x, player_y, 0, ' ');
player_x++;
textAt(coor_x, coor_y, 4, " ");
textAt(coor_x, coor_y, 4, player_x);
}
else if (GetAsyncKeyState(VK_LEFT) & 0x8000 && myMaze[player_y][player_x-1] != 1) {
textAt(player_x, player_y, 0, ' ');
player_x--;
textAt(coor_x, coor_y, 4, " ");
textAt(coor_x, coor_y, 4, player_x);
}


/* Player2*/
/* Down*/
if (GetAsyncKeyState('S') & 0x8000 && myMaze[player2_y+1][player2_x] != 1) {
textAt(player2_x, player2_y, 0, ' ');
player2_y++;
textAt((coor_x + 15), coor_y, 4, " ");
textAt((coor_x + 15), coor_y, 4, player2_y); }
/* Up*/
else if (GetAsyncKeyState('W') & 0x8000 && myMaze[player2_y-1][player2_x] != 1) {
textAt(player2_x, player2_y, 0, ' ');
player2_y--;
textAt((coor_x + 15), coor_y, 4, " ");
textAt((coor_x + 15), coor_y, 4, player2_y);
}
/* Right*/
else if (GetAsyncKeyState('D') & 0x8000 && myMaze[player2_y][player2_x+1] != 1) {
textAt(player2_x, player2_y, 0, ' ');
player2_x++;
textAt((coor_x+10), coor_y, 4, " ");
textAt((coor_x+10), coor_y, 4, player2_x);
}
/* Left*/
else if (GetAsyncKeyState('A') & 0x8000 && myMaze[player2_y][player2_x-1] != 1) {
textAt(player2_x, player2_y, 0, ' ');
player2_x--;
textAt((coor_x+10), coor_y, 4, " ");
textAt((coor_x+10), coor_y, 4, player2_x);
}



textAt(player2_x, player2_y, 5, char(2));
textAt(player_x, player_y, 3, char(2));
textAt(target_x, target_y, 6, char(6));

if (player_x == target_x && player_y == target_y) {
score01++;
currtag = 0;
}
if (score01 == 10) {
textAt(message_x, message_y, 3, "Player One Wins!");
Sleep(3250);
exit(1);
}
if (player2_x == target_x && player2_y == target_y) {
score02++;
currtag = 0;
}
if (score02 == 10) {
textAt(message_x, message_y, 3, "Player Two Wins!");
Sleep(3250);
exit(1);
}
}

}

int main(){
int Maze[1][25][46];
Maze[0]={
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1},
{1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},
{1,0,0,0,0,1,0,0,0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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1},
{1,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0,0,1},
{1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},
{1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},
{1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1},
{1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
};
const int time_x = 20;
const int time_y = 11;
int map = 0;
cout << " ____ \n";
cout << "/\\ _`\\ \n";
cout << "\\ \\ \\L\\ \\ __ ___ __ \n";
cout << " \\ \\ , / /'__`\\ /'___\\ /'__`\\ \n";
cout << " \\ \\ \\\\ \\ /\\ \\L\\.\\_/\\ \\__//\\ __/ \n";
cout << " \\ \\_\\ \\_\\ \\__/.\\_\\ \\____\\ \\____\\\n";
cout << " \\/_/\\/ /\\/__/\\/_/\\/____/\\/____/\n";
cout << "Map 1/2 : ";
cin >> map;

DrawMaze(&Maze[map]);

}


Thanks Again.

[Edited by - Crypt on September 19, 2007 12:56:47 AM]

Share this post


Link to post
Share on other sites
The suggested solution does not work, because the array initialization syntax only works when initializing arrays. Suggested modification:

namespace maps
{
const unsigned width = 41;
const unsigned height = 24;

unsigned char maze_1[width][height] = { /* data */ }
unsigned char maze_2[width][height] = { /* data */ }
unsigned char maze_3[width][height] = { /* data */ }

typedef (&maze)[width][height];

maze get(unsigned int i)
{
switch (i)
{
case 0: return maze_1;
case 1: return maze_2;
case 2: return maze_3;
default: assert (false);
}
}
}


Use maps::get(0) to get a reference to the first maze, for instance.

Share this post


Link to post
Share on other sites

This topic is 3739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this