From 4c0560f460883f3907b698cfc7f1954480edde06 Mon Sep 17 00:00:00 2001 From: Takumi Hara Date: Wed, 21 Feb 2024 00:45:54 -0600 Subject: [PATCH 1/3] Change ball color --- frontend/app/pong/[id]/PongGame.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/app/pong/[id]/PongGame.ts b/frontend/app/pong/[id]/PongGame.ts index 6264ce42..181191d2 100644 --- a/frontend/app/pong/[id]/PongGame.ts +++ b/frontend/app/pong/[id]/PongGame.ts @@ -272,6 +272,7 @@ export class PongGame { setColor(color: string) { this.paddleColor = color; this.ballColor = color; + this.ball.color = color; this.player1.color = color; this.player2.color = color; } From 15287f5b3472fe6663d10bf7e721673e1b01a97d Mon Sep 17 00:00:00 2001 From: Takumi Hara Date: Wed, 21 Feb 2024 00:57:10 -0600 Subject: [PATCH 2/3] Remove PongGame.ballColor --- frontend/app/pong/[id]/PongGame.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/frontend/app/pong/[id]/PongGame.ts b/frontend/app/pong/[id]/PongGame.ts index 181191d2..41385fa6 100644 --- a/frontend/app/pong/[id]/PongGame.ts +++ b/frontend/app/pong/[id]/PongGame.ts @@ -34,7 +34,6 @@ export class PongGame { setPlayer2Position: setFunction; onAction: onActionType | undefined; private paddleColor: string; - private ballColor: string; private userMode: userModeType; constructor( @@ -51,7 +50,6 @@ export class PongGame { this.ctx.textAlign = "center"; this.ctx.font = "48px serif"; this.paddleColor = paddleColor; - this.ballColor = ballColor; this.player1 = this.initPlayer1(); this.player2 = this.initPlayer2(); @@ -64,7 +62,7 @@ export class PongGame { 0, 0, BALL_RADIUS, - this.ballColor, + ballColor, ); this.score = { player1: 0, @@ -271,7 +269,6 @@ export class PongGame { setColor(color: string) { this.paddleColor = color; - this.ballColor = color; this.ball.color = color; this.player1.color = color; this.player2.color = color; From 6bfee1c6470f42466ea555efe083f602a8ca68b7 Mon Sep 17 00:00:00 2001 From: Takumi Hara Date: Wed, 21 Feb 2024 01:01:28 -0600 Subject: [PATCH 3/3] Remove PongGame.paddleColor --- frontend/app/pong/[id]/PongGame.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/frontend/app/pong/[id]/PongGame.ts b/frontend/app/pong/[id]/PongGame.ts index 41385fa6..657e1586 100644 --- a/frontend/app/pong/[id]/PongGame.ts +++ b/frontend/app/pong/[id]/PongGame.ts @@ -33,7 +33,6 @@ export class PongGame { setPlayer1Position: setFunction; setPlayer2Position: setFunction; onAction: onActionType | undefined; - private paddleColor: string; private userMode: userModeType; constructor( @@ -49,9 +48,8 @@ export class PongGame { this.ctx = ctx; this.ctx.textAlign = "center"; this.ctx.font = "48px serif"; - this.paddleColor = paddleColor; - this.player1 = this.initPlayer1(); - this.player2 = this.initPlayer2(); + this.player1 = this.initPlayer1(paddleColor); + this.player2 = this.initPlayer2(paddleColor); this.ball = new Ball( CANVAS_HEIGHT, @@ -195,27 +193,28 @@ export class PongGame { }; resetPlayerPosition = () => { - this.player1 = this.initPlayer1(); - this.player2 = this.initPlayer2(); + const color = this.player1.color; + this.player1 = this.initPlayer1(color); + this.player2 = this.initPlayer2(color); this.draw_canvas(); }; - initPlayer1 = () => + initPlayer1 = (paddleColor: string) => new Paddle( 0, CANVAS_HEIGHT / 2 - PADDLE_HEIGHT / 2, PADDLE_WIDTH, PADDLE_HEIGHT, - this.paddleColor, + paddleColor, ); - initPlayer2 = () => + initPlayer2 = (paddleColor: string) => new Paddle( CANVAS_WIDTH - PADDLE_WIDTH, CANVAS_HEIGHT / 2 - PADDLE_HEIGHT / 2, PADDLE_WIDTH, PADDLE_HEIGHT, - this.paddleColor, + paddleColor, ); bounceOffPaddlePlayer1 = () => { @@ -268,7 +267,6 @@ export class PongGame { }; setColor(color: string) { - this.paddleColor = color; this.ball.color = color; this.player1.color = color; this.player2.color = color;