Esempio n. 1
0
    public void ShowWait()
    {
        if (winner == 0)
        {
            starCount = 2;
        }
        else if (winner == 1)
        {
            starCount = 3;
        }
        else if (winner == 2)
        {
            starCount = 1;
        }

        Wait2.SetActive(true);


        if (winner != 0)
        {
            for (int i = 0; i < GridSize; i++)
            {
                if (0 <= finishState && finishState < GridSize)
                {
                    GridCellComp sb      = CellCompList[finishState * GridSize + i];
                    GameObject   newLine = GameObject.Instantiate(Resources.Load <GameObject>("lineH")) as GameObject;
                    newLine.transform.parent        = sb.transform;
                    newLine.transform.localPosition = new Vector3(0, 0, -1);
                    newLine.transform.localScale    = Vector3.one;
                }
                else if (GridSize <= finishState && finishState < GridSize * 2)
                {
                    GridCellComp sb      = CellCompList[i * GridSize + finishState - GridSize];
                    GameObject   newLine = GameObject.Instantiate(Resources.Load <GameObject>("lineV")) as GameObject;
                    newLine.transform.parent        = sb.transform;
                    newLine.transform.localPosition = new Vector3(0, 0, -1);
                    newLine.transform.localScale    = Vector3.one;
                }
                else if (finishState == GridSize * 2)
                {
                    GridCellComp sb      = CellCompList[i * GridSize + i];
                    GameObject   newLine = GameObject.Instantiate(Resources.Load <GameObject>("lineF")) as GameObject;
                    newLine.transform.parent        = sb.transform;
                    newLine.transform.localPosition = new Vector3(0, 0, -1);
                    newLine.transform.localScale    = new Vector3(1.4f, 1, 1);
                }
                else if (finishState == GridSize * 2 + 1)
                {
                    GridCellComp sb      = CellCompList[i * GridSize + (GridSize - i - 1)];
                    GameObject   newLine = GameObject.Instantiate(Resources.Load <GameObject>("lineZ")) as GameObject;
                    newLine.transform.parent        = sb.transform;
                    newLine.transform.localPosition = new Vector3(0, 0, -1);
                    newLine.transform.localScale    = new Vector3(1.4f, 1, 1);
                }
            }
        }
    }
Esempio n. 2
0
    public void RestartLevel(int size)
    {
        GridSize = size;
        Menu.SetActive(false);

        GameState = EGameState.Game;

        foreach (GridCellComp cellComp in CellCompList)
        {
            GameObject.Destroy(cellComp.gameObject);
        }
        CellCompList.Clear();

        if (DragChess)
        {
            GameObject.Destroy(DragChess.gameObject);
        }

        GridData = new int[GridSize, GridSize];

        float beginX = -(GridSize - 1) / 2 * CellOffset;
        float beginY = -(GridSize - 1) / 2 * CellOffset;

        for (int i = 0; i < GridSize; i++)
        {
            for (int j = 0; j < GridSize; j++)
            {
                GameObject gridPrefab = Resources.Load <GameObject>("GridCell");
                GameObject newGrid    = (GameObject)GameObject.Instantiate(gridPrefab);
                newGrid.transform.position = new Vector3(j * CellOffset + beginX, i * CellOffset + beginY);
                GridCellComp gridCellComp = newGrid.GetComponent <GridCellComp>();
                gridCellComp.gridX = j;
                gridCellComp.gridY = i;
                CellCompList.Add(gridCellComp);
            }
        }
        ShowDrawChess();
    }
Esempio n. 3
0
    public void FillRandomGrid()
    {
        int gridX = 0;
        int gridY = 0;

        if (GridSize == 5)
        {
            List <int> freeAroundList = new List <int>();

            int x = 0;
            int y = 0;

            x = LastPlayerX + 1;
            y = LastPlayerY;
            if (x >= 0 && x < GridSize && y >= 0 && y < GridSize && GridData[y, x] == 0)
            {
                freeAroundList.Add(y * GridSize + x);
            }

            x = LastPlayerX;
            y = LastPlayerY + 1;
            if (x >= 0 && x < GridSize && y >= 0 && y < GridSize && GridData[y, x] == 0)
            {
                freeAroundList.Add(y * GridSize + x);
            }

            x = LastPlayerX;
            y = LastPlayerY - 1;
            if (x >= 0 && x < GridSize && y >= 0 && y < GridSize && GridData[y, x] == 0)
            {
                freeAroundList.Add(y * GridSize + x);
            }

            x = LastPlayerX - 1;
            y = LastPlayerY;
            if (x >= 0 && x < GridSize && y >= 0 && y < GridSize && GridData[y, x] == 0)
            {
                freeAroundList.Add(y * GridSize + x);
            }

            if (freeAroundList.Count > 0)
            {
                int index2 = freeAroundList[Random.Range(0, freeAroundList.Count - 1)];

                gridX = index2 % GridSize;
                gridY = index2 / GridSize;

                print("电脑填入: " + gridY + " " + gridX);
                GridData[gridY, gridX] = 2;

                GridCellComp gridCellComp2 = CellCompList[index2];

                GameObject newChess2 = GameObject.Instantiate(OtherChessPrefab) as GameObject;
                newChess2.transform.parent        = gridCellComp2.transform;
                newChess2.transform.localPosition = Vector3.zero;

                ShowDrawChess();

                if (CheckEnd())
                {
                    GameState = EGameState.End;
                    ShowWait();
                }
                return;
            }
        }


        List <int> freeIndexList = new List <int>();

        for (int i = 0; i < GridSize; i++)
        {
            for (int j = 0; j < GridSize; j++)
            {
                if (GridData[i, j] == 0)
                {
                    freeIndexList.Add(i * GridSize + j);
                }
            }
        }

        int index = freeIndexList[Random.Range(0, freeIndexList.Count - 1)];

        gridX = index % GridSize;
        gridY = index / GridSize;

        print("电脑填入: " + gridY + " " + gridX);
        GridData[gridY, gridX] = 2;

        GridCellComp gridCellComp = CellCompList[index];

        GameObject newChess = GameObject.Instantiate(OtherChessPrefab) as GameObject;

        newChess.transform.parent        = gridCellComp.transform;
        newChess.transform.localPosition = Vector3.zero;

        ShowDrawChess();

        if (CheckEnd())
        {
            GameState = EGameState.End;
            ShowWait();
        }
    }