Simple maze game using C... Here's what I want to do. ( I am using Dev-C++ compiler)
** game map should be loaded from a file (in the following code, map is generated runtime), and its format should be something like the following.
WWWWWWWWWWWWWWWW
W W
W W
W $ $ W
W O W
W $ M W
W W
W M W
W M E W
WWWWWWWWWWWWWWWW
W = wall
O = moving character
$ = money
E = exit
M = monsters (when game is started these monsters should be chasing the O character)
** keys A,S,W and Z are used to move the character O (in the following code only key the down movement (key S) is coded.
** username and score should be visible and when game ends this info should be saved to a file (may be top 5 scorers)
==========================
==========
==========
=======
#include <iostream.h>
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
char moveR;
char moveL;
char moveU;
char moveD;
char move;
int mx=1;
int my=1;
int i,j;
char direction;
const char up_key='w', down_key='s', left_key='a', right_key='d';
char keypress;
char matrix[100][100];
void gotoxy(short x, short y)
{
HANDLE hConsoleOutput;
COORD Cursor_an_Pos = {x,y};
hConsoleOutput = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(h
ConsoleOut
put, Cursor_an_Pos);
}
void loadgrid()
{
for (i=0; i<30; i++)
{
for (j=0; j<30; j++)
{
matrix[i][j]= '.';
}
}
}
void printgrid()
{
for (i=0; i<30; i++)
{
for (j=0; j<30; j++)
{
printf("%c", matrix[i][j]);
}
printf("\n");
}
}
int main()
{
loadgrid();
printgrid();
while (mx>0 && my>0)
{
if (kbhit())
{
keypress=getch(); //keypress=(char)getchar()
if ((keypress == right_key) || (keypress == left_key) ||
(keypress == up_key) || (keypress == down_key))
direction = keypress;
if (direction == 's')
{
gotoxy(mx,my);
printf(".");
my=my+1;
gotoxy(mx,my);
printf("O");
gotoxy(mx,my);
}
if (direction == 'w')
{
gotoxy(mx,my);
printf(".");
my=my-1;
gotoxy(mx,my);
printf("O");
gotoxy(mx,my);
}
if (direction == 'a')
{
gotoxy(mx,my);
printf(".");
mx=mx-1;
gotoxy(mx,my);
printf("O");
gotoxy(mx,my);
}
if (direction == 'd')
{
gotoxy(mx,my);
printf(".");
mx=mx+1;
gotoxy(mx,my);
printf("O");
gotoxy(mx,my);
}
direction = ' ';
}
}
return 0;
}