From d388e41d35c4f403e8ec2e38838272fafb49c324 Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 19 Oct 2022 16:40:46 +0100 Subject: [PATCH 01/36] Add Hello World --- web/src/App.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/src/App.tsx b/web/src/App.tsx index 4ff136d..5626bcd 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -3,6 +3,12 @@ import './App.css'; import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; +function helloWorld(){ + console.log("Hello World") +} + +helloWorld() + function App() { return (
From 768b3cafe43d11626884634ce04a425c73dee32f Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 19 Oct 2022 16:49:41 +0100 Subject: [PATCH 02/36] Improvement, helloWorld into its own class --- web/src/App.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 5626bcd..9f7c486 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -3,11 +3,19 @@ import './App.css'; import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; -function helloWorld(){ - console.log("Hello World") +class SnakeEngine{ + + static helloWorld(){ + + function helloWorld(){ + console.log("Hello World") + } + + } } -helloWorld() +SnakeEngine.helloWorld() + function App() { return ( From e60bca5767a97a7d948f51622c47913437da6d88 Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 19 Oct 2022 16:54:32 +0100 Subject: [PATCH 03/36] Change " to ' --- web/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 5626bcd..96c466a 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -4,7 +4,7 @@ import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; function helloWorld(){ - console.log("Hello World") + console.log('Hello World') } helloWorld() From a185da36c1a7376f9b13de1fd5bada8af59fec79 Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 19 Oct 2022 16:55:38 +0100 Subject: [PATCH 04/36] Update web/src/App.tsx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- web/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 96c466a..387133e 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -3,7 +3,7 @@ import './App.css'; import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; -function helloWorld(){ +function helloWorld() { console.log('Hello World') } From 9c7b3193da6244efbc7f1a56a1e7947189b80161 Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 19 Oct 2022 16:56:15 +0100 Subject: [PATCH 05/36] Update web/src/App.tsx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- web/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 387133e..c43262c 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -4,7 +4,7 @@ import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; function helloWorld() { - console.log('Hello World') + console.log('Hello World'); } helloWorld() From 492bf8e957cdfebb8285b021dbdbe18b6b88abf6 Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:04:32 +0100 Subject: [PATCH 06/36] Update web/src/App.tsx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- web/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index a64e0b3..9003091 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -9,7 +9,7 @@ class SnakeEngine{ console.log("Hello World") } } -SnakeEngine.helloWorld() +SnakeEngine.helloWorld(); function App() { From 94e3f884b37b47619addd4f57b86096723b3a86b Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:05:04 +0100 Subject: [PATCH 07/36] Update web/src/App.tsx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- web/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 9003091..ea49aca 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -6,7 +6,7 @@ import IncrementButton from './IncrementButton'; class SnakeEngine{ static helloWorld(){ - console.log("Hello World") + console.log('Hello World') } } SnakeEngine.helloWorld(); From 627d83fb4d8d2e28553e09350e48b979c0ecb3ff Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:05:15 +0100 Subject: [PATCH 08/36] Update web/src/App.tsx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- web/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index ea49aca..27beca8 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -5,7 +5,7 @@ import IncrementButton from './IncrementButton'; class SnakeEngine{ - static helloWorld(){ + static helloWorld() { console.log('Hello World') } } From 47315b776e85173ccea7d3a5d05767d7f3c1ff2e Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:05:30 +0100 Subject: [PATCH 09/36] Update web/src/App.tsx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- web/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 27beca8..e7a67dc 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -3,7 +3,7 @@ import './App.css'; import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; -class SnakeEngine{ +class SnakeEngine { static helloWorld() { console.log('Hello World') From 83404cc5d90aad25683f9b4779c0153fe459f0af Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:05:49 +0100 Subject: [PATCH 10/36] Update web/src/App.tsx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- web/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index e7a67dc..98659fa 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -6,7 +6,7 @@ import IncrementButton from './IncrementButton'; class SnakeEngine { static helloWorld() { - console.log('Hello World') + console.log('Hello World'); } } SnakeEngine.helloWorld(); From 91897898b7827cb113ceb6bb3066ffa16e98113d Mon Sep 17 00:00:00 2001 From: Halceeyon Date: Wed, 19 Oct 2022 17:08:35 +0100 Subject: [PATCH 11/36] Created SnakeEngine.ts --- web/src/App.tsx | 7 +------ web/src/SnakeEngine/SnakeEngine.ts | 6 ++++++ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 web/src/SnakeEngine/SnakeEngine.ts diff --git a/web/src/App.tsx b/web/src/App.tsx index a64e0b3..02fe273 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -2,13 +2,8 @@ import './App.css'; import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; +import {SnakeEngine} from './SnakeEngine/SnakeEngine'; -class SnakeEngine{ - - static helloWorld(){ - console.log("Hello World") - } -} SnakeEngine.helloWorld() diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts new file mode 100644 index 0000000..daca6f7 --- /dev/null +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -0,0 +1,6 @@ +export class SnakeEngine{ + + static helloWorld(){ + console.log("Hello World") + } + } \ No newline at end of file From 109a849872843fc46e2ad8fd30c7c7158d10c0e5 Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:09:23 +0100 Subject: [PATCH 12/36] fixed linting --- web/src/App.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 98659fa..51ae92b 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,10 +1,8 @@ import './App.css'; - import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; class SnakeEngine { - static helloWorld() { console.log('Hello World'); } From 19591d02958742f631e0e10a00651f14b9620c14 Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:27:48 +0100 Subject: [PATCH 13/36] formatted --- web/src/App.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 0d92d57..08d6815 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,10 +1,9 @@ import './App.css'; import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; -import {SnakeEngine} from './SnakeEngine/SnakeEngine'; - -SnakeEngine.helloWorld() +import { SnakeEngine } from './SnakeEngine/SnakeEngine'; +SnakeEngine.helloWorld(); function App() { return ( @@ -18,14 +17,16 @@ function App() {

Vite + React

-
+

Edit src/App.tsx and save to test HMR

-

Click on the Vite and React logos to learn more

+

+ Click on the Vite and React logos to learn more +

); } From f3d6c9b40ff9c673fc6c2875bfe8a5c90a30b738 Mon Sep 17 00:00:00 2001 From: Halceeyon Date: Wed, 19 Oct 2022 17:30:49 +0100 Subject: [PATCH 14/36] Update App.tsx --- web/src/App.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 0d92d57..08d6815 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,10 +1,9 @@ import './App.css'; import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; -import {SnakeEngine} from './SnakeEngine/SnakeEngine'; - -SnakeEngine.helloWorld() +import { SnakeEngine } from './SnakeEngine/SnakeEngine'; +SnakeEngine.helloWorld(); function App() { return ( @@ -18,14 +17,16 @@ function App() {

Vite + React

-
+

Edit src/App.tsx and save to test HMR

-

Click on the Vite and React logos to learn more

+

+ Click on the Vite and React logos to learn more +

); } From 91fa84a691e4f669ee5f809240044aa66171b9c6 Mon Sep 17 00:00:00 2001 From: Mark Chittenden <41925735+mark-chit@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:50:36 +0100 Subject: [PATCH 15/36] =?UTF-8?q?Added=20board=20and=20snake=20?= =?UTF-8?q?=F0=9F=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/SnakeEngine/SnakeEngine.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index daca6f7..8bafc1b 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -1,6 +1,17 @@ -export class SnakeEngine{ +export class SnakeEngine { + static board = []; + static snake = { + length: 3, + body: [ + { x: 0, y: 0 }, + { x: 1, y: 0 }, + { x: 2, y: 0 }, + ], - static helloWorld(){ - console.log("Hello World") - } - } \ No newline at end of file + direction: 'right', + }; + + static helloWorld() { + console.log('Hello World'); + } +} From 7f86b886999844c47af09f2e74fdf4171326830d Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:55:29 +0100 Subject: [PATCH 16/36] Update web/src/App.tsx Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- web/src/App.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 0d92d57..aaed28a 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,7 +1,7 @@ import './App.css'; import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; -import {SnakeEngine} from './SnakeEngine/SnakeEngine'; +import {SnakeEngine } from './SnakeEngine/SnakeEngine'; SnakeEngine.helloWorld() From bfe0ce8b3c3e114fa3850f07d2cd6785fbb2b02c Mon Sep 17 00:00:00 2001 From: Mark Chittenden <41925735+mark-chit@users.noreply.github.com> Date: Wed, 19 Oct 2022 18:44:02 +0100 Subject: [PATCH 17/36] Update App.tsx --- web/src/App.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index aaed28a..08d6815 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,10 +1,9 @@ import './App.css'; import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; -import {SnakeEngine } from './SnakeEngine/SnakeEngine'; - -SnakeEngine.helloWorld() +import { SnakeEngine } from './SnakeEngine/SnakeEngine'; +SnakeEngine.helloWorld(); function App() { return ( @@ -18,14 +17,16 @@ function App() {

Vite + React

-
+

Edit src/App.tsx and save to test HMR

-

Click on the Vite and React logos to learn more

+

+ Click on the Vite and React logos to learn more +

); } From 0dcea24c7d6ec40d51e553d536989ccc22ac29aa Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Mon, 24 Oct 2022 12:53:44 +0100 Subject: [PATCH 18/36] Update App.tsx --- web/src/App.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index 0d92d57..08d6815 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,10 +1,9 @@ import './App.css'; import reactLogo from './assets/react.svg'; import IncrementButton from './IncrementButton'; -import {SnakeEngine} from './SnakeEngine/SnakeEngine'; - -SnakeEngine.helloWorld() +import { SnakeEngine } from './SnakeEngine/SnakeEngine'; +SnakeEngine.helloWorld(); function App() { return ( @@ -18,14 +17,16 @@ function App() {

Vite + React

-
+

Edit src/App.tsx and save to test HMR

-

Click on the Vite and React logos to learn more

+

+ Click on the Vite and React logos to learn more +

); } From bf209ee1c38a61eb379b589bb66b1d65d790828b Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:14:13 +0100 Subject: [PATCH 19/36] Added controller --- web/src/SnakeEngine/SnakeEngine.ts | 48 ++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index 8bafc1b..e1ab49a 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -1,5 +1,9 @@ +class Constants { + static SnakeSpeed = 2; +} + export class SnakeEngine { - static board = []; + board = []; static snake = { length: 3, body: [ @@ -7,11 +11,49 @@ export class SnakeEngine { { x: 1, y: 0 }, { x: 2, y: 0 }, ], - direction: 'right', }; static helloWorld() { - console.log('Hello World'); + const speed = new Constants(); + console.log(speed); + } + + static model() { + switch (SnakeEngine.snake.direction) { + case 'up': + break; + case 'down': + break; + case 'left': + break; + case 'right': + break; + default: + } + } + + static controller() { + document.addEventListener('keydown', parseInput); + function parseInput(e: { key: string}) { + switch (e.key) { + case 'ArrowUp': + SnakeEngine.snake.direction = 'up'; + break; + case 'w': + SnakeEngine.snake.direction = 'up'; + break; + case 'a': + SnakeEngine.snake.direction = 'left'; + break; + case 's': + SnakeEngine.snake.direction = 'down'; + break; + case 'd': + SnakeEngine.snake.direction = 'right'; + break; + default: + } + } } } From 59ce233cd26f20f1307baeb13e93aadb826a4f59 Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:47:22 +0100 Subject: [PATCH 20/36] Snake Now moves --- web/src/SnakeEngine/SnakeEngine.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index e1ab49a..1b935aa 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -20,17 +20,28 @@ export class SnakeEngine { } static model() { + const newSnakeHead = SnakeEngine.snake.body[SnakeEngine.snake.length - 1]; + let x = newSnakeHead.x; + let y = newSnakeHead.y; switch (SnakeEngine.snake.direction) { case 'up': + y = y - 1; break; case 'down': + y = y + 1; break; case 'left': + x = x - 1; break; case 'right': + x = x + 1; break; default: } + newSnakeHead.y = y; + newSnakeHead.x = x; + SnakeEngine.snake.body.push(newSnakeHead); + SnakeEngine.snake.body.shift(); } static controller() { From 1f25614e16445a440b3b82b4be5ceda9f48ca7e1 Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 9 Nov 2022 13:06:43 +0000 Subject: [PATCH 21/36] View prototype --- web/src/SnakeEngine/SnakeEngine.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index 1b935aa..2ae982c 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -19,6 +19,27 @@ export class SnakeEngine { console.log(speed); } + static view() { + const board = []; + const size = 10; + let row = ''; + const x = SnakeEngine.snake.body[this.length].x; + const y = SnakeEngine.snake.body[this.length].y; + for (let ycord = 0; ycord < size; ycord++) { + for (let xcord = 0; xcord < size; xcord++) { + if (xcord === x && ycord === y) { + row += 'S'; + } else { + row += '0'; + } + } + board.push(row); + } + for (let i = 0; i < board.length - 1; i++) { + console.log(board[i]); + } + } + static model() { const newSnakeHead = SnakeEngine.snake.body[SnakeEngine.snake.length - 1]; let x = newSnakeHead.x; From 88a586384e8527678ceac061d95810a8dbd2dcbb Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:02:05 +0000 Subject: [PATCH 22/36] prototype board code --- web/src/SnakeEngine/SnakeEngine.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index 2ae982c..8262239 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -14,6 +14,16 @@ export class SnakeEngine { direction: 'right', }; + static boardGenerator() { + const board = []; + let row = ''; + for (let i = 0; i < 10; i++) { + row += `${'0'.repeat(10)}`; + board.push(row); + } + return board; + } + static helloWorld() { const speed = new Constants(); console.log(speed); @@ -62,7 +72,7 @@ export class SnakeEngine { newSnakeHead.y = y; newSnakeHead.x = x; SnakeEngine.snake.body.push(newSnakeHead); - SnakeEngine.snake.body.shift(); + const oldTail = SnakeEngine.snake.body.shift(); } static controller() { From c94305c519a435875d8ae1a7da4362d91135957b Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:21:04 +0000 Subject: [PATCH 23/36] V4 --- web/src/SnakeEngine/SnakeEngine.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index 8262239..fa7d3a7 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -24,6 +24,12 @@ export class SnakeEngine { return board; } + static AddToBoard(y: number, x: number, board: Array) { + const row = board[y]; + const a = row.split(''); + a[x] = 'S'; + } + static helloWorld() { const speed = new Constants(); console.log(speed); From cd80df10d4510bcd137a676f73f0720bca864079 Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:25:09 +0000 Subject: [PATCH 24/36] AddToBoard --- web/src/SnakeEngine/SnakeEngine.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index fa7d3a7..bf86886 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -28,6 +28,8 @@ export class SnakeEngine { const row = board[y]; const a = row.split(''); a[x] = 'S'; + board[y] = a.toString(); + return board; } static helloWorld() { From 16d5ca08dcac0c0d81853a7efa8a8f8f7ff7120d Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:28:01 +0000 Subject: [PATCH 25/36] UpdateBoard --- web/src/SnakeEngine/SnakeEngine.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index bf86886..1fc0534 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -24,10 +24,10 @@ export class SnakeEngine { return board; } - static AddToBoard(y: number, x: number, board: Array) { + static UpdateBoard(y: number, x: number, board: Array, add: boolean) { const row = board[y]; const a = row.split(''); - a[x] = 'S'; + add ? a[x] = 'S' : a[x] = '0'; // add if true remove if false board[y] = a.toString(); return board; } From 37af2336195632bb47760e219da24568cd803de6 Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:40:43 +0000 Subject: [PATCH 26/36] Updated View --- web/src/SnakeEngine/SnakeEngine.ts | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index 1fc0534..994d271 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -3,7 +3,7 @@ class Constants { } export class SnakeEngine { - board = []; + static board = this.boardGenerator(); static snake = { length: 3, body: [ @@ -21,6 +21,9 @@ export class SnakeEngine { row += `${'0'.repeat(10)}`; board.push(row); } + this.UpdateBoard(0, 0, board, true); + this.UpdateBoard(0, 1, board, true); + this.UpdateBoard(0, 2, board, true); return board; } @@ -37,22 +40,7 @@ export class SnakeEngine { console.log(speed); } - static view() { - const board = []; - const size = 10; - let row = ''; - const x = SnakeEngine.snake.body[this.length].x; - const y = SnakeEngine.snake.body[this.length].y; - for (let ycord = 0; ycord < size; ycord++) { - for (let xcord = 0; xcord < size; xcord++) { - if (xcord === x && ycord === y) { - row += 'S'; - } else { - row += '0'; - } - } - board.push(row); - } + static view(board: Array) { for (let i = 0; i < board.length - 1; i++) { console.log(board[i]); } @@ -80,7 +68,9 @@ export class SnakeEngine { newSnakeHead.y = y; newSnakeHead.x = x; SnakeEngine.snake.body.push(newSnakeHead); - const oldTail = SnakeEngine.snake.body.shift(); + this.UpdateBoard(y, x, SnakeEngine.board, true); + const oldTail = SnakeEngine.snake.body.shift() as { x: number, y: number }; + this.UpdateBoard(oldTail.y, oldTail.x, SnakeEngine.board, false); } static controller() { From 1d3b96d7232a75f559edf35382278e9734c0c979 Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 9 Nov 2022 17:47:34 +0000 Subject: [PATCH 27/36] Main SudoCode --- web/src/SnakeEngine/SnakeEngine.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index 994d271..8162e60 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -96,4 +96,12 @@ export class SnakeEngine { } } } + + static main() { + console.log('Get input'); + console.log('Get next Frame'); + console.log('Update View'); + return null; + } } +SnakeEngine.main(); From daef1225248c5a1b71dca898ba4ec675052b5dec Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 16 Nov 2022 16:33:11 +0000 Subject: [PATCH 28/36] Main Loop v1 --- web/src/SnakeEngine/SnakeEngine.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index 8162e60..9a0293a 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -4,6 +4,7 @@ class Constants { export class SnakeEngine { static board = this.boardGenerator(); + static gameOver = false static snake = { length: 3, body: [ @@ -99,9 +100,19 @@ export class SnakeEngine { static main() { console.log('Get input'); - console.log('Get next Frame'); - console.log('Update View'); + this.controller(); + + const interval = setInterval(this.newFrame, 500); + if (SnakeEngine.gameOver === true) { + clearInterval(interval); + } + return null; } + + static newFrame = () => { + this.model(); + this.view(SnakeEngine.board); + } } SnakeEngine.main(); From 0548532f59601050d8cc49a4811d2e89aa926b0d Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 16 Nov 2022 17:49:00 +0000 Subject: [PATCH 29/36] generates board every time it is viewed --- web/src/SnakeEngine/SnakeEngine.ts | 41 ++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index 9a0293a..6dac5b7 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -3,7 +3,6 @@ class Constants { } export class SnakeEngine { - static board = this.boardGenerator(); static gameOver = false static snake = { length: 3, @@ -15,24 +14,38 @@ export class SnakeEngine { direction: 'right', }; + static board = this.boardGenerator(); + static boardGenerator() { - const board = []; - let row = ''; - for (let i = 0; i < 10; i++) { - row += `${'0'.repeat(10)}`; + const board: string[] = []; + for (let i = 0; i < 10 - 1; i++) { + let row = ''; + for (let j = 0; j < 10 - 1; j++) { + row += '0'; + } board.push(row); } - this.UpdateBoard(0, 0, board, true); - this.UpdateBoard(0, 1, board, true); - this.UpdateBoard(0, 2, board, true); + SnakeEngine.snake.body.forEach(element => { + this.UpdateBoard(element.y, element.x, board, true); + }); + // this.UpdateBoard(0, 0, board, true); + // this.UpdateBoard(0, 1, board, true); + // this.UpdateBoard(0, 2, board, true); return board; } static UpdateBoard(y: number, x: number, board: Array, add: boolean) { const row = board[y]; + // console.log('y:'); + // console.log(y); const a = row.split(''); - add ? a[x] = 'S' : a[x] = '0'; // add if true remove if false - board[y] = a.toString(); + if (add === true) { + a[x] = 'S'; + } else { + a[x] = '0'; + } + // add ? a[x] = 'S' : a[x] = '0'; // add if true remove if false + board[y] = a.join(''); return board; } @@ -42,6 +55,7 @@ export class SnakeEngine { } static view(board: Array) { + SnakeEngine.board = this.boardGenerator(); for (let i = 0; i < board.length - 1; i++) { console.log(board[i]); } @@ -68,10 +82,10 @@ export class SnakeEngine { } newSnakeHead.y = y; newSnakeHead.x = x; + SnakeEngine.snake.body.shift(); SnakeEngine.snake.body.push(newSnakeHead); - this.UpdateBoard(y, x, SnakeEngine.board, true); - const oldTail = SnakeEngine.snake.body.shift() as { x: number, y: number }; - this.UpdateBoard(oldTail.y, oldTail.x, SnakeEngine.board, false); + // this.UpdateBoard(oldTail.y, oldTail.x, SnakeEngine.board, false); + // this.UpdateBoard(y, x, SnakeEngine.board, true); } static controller() { @@ -101,6 +115,7 @@ export class SnakeEngine { static main() { console.log('Get input'); this.controller(); + // this.newFrame(); const interval = setInterval(this.newFrame, 500); if (SnakeEngine.gameOver === true) { From c2370ff84be714f3ac0264772f2f506dc5f43c1d Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 16 Nov 2022 17:58:20 +0000 Subject: [PATCH 30/36] generation v2 --- web/src/SnakeEngine/SnakeEngine.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index 6dac5b7..c741ebf 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -5,7 +5,7 @@ class Constants { export class SnakeEngine { static gameOver = false static snake = { - length: 3, + // length: 3, body: [ { x: 0, y: 0 }, { x: 1, y: 0 }, @@ -18,9 +18,9 @@ export class SnakeEngine { static boardGenerator() { const board: string[] = []; - for (let i = 0; i < 10 - 1; i++) { + for (let i = 0; i < 10; i++) { let row = ''; - for (let j = 0; j < 10 - 1; j++) { + for (let j = 0; j < 10; j++) { row += '0'; } board.push(row); @@ -36,8 +36,6 @@ export class SnakeEngine { static UpdateBoard(y: number, x: number, board: Array, add: boolean) { const row = board[y]; - // console.log('y:'); - // console.log(y); const a = row.split(''); if (add === true) { a[x] = 'S'; @@ -55,14 +53,14 @@ export class SnakeEngine { } static view(board: Array) { - SnakeEngine.board = this.boardGenerator(); + SnakeEngine.board = this.boardGenerator(); // board is generated for (let i = 0; i < board.length - 1; i++) { console.log(board[i]); } } static model() { - const newSnakeHead = SnakeEngine.snake.body[SnakeEngine.snake.length - 1]; + const newSnakeHead = SnakeEngine.snake.body[SnakeEngine.snake.body.length - 1]; // change to slice let x = newSnakeHead.x; let y = newSnakeHead.y; switch (SnakeEngine.snake.direction) { From 1154a3a895d047f5ce899add2e3f9c767f1a8f31 Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Sat, 19 Nov 2022 16:29:25 +0000 Subject: [PATCH 31/36] Error fix, with coords printed to console. --- web/src/SnakeEngine/SnakeEngine.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index c741ebf..9dbc52a 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -27,6 +27,7 @@ export class SnakeEngine { } SnakeEngine.snake.body.forEach(element => { this.UpdateBoard(element.y, element.x, board, true); + console.log('BoardGen x: ', element.x, 'y: ', element.y); }); // this.UpdateBoard(0, 0, board, true); // this.UpdateBoard(0, 1, board, true); @@ -36,6 +37,7 @@ export class SnakeEngine { static UpdateBoard(y: number, x: number, board: Array, add: boolean) { const row = board[y]; + console.log('Update x: ', x, 'y: ', y); const a = row.split(''); if (add === true) { a[x] = 'S'; @@ -60,9 +62,9 @@ export class SnakeEngine { } static model() { - const newSnakeHead = SnakeEngine.snake.body[SnakeEngine.snake.body.length - 1]; // change to slice - let x = newSnakeHead.x; - let y = newSnakeHead.y; + // const newSnakeHead = SnakeEngine.snake.body[SnakeEngine.snake.body.length - 1]; // change to slice + let x = SnakeEngine.snake.body[SnakeEngine.snake.body.length - 1].x; + let y = SnakeEngine.snake.body[SnakeEngine.snake.body.length - 1].y; switch (SnakeEngine.snake.direction) { case 'up': y = y - 1; @@ -78,8 +80,10 @@ export class SnakeEngine { break; default: } - newSnakeHead.y = y; - newSnakeHead.x = x; + const newSnakeHead = { x: x, y: y }; + // newSnakeHead.y = y; + // newSnakeHead.x = x; + console.log('Model x; ', x, 'Model y: ', y); SnakeEngine.snake.body.shift(); SnakeEngine.snake.body.push(newSnakeHead); // this.UpdateBoard(oldTail.y, oldTail.x, SnakeEngine.board, false); @@ -114,6 +118,7 @@ export class SnakeEngine { console.log('Get input'); this.controller(); // this.newFrame(); + this.view(SnakeEngine.board); const interval = setInterval(this.newFrame, 500); if (SnakeEngine.gameOver === true) { From 6cd8d7f306f381a596ca58d379214eaf37a0c625 Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 23 Nov 2022 16:26:22 +0000 Subject: [PATCH 32/36] Board Wrapping Added and console cleared in view --- web/src/SnakeEngine/SnakeEngine.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index 9dbc52a..aa4a569 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -37,7 +37,7 @@ export class SnakeEngine { static UpdateBoard(y: number, x: number, board: Array, add: boolean) { const row = board[y]; - console.log('Update x: ', x, 'y: ', y); + // console.log('Update x: ', x, 'y: ', y); const a = row.split(''); if (add === true) { a[x] = 'S'; @@ -55,7 +55,8 @@ export class SnakeEngine { } static view(board: Array) { - SnakeEngine.board = this.boardGenerator(); // board is generated + SnakeEngine.board = this.boardGenerator(); + console.clear(); // board is generated for (let i = 0; i < board.length - 1; i++) { console.log(board[i]); } @@ -68,22 +69,34 @@ export class SnakeEngine { switch (SnakeEngine.snake.direction) { case 'up': y = y - 1; + if (y < 0) { + y = 9; + } break; case 'down': y = y + 1; + if (y > 9) { + y = 0; + } break; case 'left': x = x - 1; + if (x < 0) { + x = 9; + } break; case 'right': x = x + 1; + if (x > 9) { + x = 0; + } break; default: } const newSnakeHead = { x: x, y: y }; // newSnakeHead.y = y; // newSnakeHead.x = x; - console.log('Model x; ', x, 'Model y: ', y); + // console.log('Model x; ', x, 'Model y: ', y); SnakeEngine.snake.body.shift(); SnakeEngine.snake.body.push(newSnakeHead); // this.UpdateBoard(oldTail.y, oldTail.x, SnakeEngine.board, false); @@ -115,7 +128,7 @@ export class SnakeEngine { } static main() { - console.log('Get input'); + // console.log('Get input'); this.controller(); // this.newFrame(); this.view(SnakeEngine.board); From e2f5afbb2cc2ecd6e3596755d57f1dd5945416a2 Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 23 Nov 2022 16:35:36 +0000 Subject: [PATCH 33/36] added new lines --- web/src/SnakeEngine/SnakeEngine.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index aa4a569..fa47e2c 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -55,11 +55,13 @@ export class SnakeEngine { } static view(board: Array) { - SnakeEngine.board = this.boardGenerator(); - console.clear(); // board is generated + SnakeEngine.board = this.boardGenerator(); // board is generated + console.clear(); + let boardString = ''; for (let i = 0; i < board.length - 1; i++) { - console.log(board[i]); + boardString += board[i] + '\n'; } + console.log(boardString); } static model() { From 6d273b0ff1b3bcbc01bc8c189237178942ce5af2 Mon Sep 17 00:00:00 2001 From: Jonas Oppong <114658990+Jonas-Oppong@users.noreply.github.com> Date: Wed, 30 Nov 2022 18:01:04 +0000 Subject: [PATCH 34/36] food --- web/src/SnakeEngine/SnakeEngine.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index fa47e2c..3689a59 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -4,6 +4,7 @@ class Constants { export class SnakeEngine { static gameOver = false + static food = { x: SnakeEngine.randomCoord(), y: SnakeEngine.randomCoord() } static snake = { // length: 3, body: [ @@ -16,6 +17,10 @@ export class SnakeEngine { static board = this.boardGenerator(); + static randomCoord() { + return Math.floor(Math.random() * (9 - 0)) + 0; + } + static boardGenerator() { const board: string[] = []; for (let i = 0; i < 10; i++) { @@ -35,14 +40,14 @@ export class SnakeEngine { return board; } - static UpdateBoard(y: number, x: number, board: Array, add: boolean) { + static UpdateBoard(y: number, x: number, board: Array, snake: boolean) { const row = board[y]; // console.log('Update x: ', x, 'y: ', y); const a = row.split(''); - if (add === true) { + if (snake === true) { a[x] = 'S'; } else { - a[x] = '0'; + a[x] = 'F'; } // add ? a[x] = 'S' : a[x] = '0'; // add if true remove if false board[y] = a.join(''); From ac4e0c579fe7ab162ff5b7e3d44d20aa124ac7ce Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 7 Dec 2022 16:25:41 +0000 Subject: [PATCH 35/36] Added Food --- web/src/SnakeEngine/SnakeEngine.ts | 35 +++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index 3689a59..2fe8a34 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -3,8 +3,9 @@ class Constants { } export class SnakeEngine { + static boardSize = 9; static gameOver = false - static food = { x: SnakeEngine.randomCoord(), y: SnakeEngine.randomCoord() } + static food = { x: 0, y: 0 } static snake = { // length: 3, body: [ @@ -18,7 +19,7 @@ export class SnakeEngine { static board = this.boardGenerator(); static randomCoord() { - return Math.floor(Math.random() * (9 - 0)) + 0; + return Math.floor(Math.random() * (SnakeEngine.boardSize + 1)); } static boardGenerator() { @@ -34,6 +35,7 @@ export class SnakeEngine { this.UpdateBoard(element.y, element.x, board, true); console.log('BoardGen x: ', element.x, 'y: ', element.y); }); + this.UpdateBoard(SnakeEngine.food.y, SnakeEngine.food.x, board, false); // this.UpdateBoard(0, 0, board, true); // this.UpdateBoard(0, 1, board, true); // this.UpdateBoard(0, 2, board, true); @@ -104,8 +106,10 @@ export class SnakeEngine { // newSnakeHead.y = y; // newSnakeHead.x = x; // console.log('Model x; ', x, 'Model y: ', y); - SnakeEngine.snake.body.shift(); SnakeEngine.snake.body.push(newSnakeHead); + if (SnakeEngine.foodEaten() === false) { + SnakeEngine.snake.body.shift(); + } // this.UpdateBoard(oldTail.y, oldTail.x, SnakeEngine.board, false); // this.UpdateBoard(y, x, SnakeEngine.board, true); } @@ -134,7 +138,32 @@ export class SnakeEngine { } } + static foodEaten() { + for (const cell of SnakeEngine.snake.body) { + if (cell.x === SnakeEngine.food.x && cell.y === SnakeEngine.food.y) { + SnakeEngine.randomiseFood(); + return true; + } + } + return false; + } + + static randomiseFood() { + let valid = false; + while (valid === false) { + valid = true; + SnakeEngine.food.x = SnakeEngine.randomCoord(); + SnakeEngine.food.y = SnakeEngine.randomCoord(); + for (const cell of SnakeEngine.snake.body) { + if (cell.x === SnakeEngine.food.x && cell.y === SnakeEngine.food.y) { + valid = false; + } + } + } + } + static main() { + SnakeEngine.randomiseFood(); // console.log('Get input'); this.controller(); // this.newFrame(); From 4974d87f87a87a8920b8d323c5cc8fc19d1de230 Mon Sep 17 00:00:00 2001 From: JakeIV <114679283+JakeIV@users.noreply.github.com> Date: Wed, 7 Dec 2022 17:08:57 +0000 Subject: [PATCH 36/36] Added arrow key control --- web/src/SnakeEngine/SnakeEngine.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/src/SnakeEngine/SnakeEngine.ts b/web/src/SnakeEngine/SnakeEngine.ts index 2fe8a34..19b9596 100644 --- a/web/src/SnakeEngine/SnakeEngine.ts +++ b/web/src/SnakeEngine/SnakeEngine.ts @@ -118,19 +118,20 @@ export class SnakeEngine { document.addEventListener('keydown', parseInput); function parseInput(e: { key: string}) { switch (e.key) { - case 'ArrowUp': - SnakeEngine.snake.direction = 'up'; - break; case 'w': + case 'ArrowUp': SnakeEngine.snake.direction = 'up'; break; case 'a': + case 'ArrowLeft': SnakeEngine.snake.direction = 'left'; break; case 's': + case 'ArrowRight': SnakeEngine.snake.direction = 'down'; break; case 'd': + case 'ArrowDown': SnakeEngine.snake.direction = 'right'; break; default: