I just created my first "make something move in a maze with the arrow keys" program. I then changed the map I was playing on (it's a string). I changed all of the variables I needed to accomidate the change. I get crap. The initial output is gibberish, and when I push the arrow keys, I can bareley see my map flichering in the BACHGROUND of this text. I'll give you the code and the output picture. Good luck to whoever dare venture into my hechtic code.... (well, not really; oh nevermind!):
Code:
#include "stdafx.h"
#define _clrscr
#include <monkey.h>
//12x30
typedef enum UPARAM {ZIP,UP,DOWN,LEFT,RIGHT,Q,A,Z,W,S,X};
int COL_MAX = 47;
int ROW_MAX = 11;
int PLAYERX = 1;
int PLAYERY = 12;
char ITEM = 'O';
char ItemMessage[50] = "You picked up an item!";
char* message = new char[50];
char MAP[11][47] = {" ____________________________________________ ",
"| | |X |",
"| | |_______________ |",
"| | |> |---_----------_ |",
"| | | O | | |",
"| | |> | | | | |",
"| | | | | |",
"| |______|______| --------------- |",
"| |",
"(--------------------------------------------)"};
void display();
int ReadFiles();
int MovePlayer(int x,int y);
UPARAM PassParam(UPARAM Uparam);
int main(int argc, char* argv[])
{
message = " ";
char input;
char arrow;
UPARAM Uparam = ZIP;
/////////////GAME PUMP/////////////GAME PUMP////////////////////
/////////////GAME PUMP/////////////GAME PUMP////////////////////
/////////////GAME PUMP/////////////GAME PUMP////////////////////
while(1)
{
//SHOW MAP SCREEN
display();
printf("\n");
//OUTPUT MESSAGE (BLANK IF THERE IS NOTHING TO SAY)
if(!strcmpi(message," "))
{
}
else
{
printf(message);
while(!kbhit());
}
message = " ";
input = getch();
//IF ARROW KEY...
if((int)input == -32)
{
arrow = getch();
switch(arrow)
{
case 'H':
{
Uparam = UP;
}break;
case 'P':
{
Uparam = DOWN;
}break;
case 'K':
{
Uparam = LEFT;
}break;
case 'M':
{
Uparam = RIGHT;
}break;
}
}
//IF OTHER THAN ARROW KEY...
else
{
switch(input)
{
case 'x':
{
return 0;
}break;
}
}
//SEND MESSAGE
PassParam(Uparam);
//CLEAR THE SCREEN
clrscr();
}
/////////////END GAME PUMP/////////////END GAME PUMP////////////////////
/////////////END GAME PUMP/////////////END GAME PUMP////////////////////
/////////////END GAME PUMP/////////////END GAME PUMP////////////////////
return 0;
}
void display()
{
for(int loop2 = 0; loop2 < COL_MAX; loop2++)
{
for(int loop1 = 0; loop1 < ROW_MAX; loop1++)
{
char displayer;
displayer = MAP[loop2][loop1];
printf("%c",displayer);
if(loop1 == (ROW_MAX - 1))
printf("\n");
}
}
}
int MovePlayer(int x, int y)
{
if(MAP[x][y] == ' ')
{
MAP[PLAYERX][PLAYERY] = ' ';
MAP[x][y] = 'X';
PLAYERX = x;
PLAYERY = y;
}
else if(MAP[x][y] == ITEM)
{
MAP[PLAYERX][PLAYERY] = ' ';
MAP[x][y] = 'X';
PLAYERX = x;
PLAYERY = y;
message = ItemMessage;
}
return 0;
}
UPARAM PassParam(UPARAM Uparam)
{
switch(Uparam)
{
case UP:
{
MovePlayer(PLAYERX - 1,PLAYERY);
}break;
case DOWN:
{
MovePlayer(PLAYERX + 1,PLAYERY);
}break;
case LEFT:
{
MovePlayer(PLAYERX,PLAYERY - 1);
}break;
case RIGHT:
{
MovePlayer(PLAYERX,PLAYERY + 1);
}break;
default:
{
}break;
}
return ZIP;
}
int ReadFiles()
{
char* COLMAX = new char[2];
char* ROWMAX = new char[2];
ifstream FileReader("C:\\Maze\\boarddimensions.txt");
FileReader>>COLMAX;
FileReader>>ROWMAX;
FileReader.close();
return 0;
}