aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ee1301/wk5/hw5_directory/mazeRunner_v1.cpp')
-rw-r--r--ee1301/wk5/hw5_directory/mazeRunner_v1.cpp15
1 files changed, 14 insertions, 1 deletions
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;
}