Exemple #1
0
 public CMoveItem(CBoard board, CPiece piece, int file, int rank)
 {
     Board = board;
     Piece = piece;
     File  = file;
     Rank  = rank;
 }
    /// <summary>
    /// ゲームを開始する
    /// </summary>
    public void GameStart()
    {
        this.GameArea.SetActive(true);
        this.DynamicCreateObjects.Clear();

        //格子を生成
        this.createGrid();

        //使用する画像を決定
        int index = -1;

        if (this.Images.Length <= this.PlayedImageList.Count)
        {
            this.PlayedImageList.Clear();                   //全部遊んでいたら履歴を初期化
        }
        do
        {
            index = Random.Range(0, this.Images.Length);
        } while(this.PlayedImageList.Contains(index) == true);
        this.PlayedImageList.Add(index);
        this.OnePiece.GetComponent <UnityEngine.UI.RawImage>().texture = this.Images[index];

        //ピースを分割
        this.Pieces = new CPiece[this.Level, this.Level];
        for (int x = 0; x < this.Level; x++)
        {
            for (int y = 0; y < this.Level; y++)
            {
                this.Pieces[x, y]      = new CPiece();
                this.Pieces[x, y].PosX = x;
                this.Pieces[x, y].SrcX = x;
                this.Pieces[x, y].PosY = y;
                this.Pieces[x, y].SrcY = y;
                this.Pieces[x, y].obj  = Instantiate(this.OnePiece, this.PicturePieces.transform);
                this.Pieces[x, y].obj.transform.position = new Vector3(
                    this.GameAreaBasePoint.x + this.PieceOneWidth / 2 + this.PieceOneWidth * x,
                    this.GameAreaBasePoint.y - this.PieceOneHeight / 2 - this.PieceOneHeight * y,
                    2
                    );
                this.Pieces[x, y].obj.GetComponent <RectTransform>().sizeDelta = new Vector2(this.PieceOneWidth, this.PieceOneHeight);
                this.DynamicCreateObjects.Add(this.Pieces[x, y].obj);
            }
        }

        //画面上の表示位置をセットする
        for (int x = 0; x < this.Level; x++)
        {
            for (int y = 0; y < this.Level; y++)
            {
                this.Pieces[x, y].obj.GetComponent <UnityEngine.UI.RawImage>().uvRect = new Rect(
                    x * (1.0f / this.Level),
                    (1.0f / this.Level * (this.Level - 1)) - y * (1.0f / this.Level),
                    1.0f / this.Level,
                    1.0f / this.Level
                    );
            }
        }

        //選択パネルを生成
        for (int x = 0; x < this.Level; x++)
        {
            for (int y = 0; y < this.Level; y++)
            {
                var selectPanel = Instantiate(this.ActivePanel, this.PicturePieces.transform);
                selectPanel.GetComponent <RectTransform>().sizeDelta = new Vector2(this.PieceOneWidth, this.PieceOneHeight);
                selectPanel.GetComponent <RectTransform>().position  = this.Pieces[x, y].obj.transform.position;
                selectPanel.GetComponent <SelectPanel>().SetPosition(x, y);
                this.DynamicCreateObjects.Add(selectPanel);
            }
        }

        //右下のピースを空けて、そのピースを完成時まで内部保管する
        this.EmptySrcPanel     = this.Pieces[this.Level - 1, this.Level - 1];
        this.EmptySrcPanel.obj = this.Pieces[this.Level - 1, this.Level - 1].obj;
        this.EmptySrcPanel.obj.transform.position = new Vector3(
            this.GameAreaBasePoint.x + this.PieceOneWidth / 2 + this.PieceOneWidth * this.EmptySrcPanel.PosX,
            this.GameAreaBasePoint.y - this.PieceOneHeight / 2 - this.PieceOneHeight * this.EmptySrcPanel.PosY,
            2
            );
        this.EmptySrcPanel.obj.SetActive(false);
        this.Pieces[this.Level - 1, this.Level - 1] = null;

        if (DefaultCompleteMode == true)
        {
            //デバッグ用: 最初から完成状態にする
            for (int x = 0; x < this.Level; x++)
            {
                for (int y = 0; y < this.Level; y++)
                {
                    if (this.Pieces[x, y] == null)
                    {
                        continue;
                    }
                    this.Pieces[x, y].obj.GetComponent <UnityEngine.UI.RawImage>().uvRect = new Rect(
                        x * (1.0f / this.Level),
                        (1.0f / this.Level * (this.Level - 1)) - y * (1.0f / this.Level),
                        1.0f / this.Level,
                        1.0f / this.Level
                        );
                }
            }
        }
        else
        {
            //ピースを分散: 全体図のどの部分を示すかを交換方式でシャッフルする
            this.moveLog = true;
            int counter = 0;
            while (counter < ShuffleCount)
            {
                int x = Random.Range(0, this.Level);
                int y = Random.Range(0, this.Level);
                if (this.IsEmptyPiece(x, y) == false && this.MovePiece(x, y, false) == true)
                {
                    counter++;
                }
            }
            this.moveLog = false;
        }
    }