diff options
author | RossTheRoss <msattr@gmail.com> | 2019-04-01 11:06:07 -0500 |
---|---|---|
committer | RossTheRoss <msattr@gmail.com> | 2019-04-01 11:06:07 -0500 |
commit | 1f0036528393478007640698858eb6079dc8d2fe (patch) | |
tree | c21e68d45ef562e1867b76d6477f2d65401d46d0 /ee1301/wk5/hw5_directory/mazeRunner_v1.cpp | |
parent | DO not much really (diff) | |
download | homework-1f0036528393478007640698858eb6079dc8d2fe.tar homework-1f0036528393478007640698858eb6079dc8d2fe.tar.gz homework-1f0036528393478007640698858eb6079dc8d2fe.tar.bz2 homework-1f0036528393478007640698858eb6079dc8d2fe.tar.lz homework-1f0036528393478007640698858eb6079dc8d2fe.tar.xz homework-1f0036528393478007640698858eb6079dc8d2fe.tar.zst homework-1f0036528393478007640698858eb6079dc8d2fe.zip |
Start HW
Diffstat (limited to 'ee1301/wk5/hw5_directory/mazeRunner_v1.cpp')
-rw-r--r-- | ee1301/wk5/hw5_directory/mazeRunner_v1.cpp | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp b/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp index d915549..c761e76 100644 --- a/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp +++ b/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp @@ -3,6 +3,8 @@ #include <fstream> #include <string> using namespace std; +ifstream fin; +ofstream fout; const char BLANK = '-'; const char ROBOT = 'X'; @@ -18,7 +20,8 @@ const int lengthY = 10; // it "should" work with non-square, YMMV // V // +Y -void initBoard(char board[lengthX][lengthY], int &xPos, int &yPos); +void initBoardDefault(char board[lengthX][lengthY], int &xPos, int &yPos); +void initBoardCustom(char board[lengthX][lengthY], int &xPos, int &yPos); void clearScreen(); void showGrid(char board[lengthX][lengthY]); @@ -30,9 +33,13 @@ int main() srand(time(NULL)); char board[lengthX][lengthY] = {0}; int xPos = 0, yPos = 0; - - initBoard(board, xPos, yPos); - + fin.open("maze.txt"); //maze.txt is in the directory that it is run in + if (!fin.is_open()) //If a custom maze does not exist, generate one automatically + { + initBoardDefault(board, xPos, yPos); + } else { + initBoardCustom(board, xPos, yPos); + } while(hasChar(board, GOAL)) { char action; @@ -51,11 +58,11 @@ int main() return 0; } -void initBoard(char board[lengthX][lengthY], int &xPos, int &yPos) { +//The default (no custom file) maze is procedurally generated +void initBoardDefault(char board[lengthX][lengthY], int &xPos, int &yPos) { for(int curRow=0; curRow < lengthY; curRow++) { for(int curCol=0; curCol < lengthX; curCol++) { if ( (rand() % 5) + 1 == 4 || (rand() % 10) + 1 == 7) { - //Procedural generation is best for a game like this even if it makes the game impossible board[curCol][curRow] = WALL; } else { board[curCol][curRow] = BLANK; @@ -71,6 +78,18 @@ void initBoard(char board[lengthX][lengthY], int &xPos, int &yPos) { yPos = lengthY/2; } +void initBoardCustom(char board[lengthX][lengthY], int &xPos, int &yPos) +{ + for (int curRow = 0; curRow < lengthY; curRow++) + { + for (int curCol = 0; curCol < lengthX; curCol++) + { + fin >> board[curCol][curRow]; + } + } + +} + bool hasChar(char board[lengthX][lengthY], char findMe) { for(int curRow=0; curRow < lengthY; curRow++) { for(int curCol=0; curCol < lengthX; curCol++) { |