Esempio n. 1
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());
    }