Hi guys just wondering if anyone could give me some tips on starting a moveable char function for my maze game.
I wish to create a function that allows me to move the player through the maze shown below. I have a few ideas on how to do this however the methods I am coming up with are slightly long winded.
Just wondering if anyone had any examples or ideas.
Below is the code I have so far
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <conio.h>
#include <Windows.h>
using namespace std;
int col = 1;
int row = 2;
const int rowm = 20;
const int colm = 20;
char maze[rowm][colm] =
{
{'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X'},
{'X','S','X','X','X','X',' ',' ',' ',' ',' ',' ',' ',' ','X','X',' ',' ',' ','X'},
{'X',' ','X','X','X','X',' ','X','X','X','X','X','X','X','X','X',' ',' ',' ','X'},
{'X',' ',' ',' ',' ','X',' ',' ',' ',' ',' ',' ',' ',' ',' ','X',' ','X','X','X'},
{'X',' ','X','X','X','X',' ','X','X','X','X','X','X','X',' ','X',' ',' ',' ','X'},
{'X',' ','X','X','X','X',' ',' ',' ',' ',' ',' ',' ',' ',' ','X',' ','X',' ','X'},
{'X',' ','X',' ',' ','X',' ','X','X','X',' ','X','X','X','X','X',' ','X',' ','X'},
{'X',' ',' ',' ','X','X',' ',' ','X','X',' ',' ',' ',' ',' ',' ',' ','X',' ','X'},
{'X',' ','X',' ','X','X','X',' ','X',' ',' ',' ',' ','X',' ','X',' ',' ',' ','X'},
{'X',' ','X',' ',' ',' ',' ',' ','X',' ','X','X',' ','X',' ','X',' ','X','X','X'},
{'X',' ','X','X','X','X','X',' ','X',' ','X','X',' ','X',' ','X',' ',' ',' ','X'},
{'X',' ','X','X',' ',' ',' ',' ','X',' ',' ','X',' ','X',' ','X',' ','X',' ','X'},
{'X',' ',' ','X',' ','X','X','X','X','X',' ','X',' ','X',' ','X',' ','X',' ','X'},
{'X','X',' ','X',' ','X',' ',' ',' ',' ',' ','X',' ','X',' ','X','X','X',' ','X'},
{'X','X',' ','X','X','X','X',' ','X',' ','X','X',' ','X',' ',' ',' ','X',' ','X'},
{'X','X',' ','X','X','X','X',' ','X',' ','X','X',' ','X','X','X','X','X',' ','X'},
{'X',' ',' ','X',' ',' ','X',' ','X',' ','X','X',' ',' ',' ','X',' ',' ',' ','X'},
{'X',' ','X','X','X',' ','X',' ','X',' ','X','X','X','X',' ','X',' ','X',' ','X'},
{'X',' ',' ',' ',' ',' ','X',' ','X',' ',' ',' ',' ',' ',' ','X',' ','X','F','X'},
{'X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X','X'}};
void printmaze();
void runmaze(int, int);
void initgame()
{
printf("Welcome to ze game!");
}
void printmaze()
{
for(int row = 0; row < rowm; row++)
{
for(int col=0; col < colm; col++)
cout << maze[row][col];
cout << "\n";
}
}
void runmaze(int row, int col)
{
if( (row>0 && row<rowm) && (col>0 && col<colm)) {
if( maze[row][col] == 'W' ) return;
if( maze[row][col] == ' ') {
maze[row][col]='*';
runmaze(row, col+1);
runmaze(row, col-1);
runmaze(row-1, col);
runmaze(row+1, col);
}
}
}
void player(char rowm, char colm)
{
player(rowm ="h", colm
}
int main()
{
runmaze(2,2);
printmaze();
return 0;
}
Regards
Ryan