|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <fstream>
|
|
#include <string>
|
|
#include<iostream>
|
|
#include "Maze.h"
|
|
using namespace std;
|
|
|
|
|
|
void Maze::printMaze(int gameLevel)
|
|
{
|
|
ifstream inFile;
|
|
switch (gameLevel)
|
|
{
|
|
case 1:
|
|
inFile.open("map1.txt");
|
|
break;
|
|
case 2:
|
|
inFile.open("map2.txt");
|
|
break;
|
|
case 3:
|
|
inFile.open("map3.txt");
|
|
break;
|
|
}
|
|
|
|
int i = 0;
|
|
totalDot = 0;
|
|
str = new string[18];
|
|
if(inFile.is_open())
|
|
{
|
|
while(!inFile.eof())
|
|
{
|
|
getline(inFile, str[i]);
|
|
for(int a=0;a<21;a++)
|
|
{
|
|
cout << str[i][a];
|
|
}
|
|
cout << endl;
|
|
i++;
|
|
}
|
|
inFile.close();
|
|
}
|
|
else
|
|
cout << "Fail to open file" << endl;
|
|
}
|
|
|
|
char Maze::getMazeArray(int x, int y) const
|
|
{
|
|
char temp = str[y][x];
|
|
return temp;
|
|
}
|
|
|
|
void Maze::setMazeArray(int x, int y, char symbol)
|
|
{
|
|
str[y][x] = symbol;
|
|
}
|
|
|
|
void Maze::killArray()
|
|
{
|
|
delete []str;
|
|
}
|
|
|
|
|
|
int Maze::getTotalDot()
|
|
{
|
|
return totalDot;
|
|
}
|
|
|
|
|
|
void Maze::setTotalDot(int n)
|
|
{
|
|
totalDot += n ;
|
|
}
|
|
|
|
void Maze::checkTotalDot()
|
|
{
|
|
|
|
totalDot=0;
|
|
for(int i=0; i<18;i++)
|
|
{
|
|
for (int j=0; j<21; j++)
|
|
{
|
|
if (getMazeArray(j,i)=='.' || getMazeArray(j,i)=='X')
|
|
{
|
|
totalDot++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void Maze::mazeReset(int gameLevel)
|
|
{
|
|
printMaze(gameLevel);
|
|
}
|
|
|