I am developing a maze game. And it's getting me frustrated because i put so much effort into this program and can figure out how to place characters in a maze game. I am developing a maze game and i basically can navigate throughout the array 5X5. However, my problem is i can't figure how to place the rest of characters on the board.
The game should look like this:
CODE
X ? ? _ ?
X X _ X _
X ? X ?
??_ _ _
x - number of barries
? - 5 number of golden coins
? - 2 bombs
This what i have done so far:
CODE
#include <iostream>
#include <cassert>
using namespace std;
void print(char board[]);
void shuffle( char, int);
const int ROW_SIZE = 5;
const int BOARD_SIZE = ROW_SIZE * ROW_SIZE;
int main()
{
char board[BOARD_SIZE] = {
'X', '?', 'X', '?', 'X',
'?', 'X', '?', '?', '?',
'X', '?' ,'_', '_', '_',
'_', '_', '_', '_', '_',
'_', '_', '_', '_', '_'};
int Xposition = BOARD_SIZE / 2;
for (int i=0;i<BOARD_SIZE; i++)
board[i] = '_';
board[Xposition] = '*';
bool playing = true;
while (playing)
{
print(board);
char input;
bool okMove = true;
int newPosition;
cout <<"Move (u,d,l,r), or quit (q): ";
cin >> input;
if (input == 'q')
playing = false;
else if (input == 'l') {
newPosition = Xposition - 1;
if (Xposition % ROW_SIZE == 0)
okMove = false;
}else if (input == 'r') {
newPosition = Xposition + 1;
if (newPosition % ROW_SIZE == 0)
okMove = false;
}else if (input == 'u') {
newPosition = Xposition - ROW_SIZE;
if (newPosition < 0)
okMove = false;
}else if (input == 'd') {
newPosition = Xposition + ROW_SIZE;
if (newPosition >= BOARD_SIZE)
okMove = false;
}else
okMove = false;
if (playing)
{
if (okMove)
{
board[newPosition] = '*';
board [Xposition] = '_';
Xposition = newPosition;
}else
cout << "Illegal move\n";
}
}
return 0;
}
//print the maze board
//precondition: board size == BOARD_SIZe
//postcondition: none
void print(char board [])
{
for (int count=0;count < BOARD_SIZE;count++)
{
if (count % ROW_SIZE == 0)
cout << endl;
cout << board[count];
}
cout << endl;
}
void runmaze( char a [], int SIZE)
{
char gold = '?';
char bomb = '?';
char barrier = 'X';
//for ( int count = 0; count < BOARD_SIZE - 1; count ++)
{
if ( )
}
}
/ ********************************************************************************
******************************************************************
********************************************************************************
*******************************************************************
********************************************************************************
*******************************************************************
********************************************************************************
******************************************************************/
void shuffle( char input[], int SIZE )
{
assert (SIZE >=0);
int i = SIZE;
while ( i > 1)
{
int j = rand() % i;
char temp = input[ j - 1];
input [i - 1] = input[j];
input [j] = temp;
i --;
}
}
Any help is much appreciated.