/********************************************************************* C201 Computer Programming II Fall 2006 Dana Vrajitoru & A class to store a maze. **********************************************************************/ #include "maze.h" #include using namespace std; // Default constructor: initializes the maze to spaces in all the // cells. Maze::Maze() : player_x(0), player_y(0) { for (int i=0; i> table[x][y]; fin.close(); return true; } } // Inputs the maze from a file and returns true if it was succesful. void Maze::Random_player() { do { player_x = rand() % SIZE; player_y = rand() % SIZE; } while (table[player_x][player_y] == wall); } // Moves the player up by one case. If the player is already at the // top or if the next cell going up is a wall, the movement is not // performed and the function returns false. // player_y = player_y -1 bool Maze::Move_up() { if (player_y > 0 && table[player_x][player_y-1] != wall) { player_y = player_y -1; return true; } else return false; } // Moves in a direction specified by the char. If the movement is // not possible it returns false. bool Maze::Move(char dir) { switch (dir) { case 'i': case 'I': case 'w': case 'W': return Move_up(); default: return false; } } // Outputs the entire maze. ostream &operator<<(ostream &out, Maze &m) { for (int y=0; y>(istream &in, Cell_ty &c) { int n; in >> n; c = Cell_ty(n); return in; }