@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		Point point = snapMouseToBoard(arg0.getX(), arg0.getY());
		if (availableMoves != null) {
			for (Move m : availableMoves) {
				if (m.getEndingTile().getX() == point.x
						&& m.getEndingTile().getY() == point.y) {
					if (m.getType() == Move.Type.MOVE_PROMOTE) {
						ChessPiece.Type type = promptForPieceType();
						CompoundMove move = (CompoundMove) m;
						MoveTransform transform = (MoveTransform) move
								.getMoveB();
						transform.setTransformation(type);
					}
					availableMoves = null;
					hasSelectedPiece = false;
					game.applyMove(m);
					this.recalculateAllAvailableMoves();
					return;
				}
			}

			hasSelectedPiece = false;
			availableMoves = null;
		}

		if (game.getChessBoard().isValidLocation(point.x, point.y)
				&& game.getChessBoard().hasPieceAtLocation(point.x, point.y)
				&& game.getChessBoard().getPiece(point.x, point.y).getPlayer() == game
						.getCurrentTurn()) {
			lastSelectedX = point.x;
			lastSelectedY = point.y;
			hasSelectedPiece = true;
			availableMoves = game.generateMovesForTile(game.getChessBoard()
					.getTile(lastSelectedX, lastSelectedY));
		}
	}