Пример #1
0
        /// <summary>
        /// Initialize the game.
        /// </summary>
        /// <param name="resChanged">Has the resolution / gamesize changed?</param>
        void InitGame(bool resChanged)
        {
            if (resChanged) //res has changed
            {
                var holder = tileHolder as RectTransform;
                //adjust the size so it BARELY fits.
                holder.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, currentRes.width * (tileOffset + tileSize));
                holder.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, currentRes.height * (tileOffset + tileSize));

                //Clear the tiles currently in-game.
                for (int i = tileHolder.childCount - 1; i >= 0; i--)
                {
                    Destroy(tileHolder.GetChild(i).gameObject);
                }
                //instantiate the tiles.
                tileMap = new Tile[currentRes.width, currentRes.height];
                for (int y = 0; y < currentRes.height; y++)
                {
                    for (int x = 0; x < currentRes.width; x++)
                    {
                        //get the tile components and set their things.
                        Tile temp = Instantiate(tilePrefab, tileHolder).GetComponent <Tile>();
                        tileMap[x, y] = temp;
                        temp.coords   = new Vector2Int(x, y);
                        temp.clicked  = false; //double check
                        temp.isBomb   = false;
                    }
                }
            }
            else //size has not changed.
            {
                //reset the field.
                for (int y = 0; y < currentRes.height; y++)
                {
                    for (int x = 0; x < currentRes.width; x++)
                    {
                        Tile t = tileMap[x, y];
                        t._Reset();
                    }
                }
            }

            this.bombCount = new int[currentRes.width, currentRes.height];
            //reset the thingy
            firstClick = true;
        }