aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk5/hw5_directory/mazeRunner_v1.cpp
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-04-01 20:29:08 -0500
committerRossTheRoss <msattr@gmail.com>2019-04-01 20:29:08 -0500
commitfc5c8a4646865aece1284e0db7d8eac6eafa99b4 (patch)
tree8a719f964c673aed4846e19967f439de97a65c35 /ee1301/wk5/hw5_directory/mazeRunner_v1.cpp
parentStart HW (diff)
downloadhomework-fc5c8a4646865aece1284e0db7d8eac6eafa99b4.tar
homework-fc5c8a4646865aece1284e0db7d8eac6eafa99b4.tar.gz
homework-fc5c8a4646865aece1284e0db7d8eac6eafa99b4.tar.bz2
homework-fc5c8a4646865aece1284e0db7d8eac6eafa99b4.tar.lz
homework-fc5c8a4646865aece1284e0db7d8eac6eafa99b4.tar.xz
homework-fc5c8a4646865aece1284e0db7d8eac6eafa99b4.tar.zst
homework-fc5c8a4646865aece1284e0db7d8eac6eafa99b4.zip
Finish A
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;
}