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
|
#include <iostream>
#include <cstring>
using namespace std;
const char* level1[23] =
{
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"X X",
"X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X",
"X X K X D X X",
"X XXXXXXXXXXXXXXXXXXXXXX XXXXXXXXX XXXXXXXXXXXXXXXXXXXXX X X",
"X X X X X XXXXX X X",
"X X XXXXX X XXXXXXXXXXXXXX XXXXXXXX XXXXXXXXXXX X X",
"X X X X D X X X X X XXXXX X",
"X X XXXX X X XXXXXXXXXX X X X XXXX X X",
"X X X X E X XXXXXXXXX XXXXXXXX X XXXXX X X",
"X XXXXXXXXXXXXXXXX D X XXK X X X X KX X",
"X X X X KX XXXXXX XXXXXX XXXXXXXX X X X XXXXXXDX",
"X X X X X X X XXX X X X X D X X",
"X X X X X X XXXXXXXXXXXXXXX XXXXXXXXXXXXXX X XXXXX X X",
"X X X X X X X X X KX X X X",
"X X X X X X X X XXXXXXXXXXX X XXXXXXXXXXX X XXXXX X",
"X X X X X X X X X X KX X X X X X",
"X X X X X X X X XX X X XXXXXXXXXXXXX X X",
"X X X X X X X X X XXXXXXXX X X X X X X",
"X X X X X X X X X X X X X X",
"X X XXXXXXXXXXXXX X XXXXXXXX X X X XXXXXXXXXXXXXXXXXX X",
"XS X X",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
};
// Player structure
struct playerinfo
{
int x; // X position
int y; // Y position
int keys; // Number of keys the player has
};
// Current game info structure
struct gameinfo
{
char** board; // The maze array
int maxx; // Max size of the maze array X coordinate
int maxy; // Max size of the maze array X coordinate
int level; // The level of the maze
playerinfo player; // Link to player data struct
};
// Initializes the dynamic array that stores the maze
char** initboard(gameinfo game)
{
char** matrix = new char*[game.maxx];
for (int i=0; i<game.maxx; i++)
matrix[i] = new char[game.maxy];
return matrix;
}
void delboard(gameinfo game)
{
for (int i=0;i<game.maxx;i++)
delete [] game.board[i];
delete [] game.board;
}
int main()
{
gameinfo game;
game.maxx=65;
game.maxy=23;
game.board = initboard(game);
memcpy(game.board,level1,sizeof(level1));
game.board = initboard(game);
delboard(game);
}
|