Code review 2023-01-10

This commit is contained in:
s-prechtl 2023-01-10 08:45:34 +01:00
parent d748312d66
commit 637a867c7e
9 changed files with 13 additions and 5 deletions

View file

@ -6,7 +6,7 @@ import {leaderboardRoute} from "./leaderboardRoute.js";
import {userRoute} from "./userRoute.js"; import {userRoute} from "./userRoute.js";
import {gameRoute} from "./gameRoute.js"; import {gameRoute} from "./gameRoute.js";
// TODO: Rename variables --> Responsotory + Comments
const app = express() const app = express()
const port = 3000 const port = 3000

View file

@ -42,6 +42,7 @@ userRoute.post(
) )
userRoute.get('/:userId/scores', userRoute.get('/:userId/scores',
// TODO: With id exists --> cusotm validator
param('userId').isInt({min: 1}), param('userId').isInt({min: 1}),
async (req, res) => { async (req, res) => {
//region validate parameters //region validate parameters

View file

@ -1,3 +1,4 @@
// TODO: Refactor
const pipeImagePath: string = "resources/raspberry-low-res.png"; const pipeImagePath: string = "resources/raspberry-low-res.png";
const obstacleWidth: number = 88; const obstacleWidth: number = 88;
let obstacleOffset: number; let obstacleOffset: number;
@ -33,6 +34,7 @@ function setupGame() {
raspberry.image = raspberryImagePath; raspberry.image = raspberryImagePath;
// Create all obstacles // Create all obstacles
// TODO: Loop
obstacles = []; obstacles = [];
obstacles.push(new Obstacle( obstacles.push(new Obstacle(
new Position(width, 0), new Position(width, 0),
@ -57,6 +59,7 @@ function setupGame() {
obstacles.forEach((obstacle) => obstacle.randomizeHeight()); obstacles.forEach((obstacle) => obstacle.randomizeHeight());
} }
// TODO: Split into funciton
function draw() { function draw() {
background(backgroundImage) background(backgroundImage)
if (!paused) { if (!paused) {

View file

@ -1,7 +1,7 @@
class Obstacle extends Entity implements Collidable { class Obstacle extends Entity implements Collidable {
private pipeTop: Pipe; private pipeTop: Pipe;
private pipeBottom: Pipe; private pipeBottom: Pipe;
private readonly distanceBetweenPipes: number; private static distanceBetweenPipes: number;
private readonly padding: number = 150; private readonly padding: number = 150;
private readonly speed: number = 3; private readonly speed: number = 3;
@ -22,7 +22,8 @@ class Obstacle extends Entity implements Collidable {
this.pipeTop.image = pipeImagePath; this.pipeTop.image = pipeImagePath;
this.pipeBottom.image = pipeImagePath; this.pipeBottom.image = pipeImagePath;
this.distanceBetweenPipes = height / 2.5; Obstacle.distanceBetweenPipes = height / 2.5;
//TODO: Put into setupGame()
Obstacle.startX = width; Obstacle.startX = width;
} }
@ -41,9 +42,10 @@ class Obstacle extends Entity implements Collidable {
* Randomizes the height of the pipes * Randomizes the height of the pipes
*/ */
public randomizeHeight(): void { 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.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; this.pipeBottom.height = height - this.pipeTop.height - this.padding;
} }
@ -57,6 +59,7 @@ class Obstacle extends Entity implements Collidable {
} }
public update(): void { public update(): void {
// TODO: Put into pipe.update
this.pipeTop.position.x -= this.speed; this.pipeTop.position.x -= this.speed;
this.pipeBottom.position.x -= this.speed; this.pipeBottom.position.x -= this.speed;
this.position.x = this.pipeTop.position.x; this.position.x = this.pipeTop.position.x;

View file

@ -28,6 +28,7 @@ class Raspberry extends Entity {
* Constructs the Raspberry with fixed sizes * Constructs the Raspberry with fixed sizes
*/ */
constructor() { constructor() {
// TODO: Move literals to consta
super(new Position(width / 6, height / 2), 180, 70, 0); super(new Position(width / 6, height / 2), 180, 70, 0);
} }