From fc5c8a4646865aece1284e0db7d8eac6eafa99b4 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Mon, 1 Apr 2019 20:29:08 -0500 Subject: Finish A --- ee1301/wk5/hw5_directory/mazeRunner_v1.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'ee1301/wk5/hw5_directory/mazeRunner_v1.cpp') diff --git a/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp b/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp index c761e76..a938386 100644 --- a/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp +++ b/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp @@ -85,6 +85,11 @@ void initBoardCustom(char board[lengthX][lengthY], int &xPos, int &yPos) for (int curCol = 0; curCol < lengthX; curCol++) { fin >> board[curCol][curRow]; + if (board[curCol][curRow] == 'X') { + board[curCol][curRow] = ROBOT; + xPos = curCol; + yPos = curRow; + } } } @@ -118,7 +123,7 @@ void showGrid(char board[lengthX][lengthY]) { } void updateGrid(char board[lengthX][lengthY],int & xPos, int & yPos,char action) { - board[xPos][yPos] = BLANK; + int oldX = xPos; int oldY = yPos; if (action == 'l' && xPos > 0) { xPos--; } else if(action == 'r' && xPos < lengthX - 1) { @@ -128,5 +133,13 @@ void updateGrid(char board[lengthX][lengthY],int & xPos, int & yPos,char action) } else if(action == 'd' && yPos < lengthY - 1) { yPos++; } + //Hit detection + if (board[xPos][yPos] == WALL) { + xPos = oldX; + yPos = oldY; + board[xPos][yPos] = WALL; + } else { + board[oldX][oldY] = BLANK; + } board[xPos][yPos] = ROBOT; } -- cgit v1.2.3