Exemplo n.º 1
0
    public void InputDirection(int playerIndex, int direction)
    {
        bool IsGridFull = false;
        int  offsetDir  = (direction == 0) ? 1: direction;

        int k = -1;

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

            k = 0;
            selectedPosition[playerIndex][1] = (selectedPosition[playerIndex][1] + 4 + direction) % 4;
            while (!IsGridFull && grid.NbVacantSlots(selectedPosition[playerIndex][1], playerIndex) == 0) //ROW IS FULL
            {
                selectedPosition[playerIndex][1] = (selectedPosition[playerIndex][1] + 4 + offsetDir) % 4;
                k++;
                if (k > 4)
                {
                    IsGridFull = true;
                }
            }

            grid.PreviewRow(selectedPosition[playerIndex][1], playerIndex, true);
        }
        else if (selectedPosition[playerIndex][0] == 1)
        {
            grid.PreviewSlot(selectedPosition[playerIndex][1], selectedPosition[playerIndex][2], playerIndex, false);

            k = 0;
            selectedPosition[playerIndex][2] = (selectedPosition[playerIndex][2] + 4 + direction) % 4;
            while (!IsGridFull && !grid.IsSlotVacant(selectedPosition[playerIndex][1], selectedPosition[playerIndex][2], playerIndex)) //SLOT IS FULL
            {
                selectedPosition[playerIndex][2] = (selectedPosition[playerIndex][2] + 4 + offsetDir) % 4;
                k++;
                if (k > 4)
                {
                    IsGridFull = true;
                }
            }

            grid.PreviewSlot(selectedPosition[playerIndex][1], selectedPosition[playerIndex][2], playerIndex, true);
        }
    }