public void SetOwnColor(Checkerboard.TileState newOwnColor)
    {
        Assert.AreNotEqual(Checkerboard.TileState.None, newOwnColor);

        ownColor = newOwnColor;

        float targetRotation = newOwnColor == Checkerboard.TileState.Black ? 180f : 0f;

        transform.DOKill(complete: true);
        transform.DOLocalRotate(Vector3.up * targetRotation, rotationDuration).SetEase(Ease.InOutQuad);
    }
    private void GenerateTileView(int x, int y)
    {
        var gridPosition = new Vector2Int(x, y);

        grid[x, y].tile    = AddTile(gridPosition);
        grid[x, y].overlay = AddOverlay(gridPosition);

        Checkerboard.TileState tile = checkerboard.GetAt(gridPosition);
        if (tile != Checkerboard.TileState.None)
        {
            grid[x, y].pieceView = AddPiece(gridPosition, isWhite: tile == Checkerboard.TileState.White);
        }
    }
    public void Clear()
    {
        if (checkerboard != null)
        {
            checkerboard.OnPieceAdded   -= CheckerboardOnPieceAdded;
            checkerboard.OnPieceMoved   -= CheckerboardOnPieceMoved;
            checkerboard.OnPieceRemoved -= CheckerboardOnPieceRemoved;
            checkerboard.OnMultiCapture -= CheckerboardOnMultiCapture;
            checkerboard = null;
        }

        DestroyAllChildren(tilesParent);
        DestroyAllChildren(overlaysParent);
        DestroyAllChildren(piecesParent);
        grid = null;

        ownColor = Checkerboard.TileState.White;
    }
示例#4
0
    public void On(MakeMove request)
    {
        if (!IsFromPlayersAtThisTable(request))
        {
            return;
        }

        if (!IsFromCorrectPlayer(request))
        {
            Debug.LogWarning("Request to move a piece came from the wrong player.");
            SendAllAtTable(MakeServerChatMessage("Warning: Request to make invalid move."));
            return;
        }

        if (!checkerboard.TryMakeMove(request.origin, request.target))
        {
            Debug.LogWarning("Request to make invalid move.");
            SendAllAtTable(MakeServerChatMessage("Warning: Request to make invalid move."));
            return;
        }

        AnnounceMove(request.origin, request.target);

        Checkerboard.TileState victorColor = checkerboard.CheckVictory();
        if (victorColor != Checkerboard.TileState.None)
        {
            ServerPlayer victor = victorColor == Checkerboard.TileState.White ? playerA : playerB;
            SendAllAtTable(new NotifyVictory(victor.playerId));
            SendAllAtTable(MakeServerChatMessage($"{victor.nickname} wins!"));

            checkerboard = CheckersHelper.MakeDefaultCheckerboard();
            StartNewGame();
            AnnounceNewTurn(GetCurrentPlayer());

            return;
        }

        currentPlayerIsB = checkerboard.currentPlayerColor == Checkerboard.TileState.Black;

        // only change if not double capture
        //currentPlayerIsB = !currentPlayerIsB;

        AnnounceNewTurn(GetCurrentPlayer());
    }