#include <iostream>
#include <fstream>
#include <string>
using namespace std;
char gameArray[8][16];
int startX = 0;
int startY = 0;
bool positionCheck = false;
// Reminder:
// i = y-axis direction
// j = x-axis direction
void findPath(void)
{
for (int i = 0; i<8; i++)
{
for (int j = 0; j <16; j++)
{
if (gameArray[i][j] == 'M')
{
if (positionCheck == false)
{
startX = j;
startY = i;
positionCheck = true;
cout << "Mouse is at: " << i << " " << j << endl;
}
}
}
}
// moving in north
if (gameArray[startY-1][startX] == ' ' ) // checking -1 of the y axis for a space. Can be increased to check more spaces at the front.
{
cout << "Replacing path!" << endl;
gameArray[startY-1][startX] = '+'; // if the space is available, change the space to a + sign.
startY--;
findPath(); // recurs to that it'll recheck
}
// moving in south
else if (gameArray[startY+1][startX] == ' ') // same as north
{
cout << "Replacing path!" << endl;
gameArray[startY+1][startX] = '+';
startY++;
findPath();
}
// moving in west
else if (gameArray[startY][startX-1] == ' ')
{
cout << "Replacing path!" << endl;
gameArray[startY][startX-1] = '+';
startX--;
findPath();
}
else if (gameArray[startY][startX+1] == ' ')
{
cout << "Replacing path!" << endl;
gameArray[startY][startX+1] = '+';
startX++;
findPath();
}
}
char inputStandard(void)
{
ifstream myfile ("standard.txt");
if (myfile.is_open())
{
for (int i = 0; i<8; i++)
{
for (int j = 0; j < 16; j++)
{
myfile.get(gameArray[i][j]);
}
}
myfile.close();
}
return 0;
}
char inputCustom(void)
{
ifstream myfile ("custom.txt");
if (myfile.is_open())
{
for (int i = 0; i<8; i++)
{
for (int j = 0; j < 16; j++)
{
myfile.get(gameArray[i][j]);
}
}
myfile.close();
}
return 0;
}
void main(void)
{
string status_mode = "NONE";
int choice;
for (int start_loop = 1; start_loop>0; start_loop++)
{
if (status_mode != "NONE")
{
for (int indexrow=0; indexrow<8; indexrow++)
{
for (int indexcol=0; indexcol<16;indexcol++)
{
cout << gameArray[indexrow][indexcol];
}
}
cout << endl;
}
cout << "Active Maze: " << status_mode << endl;
cout << "1. Select Standard Maze" << endl;
cout << "2. Select Custom Maze" << endl;
cout << "3. Find Path" << endl;
cout << "4. Print Path" << endl;
cout << "5. End " << endl;
cin >> choice;
if (choice == 1)
{
status_mode = "STANDARD";
inputStandard();
cout << "Standard Mode Selected!" << endl << endl;
}
if (choice == 2)
{
status_mode = "CUSTOM";
inputCustom();
cout << "Custom Mode Selected!" << endl << endl;
}
if (choice == 3)
{
findPath();
}
if (choice == 4)
{
cout << "DISABLED. " << endl << endl;
}
if (choice == 5)
{
cout << "EXITING!" << endl;
break;
}
if (!cin)
{
cout << "ERROR IN INPUT!" << endl;
}
}
}