From c6f292b3a92d074163ce8221bd011c3af2ebac3a Mon Sep 17 00:00:00 2001 From: Zydan1 Date: Thu, 11 Jan 2018 19:53:52 +0100 Subject: [PATCH 1/2] robot game --- week3/final/robot-text/robot.js | 52 +++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/week3/final/robot-text/robot.js b/week3/final/robot-text/robot.js index f2eb96d..021e63b 100644 --- a/week3/final/robot-text/robot.js +++ b/week3/final/robot-text/robot.js @@ -2,21 +2,28 @@ 'use strict'; const board = [ - ['T', 'T', '.', 'F'], - ['T', '.', '.', '.'], - ['.', '.', '.', '.'], - ['R', '.', '.', 'W'] + ['A', '.', '.', '.','.'], + ['.', '.', '.', '.','.'], + ['R', '.', '.', '.','F'], + ['.', 'A', 'A', 'A','.'] + ]; +console.log(board[2][0]); + const robot = { x: 0, - y: 0, - dir: 'up', + y: 1, + dir: 'down', }; + let flagReached = false; let moves = 0; + let appleEaten = false; + let applesEatenNum = 0; + board.reverse(); const trailIndicators = { @@ -37,7 +44,11 @@ console.log(line); } if (flagReached) { - console.log('\nHurray! Flag reached in ' + moves + ' steps!'); + console.log('\nHurray! Flag reached in ' + moves + ' steps!' + ' and i did eat ' + applesEatenNum + ' apples' ); + } + if(appleEaten){ + console.log('Yum') ; + } } @@ -62,14 +73,19 @@ const cellContents = board[y][x]; - if (cellContents === '.' || cellContents === 'F') { + if (cellContents === '.' || cellContents === 'F' || cellContents === 'A') { board[robot.y][robot.x] = trailIndicators[robot.dir]; robot.x = x; robot.y = y; board[y][x] = 'R'; + if (cellContents === 'F') { flagReached = true; } + if(cellContents === 'A'){ + applesEatenNum+=1; + appleEaten = true; + } } moves += 1; @@ -97,14 +113,12 @@ } render(); - - move(); - turn('right'); - move(); - move(); - move(); - turn('left'); - move(); - move(); - -})(); +move(); +turn('left') +move(); +move(); +move(); +move(); +turn('left'); +move(); +})(); \ No newline at end of file From 217ecb3f3de8dc0d7e049cfa693f83628e03352f Mon Sep 17 00:00:00 2001 From: Zydan1 Date: Thu, 11 Jan 2018 20:07:05 +0100 Subject: [PATCH 2/2] changed --- week3/final/robot-text/robot.js | 52 ++++++++++++--------------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/week3/final/robot-text/robot.js b/week3/final/robot-text/robot.js index 021e63b..f2eb96d 100644 --- a/week3/final/robot-text/robot.js +++ b/week3/final/robot-text/robot.js @@ -2,28 +2,21 @@ 'use strict'; const board = [ - ['A', '.', '.', '.','.'], - ['.', '.', '.', '.','.'], - ['R', '.', '.', '.','F'], - ['.', 'A', 'A', 'A','.'] - + ['T', 'T', '.', 'F'], + ['T', '.', '.', '.'], + ['.', '.', '.', '.'], + ['R', '.', '.', 'W'] ]; -console.log(board[2][0]); - const robot = { x: 0, - y: 1, - dir: 'down', + y: 0, + dir: 'up', }; - let flagReached = false; let moves = 0; - let appleEaten = false; - let applesEatenNum = 0; - board.reverse(); const trailIndicators = { @@ -44,11 +37,7 @@ console.log(board[2][0]); console.log(line); } if (flagReached) { - console.log('\nHurray! Flag reached in ' + moves + ' steps!' + ' and i did eat ' + applesEatenNum + ' apples' ); - } - if(appleEaten){ - console.log('Yum') ; - + console.log('\nHurray! Flag reached in ' + moves + ' steps!'); } } @@ -73,19 +62,14 @@ console.log(board[2][0]); const cellContents = board[y][x]; - if (cellContents === '.' || cellContents === 'F' || cellContents === 'A') { + if (cellContents === '.' || cellContents === 'F') { board[robot.y][robot.x] = trailIndicators[robot.dir]; robot.x = x; robot.y = y; board[y][x] = 'R'; - if (cellContents === 'F') { flagReached = true; } - if(cellContents === 'A'){ - applesEatenNum+=1; - appleEaten = true; - } } moves += 1; @@ -113,12 +97,14 @@ console.log(board[2][0]); } render(); -move(); -turn('left') -move(); -move(); -move(); -move(); -turn('left'); -move(); -})(); \ No newline at end of file + + move(); + turn('right'); + move(); + move(); + move(); + turn('left'); + move(); + move(); + +})();