/* Name:Wong Pui Shan Sdutent ID:52611804 program: AScISD Name: HAR Chiu Kwong Samson Sdutent ID:52629360 program: AScISD Name: LAM Cheuk Man Sdutent ID:52621140 program: AScISD Name:KO Jeffrey KO Sdutent ID:525 695 30 program: AScISD */ #include #include #include #include "Maze.h" using namespace std; void Maze::printMaze(int gameLevel) { ifstream inFile; switch (gameLevel) { case 1: inFile.open("map1.txt"); // open the file break; case 2: inFile.open("map2.txt"); // open the file break; case 3: inFile.open("map3.txt"); // open the file break; } int i = 0; totalDot = 0; str = new string[18]; if(inFile.is_open()) // check if the file could be open { while(!inFile.eof()) // not end of file { getline(inFile, str[i]); // obtain a line of text from file for(int a=0;a<21;a++) { cout << str[i][a]; } cout << endl; i++; } inFile.close(); // close the file } 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() { //count the total amount of Dot in the Maze 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); }