/** * Displays the given game board. * * @param board The board to display. */ public void displayBoard(Board board) { int width = board.getWidth(); int height = board.getHeight(); int tileSize = determineTileSize(width, height); offsetTop = (boardView.getHeight() - (height * tileSize)) / 2; offsetLeft = (boardView.getWidth() - (width * tileSize)) / 2; // Start with an empty display. boardView.removeAllViews(); Ball ball; Goal goal; Man man; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { switch (board.getBoardPiece(x, y)) { case Board.GOAL: goal = new Goal(this, tileSize, x, y); gameController.addGoal(goal); break; case Board.BALL: ball = new Ball(this, tileSize, x, y); gameController.addBall(ball); break; case Board.BALL_IN_GOAL: goal = new Goal(this, tileSize, x, y); gameController.addGoal(goal); ball = new Ball(this, tileSize, x, y); gameController.addBall(ball); break; case Board.MAN: man = new Man(this, tileSize, x, y); gameController.setMan(man); break; case Board.MAN_ON_GOAL: goal = new Goal(this, tileSize, x, y); gameController.addGoal(goal); man = new Man(this, tileSize, x, y); gameController.setMan(man); break; case Board.WALL: new Wall(this, tileSize, x, y); break; } if (board.isFloor(x, y)) { new Floor(this, tileSize, x, y); } } } }