Пример #1
0
    public void MainButton(int playerIndex)
    {
        mainCanvas.playersUI[playerIndex].TriggerPressButton(-1);

        if (gridIsFull)
        {
            return;
        }

        if (selectedPosition[playerIndex][0] == -1)
        {
            if (Player.players[playerIndex].canPlayMain)
            {
                selectedPosition[playerIndex][0] = 0;
                selectedPosition[playerIndex][1] = 0;
                selectedPosition[playerIndex][2] = 0;

                mainCanvas.TriggerPlaceMode(playerIndex, true, 0);

                mainCanvas.playersUI[playerIndex].PressMainButton();
                Player.players[playerIndex].mode = PlayerMode.PlacingMode;

                InputDirection(playerIndex, 0);
            }
            else
            {
                mainCanvas.playersUI[playerIndex].TriggerDisabledButton(-1);
                return;
            }
        }
        else if (Player.players[playerIndex].mode == PlayerMode.PlacingMode)
        {
            if (selectedPosition[playerIndex][0] < 1)
            {
                selectedPosition[playerIndex][0]++;

                if (selectedPosition[playerIndex][0] == 1)
                {
                    mainCanvas.TriggerPlaceMode(playerIndex, true, 1);
                    grid.PreviewRow(selectedPosition[playerIndex][1], playerIndex, false);
                    InputDirection(playerIndex, 0);

                    if (grid.NbVacantSlots(selectedPosition[playerIndex][1], playerIndex) == 1)
                    {
                        selectedPosition[playerIndex][2] = 0;
                        while (!grid.IsSlotVacant(selectedPosition[playerIndex][1], selectedPosition[playerIndex][2], playerIndex)) //ROW IS FULL
                        {
                            selectedPosition[playerIndex][2]++;
                        }
                        selectedPosition[playerIndex][0]++;
                        MainButton(playerIndex);
                        return;
                    }
                }
            }
            else //selectedPosition[playerIndex][0] >= 2
            {
                Player.players[playerIndex].mode = PlayerMode.Normal;
                mainCanvas.TriggerPlaceMode(playerIndex, false, 1);
                grid.PreviewSlot(selectedPosition[playerIndex][1], selectedPosition[playerIndex][2], playerIndex, false);
                if (true)
                {
                    Slot slot = grid.GetSlot(selectedPosition[playerIndex][1], selectedPosition[playerIndex][2], playerIndex);

                    if (slot.IsVacant)
                    {
                        if (slot.hasPiece)
                        {
                            slot.GetPlayerPiece().ReplacePieceOnSlot();
                        }

                        PlayerPiece piece = Instantiate(gm.playersData[playerIndex].playerPiecePrefab, slot.pieceCenter);
                        piece.playerIndex = playerIndex;
                        piece.Initialize(slot);

                        slot.hasPiece = true;
                    }
                }
                selectedPosition[playerIndex][0] = -1;
            }
        }
    }