public void CountScores()
    {
        int  gwidth  = 4;
        int  gheight = 4;
        bool ok;
        int  playerIndex;

        for (int p = 0; p < 2; p++)
        {
            for (int i = 0; i < gheight; i++)
            {
                for (int j = 0; j < gwidth - 3 + 1; j++)
                {
                    playerIndex = grid.GetSlot(i, j, p).playerIndex;
                    if (playerIndex != -1)
                    {
                        ok = playerIndex == grid.GetSlot(i, j + 1, p).playerIndex;
                        ok = ok && (playerIndex == grid.GetSlot(i, j + 2, p).playerIndex);

                        if (ok)
                        {
                            Player.players[playerIndex].score += 3;

                            grid.GetSlot(i, j, p).ScorePoint(playerIndex);
                            grid.GetSlot(i, j + 1, p).ScorePoint(playerIndex);
                            grid.GetSlot(i, j + 2, p).ScorePoint(playerIndex);
                        }
                    }

                    if (i < gheight - 3 + 1)
                    {
                        int k = p == 1 ? i : gheight - 1 - i;
                        int m = p == 1 ? 1 : -1;

                        playerIndex = grid.GetSlot(k, j, 0).playerIndex;
                        if (playerIndex != -1)
                        {
                            ok = playerIndex == grid.GetSlot(k + m, j + 1, 0).playerIndex;
                            ok = ok && (playerIndex == grid.GetSlot(k + 2 * m, j + 2, 0).playerIndex);

                            if (ok)
                            {
                                Player.players[playerIndex].score += 3;

                                grid.GetSlot(k, j, 0).ScorePoint(playerIndex);
                                grid.GetSlot(k + m, j + 1, 0).ScorePoint(playerIndex);
                                grid.GetSlot(k + 2 * m, j + 2, 0).ScorePoint(playerIndex);
                            }
                        }
                    }
                }
            }
        }
    }
Beispiel #2
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;
            }
        }
    }