From 637a867c7e08e50fc4e3992866871075542fa9e4 Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Tue, 10 Jan 2023 08:45:34 +0100 Subject: [PATCH] Code review 2023-01-10 --- backend/api/src/app.ts | 2 +- backend/api/src/userRoute.ts | 1 + frontend/game.ts | 3 +++ frontend/{models => model}/Collidable.ts | 0 frontend/{models => model}/Entity.ts | 0 frontend/{models => model}/Obstacle.ts | 11 +++++++---- frontend/{models => model}/Pipe.ts | 0 frontend/{models => model}/Position.ts | 0 frontend/{models => model}/Raspberry.ts | 1 + 9 files changed, 13 insertions(+), 5 deletions(-) rename frontend/{models => model}/Collidable.ts (100%) rename frontend/{models => model}/Entity.ts (100%) rename frontend/{models => model}/Obstacle.ts (87%) rename frontend/{models => model}/Pipe.ts (100%) rename frontend/{models => model}/Position.ts (100%) rename frontend/{models => model}/Raspberry.ts (97%) diff --git a/backend/api/src/app.ts b/backend/api/src/app.ts index 17361ac..ca51deb 100644 --- a/backend/api/src/app.ts +++ b/backend/api/src/app.ts @@ -6,7 +6,7 @@ import {leaderboardRoute} from "./leaderboardRoute.js"; import {userRoute} from "./userRoute.js"; import {gameRoute} from "./gameRoute.js"; - +// TODO: Rename variables --> Responsotory + Comments const app = express() const port = 3000 diff --git a/backend/api/src/userRoute.ts b/backend/api/src/userRoute.ts index 305a203..638665e 100644 --- a/backend/api/src/userRoute.ts +++ b/backend/api/src/userRoute.ts @@ -42,6 +42,7 @@ userRoute.post( ) userRoute.get('/:userId/scores', + // TODO: With id exists --> cusotm validator param('userId').isInt({min: 1}), async (req, res) => { //region validate parameters diff --git a/frontend/game.ts b/frontend/game.ts index 07fde06..db7d4ac 100644 --- a/frontend/game.ts +++ b/frontend/game.ts @@ -1,3 +1,4 @@ +// TODO: Refactor const pipeImagePath: string = "resources/raspberry-low-res.png"; const obstacleWidth: number = 88; let obstacleOffset: number; @@ -33,6 +34,7 @@ function setupGame() { raspberry.image = raspberryImagePath; // Create all obstacles + // TODO: Loop obstacles = []; obstacles.push(new Obstacle( new Position(width, 0), @@ -57,6 +59,7 @@ function setupGame() { obstacles.forEach((obstacle) => obstacle.randomizeHeight()); } +// TODO: Split into funciton function draw() { background(backgroundImage) if (!paused) { diff --git a/frontend/models/Collidable.ts b/frontend/model/Collidable.ts similarity index 100% rename from frontend/models/Collidable.ts rename to frontend/model/Collidable.ts diff --git a/frontend/models/Entity.ts b/frontend/model/Entity.ts similarity index 100% rename from frontend/models/Entity.ts rename to frontend/model/Entity.ts diff --git a/frontend/models/Obstacle.ts b/frontend/model/Obstacle.ts similarity index 87% rename from frontend/models/Obstacle.ts rename to frontend/model/Obstacle.ts index e12ad11..bdf923c 100644 --- a/frontend/models/Obstacle.ts +++ b/frontend/model/Obstacle.ts @@ -1,7 +1,7 @@ class Obstacle extends Entity implements Collidable { private pipeTop: Pipe; private pipeBottom: Pipe; - private readonly distanceBetweenPipes: number; + private static distanceBetweenPipes: number; private readonly padding: number = 150; private readonly speed: number = 3; @@ -22,7 +22,8 @@ class Obstacle extends Entity implements Collidable { this.pipeTop.image = pipeImagePath; this.pipeBottom.image = pipeImagePath; - this.distanceBetweenPipes = height / 2.5; + Obstacle.distanceBetweenPipes = height / 2.5; + //TODO: Put into setupGame() Obstacle.startX = width; } @@ -41,9 +42,10 @@ class Obstacle extends Entity implements Collidable { * Randomizes the height of the pipes */ public randomizeHeight(): void { - this.pipeTop.height = this.randomRange(this.padding, height - this.padding - this.distanceBetweenPipes); + this.pipeTop.height = this.randomRange(this.padding, height - this.padding - Obstacle.distanceBetweenPipes); + //TODO: Soi des do sei? this.pipeTop.position.y = 0; - this.pipeBottom.position.y = this.pipeTop.height + this.distanceBetweenPipes; + this.pipeBottom.position.y = this.pipeTop.height + Obstacle.distanceBetweenPipes; this.pipeBottom.height = height - this.pipeTop.height - this.padding; } @@ -57,6 +59,7 @@ class Obstacle extends Entity implements Collidable { } public update(): void { + // TODO: Put into pipe.update this.pipeTop.position.x -= this.speed; this.pipeBottom.position.x -= this.speed; this.position.x = this.pipeTop.position.x; diff --git a/frontend/models/Pipe.ts b/frontend/model/Pipe.ts similarity index 100% rename from frontend/models/Pipe.ts rename to frontend/model/Pipe.ts diff --git a/frontend/models/Position.ts b/frontend/model/Position.ts similarity index 100% rename from frontend/models/Position.ts rename to frontend/model/Position.ts diff --git a/frontend/models/Raspberry.ts b/frontend/model/Raspberry.ts similarity index 97% rename from frontend/models/Raspberry.ts rename to frontend/model/Raspberry.ts index 32fcb3e..aaec5d8 100644 --- a/frontend/models/Raspberry.ts +++ b/frontend/model/Raspberry.ts @@ -28,6 +28,7 @@ class Raspberry extends Entity { * Constructs the Raspberry with fixed sizes */ constructor() { + // TODO: Move literals to consta super(new Position(width / 6, height / 2), 180, 70, 0); }