Make the board an attribute of the piece holder

This commit is contained in:
Lonami Exo 2017-02-21 21:12:52 +01:00
parent 46214456f1
commit a8dc942bc2
2 changed files with 11 additions and 7 deletions

View file

@ -42,6 +42,9 @@ public class PieceHolder implements BinSerializable {
// The size the cells will adopt once picked // The size the cells will adopt once picked
private final float pickedCellSize; private final float pickedCellSize;
// Every piece holder belongs to a specific board
private final Board board;
//endregion //endregion
//region Static members //region Static members
@ -52,7 +55,9 @@ public class PieceHolder implements BinSerializable {
//region Constructor //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; enabled = true;
count = pieceCount; count = pieceCount;
pieces = new Piece[count]; 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 // 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 // returns one of the following: NO_DROP, NORMAL_DROP, ON_BOARD_DROP
public DropResult dropPiece(Board board) { public DropResult dropPiece() {
DropResult result; DropResult result;
if (heldPiece > -1) { if (heldPiece > -1) {
@ -209,8 +214,7 @@ public class PieceHolder implements BinSerializable {
} }
// Updates the state of the piece holder (and the held piece) // 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() {
public void update(Board board) {
Piece piece; Piece piece;
if (heldPiece > -1) { if (heldPiece > -1) {
piece = pieces[heldPiece]; piece = pieces[heldPiece];

View file

@ -85,7 +85,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
} }
board = new Board(layout, BOARD_SIZE); 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); pauseMenu = new PauseMenuStage(layout, game, scorer, gameMode);
bonusParticleHandler = new BonusParticleHandler(game); bonusParticleHandler = new BonusParticleHandler(game);
@ -166,7 +166,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
scorer.draw(batch); scorer.draw(batch);
board.draw(batch); board.draw(batch);
holder.update(board); holder.update();
holder.draw(batch); holder.draw(batch);
bonusParticleHandler.run(batch); bonusParticleHandler.run(batch);
@ -202,7 +202,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
@Override @Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) { 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) if (!result.dropped)
return false; return false;