diff --git a/README.md b/README.md index 091a9fa..49c7e2b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PonGo -![Coverage](https://img.shields.io/badge/Coverage-66.7%25-yellow) +![Coverage](https://img.shields.io/badge/Coverage-59.2%25-yellow) ![Unit-tests](https://img.shields.io/github/actions/workflow/status/lguibr/pongo/test.yml?label=UnitTests) ![Building](https://img.shields.io/github/actions/workflow/status/lguibr/pongo/build.yml?label=Build) ![Lint](https://img.shields.io/github/actions/workflow/status/lguibr/pongo/lint.yml?label=Lint) diff --git a/game/ball.go b/game/ball.go index ca492db..c7382f1 100644 --- a/game/ball.go +++ b/game/ball.go @@ -107,7 +107,7 @@ func (ball *Ball) Move() { ball.Vy += ball.Ay } -func (ball *Ball) getCenterIndex(grid Grid) (x, y int) { +func (ball *Ball) getCenterIndex() (x, y int) { cellSize := utils.CellSize row := ball.X / cellSize col := ball.Y / cellSize diff --git a/game/ball_test.go b/game/ball_test.go index 5eef1cc..95a7a14 100644 --- a/game/ball_test.go +++ b/game/ball_test.go @@ -360,7 +360,7 @@ func TestBall_GetCenterIndex(t *testing.T) { for _, tc := range testCases { ball := &Ball{X: tc.ballX, Y: tc.ballY} - row, col := ball.getCenterIndex(NewGrid(gridSize)) + row, col := ball.getCenterIndex() if row != tc.expectedRow || col != tc.expectedCol { t.Errorf("Test case %s failed: expected row %d and col %d but got row %d and col %d", tc.name, tc.expectedRow, tc.expectedCol, row, col) } diff --git a/game/collision.go b/game/collision.go index 06588fb..ff16471 100644 --- a/game/collision.go +++ b/game/collision.go @@ -54,7 +54,7 @@ func (ball *Ball) CollidePaddle(paddle *Paddle) { func (ball *Ball) CollideCells(grid Grid, cellSize int) { gridSize := len(grid) - row, col := ball.getCenterIndex(grid) + row, col := ball.getCenterIndex() if row < 0 || row > gridSize-1 || col < 0 || col > gridSize-1 { return } diff --git a/game/paddle.go b/game/paddle.go index be7780c..85cc5ce 100644 --- a/game/paddle.go +++ b/game/paddle.go @@ -118,7 +118,6 @@ func (paddle *Paddle) SetDirection(buffer []byte) (Direction, error) { } newDirection := utils.DirectionFromString(direction.Direction) - utils.Logger("./data/direction.json", fmt.Sprintf("newDirection: %v", newDirection)) paddle.Direction = newDirection return direction, nil } diff --git a/game/paddle_test.go b/game/paddle_test.go index 8a4ab01..90a3aa4 100644 --- a/game/paddle_test.go +++ b/game/paddle_test.go @@ -20,7 +20,10 @@ func TestPaddle_SetDirection(t *testing.T) { {[]byte(``), "", false}, } for _, tc := range testCases { - paddle.SetDirection(tc.buffer) + _, err := paddle.SetDirection(tc.buffer) + if err != nil { + println(err) + } if tc.shouldPass { if paddle.Direction != tc.direction { t.Errorf("Expected direction to be %s but got %s", tc.direction, paddle.Direction) diff --git a/game/reader.go b/game/reader.go index 15cac61..9e78249 100644 --- a/game/reader.go +++ b/game/reader.go @@ -1,6 +1,7 @@ package game import ( + "fmt" "math/rand" "time" @@ -76,7 +77,10 @@ func (playerPaddle *Paddle) ReadPaddleChannel(paddleChannel chan PaddleMessage) switch message := message.(type) { case PaddleDirectionMessage: direction := message.Direction - playerPaddle.SetDirection(direction) + _, err := playerPaddle.SetDirection(direction) + if err != nil { + fmt.Println("Error setting direction :", err) + } default: continue }