From c25f2f0342e9b8e652aafd56781ee4195d12f1e2 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Sun, 31 Mar 2019 21:43:55 -0500 Subject: DO not much really --- ee1301/wk5/hw5_directory/mazeRunner_v1.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'ee1301') diff --git a/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp b/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp index 8e6c3ee..d915549 100644 --- a/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp +++ b/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp @@ -1,4 +1,5 @@ #include +#include #include #include using namespace std; @@ -6,6 +7,7 @@ using namespace std; const char BLANK = '-'; const char ROBOT = 'X'; const char GOAL = 'O'; +const char WALL = 'W'; const int screen_num_lines = 25; const int lengthX = 10; // for now we only support square boards const int lengthY = 10; // it "should" work with non-square, YMMV @@ -25,6 +27,7 @@ void updateGrid(char board[lengthX][lengthY], int &xPos, int &yPos, char action) int main() { + srand(time(NULL)); char board[lengthX][lengthY] = {0}; int xPos = 0, yPos = 0; @@ -51,9 +54,15 @@ int main() void initBoard(char board[lengthX][lengthY], int &xPos, int &yPos) { for(int curRow=0; curRow < lengthY; curRow++) { for(int curCol=0; curCol < lengthX; curCol++) { - board[curCol][curRow] = BLANK; + 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; + } } } + board[0][0] = GOAL; board[lengthX/2][lengthY/2] = ROBOT; -- cgit v1.2.3