From c6f292b3a92d074163ce8221bd011c3af2ebac3a Mon Sep 17 00:00:00 2001 From: Zydan1 Date: Thu, 11 Jan 2018 19:53:52 +0100 Subject: [PATCH 1/4] 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/4] 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(); + +})(); From 98c4bc6128d496414226c5e5d949399381c1a987 Mon Sep 17 00:00:00 2001 From: Zydan1 Date: Thu, 11 Jan 2018 20:41:20 +0100 Subject: [PATCH 3/4] files is added --- ...er Could you please accept my pull request | 0 week3/final/robot-text/Hamza.md | 1 + week3/final/robot-text/robot.js | 54 ++++++++++++------- 3 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 week3/final/robot-text/ Hello teacher Could you please accept my pull request create mode 100644 week3/final/robot-text/Hamza.md diff --git a/week3/final/robot-text/ Hello teacher Could you please accept my pull request b/week3/final/robot-text/ Hello teacher Could you please accept my pull request new file mode 100644 index 0000000..e69de29 diff --git a/week3/final/robot-text/Hamza.md b/week3/final/robot-text/Hamza.md new file mode 100644 index 0000000..cfcdbed --- /dev/null +++ b/week3/final/robot-text/Hamza.md @@ -0,0 +1 @@ +hello teacher could you accept my pull request diff --git a/week3/final/robot-text/robot.js b/week3/final/robot-text/robot.js index f2eb96d..867d58f 100644 --- a/week3/final/robot-text/robot.js +++ b/week3/final/robot-text/robot.js @@ -1,22 +1,29 @@ -(function () { +((function () { '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 d13eefbcedcc57307020216683c899a06e12dd86 Mon Sep 17 00:00:00 2001 From: Zydan1 Date: Fri, 12 Jan 2018 20:37:57 +0100 Subject: [PATCH 4/4] change code --- week3/final/robot-text/robot.js | 34 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/week3/final/robot-text/robot.js b/week3/final/robot-text/robot.js index 867d58f..83852fd 100644 --- a/week3/final/robot-text/robot.js +++ b/week3/final/robot-text/robot.js @@ -2,25 +2,19 @@ 'use strict'; const board = [ - ['A', '.', '.', '.','.'], + ['.', '.', '.', '.','.'], ['.', '.', '.', '.','.'], ['R', '.', '.', '.','F'], - ['.', 'A', 'A', 'A','.'] - + ['.', 'A', 'A', 'A','.'], + ['.', '.', '.', '.','.'] ]; -console.log(board[2][0]); - - const robot = { x: 0, - y: 1, + y: 2, dir: 'down', }; - - let flagReached = false; let moves = 0; - let appleEaten = false; let applesEatenNum = 0; @@ -111,14 +105,14 @@ console.log(board[2][0]); break; } } - render(); -move(); -turn('left') -move(); -move(); -move(); -move(); -turn('left'); -move(); -})); \ No newline at end of file + move(); + turn('left'); + move(); + move(); + move(); + move(); + turn('left'); + move(); + +}()));