diff --git a/core/src/io/github/lonamiwebs/klooni/game/PieceHolder.java b/core/src/io/github/lonamiwebs/klooni/game/PieceHolder.java index f70eb04..6b614f3 100644 --- a/core/src/io/github/lonamiwebs/klooni/game/PieceHolder.java +++ b/core/src/io/github/lonamiwebs/klooni/game/PieceHolder.java @@ -42,6 +42,9 @@ public class PieceHolder implements BinSerializable { // The size the cells will adopt once picked private final float pickedCellSize; + // Every piece holder belongs to a specific board + private final Board board; + //endregion //region Static members @@ -52,7 +55,9 @@ public class PieceHolder implements BinSerializable { //region Constructor - public PieceHolder(final GameLayout layout, final int pieceCount, final float pickedCellSize) { + public PieceHolder(final GameLayout layout, final Board board, + final int pieceCount, final float pickedCellSize) { + this.board = board; enabled = true; count = pieceCount; pieces = new Piece[count]; @@ -176,7 +181,7 @@ public class PieceHolder implements BinSerializable { // Tries to drop the piece on the given board. As a result, it // returns one of the following: NO_DROP, NORMAL_DROP, ON_BOARD_DROP - public DropResult dropPiece(Board board) { + public DropResult dropPiece() { DropResult result; if (heldPiece > -1) { @@ -209,8 +214,7 @@ public class PieceHolder implements BinSerializable { } // Updates the state of the piece holder (and the held piece) - // TODO Passing the board seems expensive… Should it rather be an attribute? - public void update(Board board) { + public void update() { Piece piece; if (heldPiece > -1) { piece = pieces[heldPiece]; diff --git a/core/src/io/github/lonamiwebs/klooni/screens/GameScreen.java b/core/src/io/github/lonamiwebs/klooni/screens/GameScreen.java index 05cf406..5e85598 100644 --- a/core/src/io/github/lonamiwebs/klooni/screens/GameScreen.java +++ b/core/src/io/github/lonamiwebs/klooni/screens/GameScreen.java @@ -85,7 +85,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable { } board = new Board(layout, BOARD_SIZE); - holder = new PieceHolder(layout, HOLDER_PIECE_COUNT, board.cellSize); + holder = new PieceHolder(layout, board, HOLDER_PIECE_COUNT, board.cellSize); pauseMenu = new PauseMenuStage(layout, game, scorer, gameMode); bonusParticleHandler = new BonusParticleHandler(game); @@ -166,7 +166,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable { scorer.draw(batch); board.draw(batch); - holder.update(board); + holder.update(); holder.draw(batch); bonusParticleHandler.run(batch); @@ -202,7 +202,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable { @Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { - PieceHolder.DropResult result = holder.dropPiece(board); + PieceHolder.DropResult result = holder.dropPiece(); if (!result.dropped) return false;