Beispiel #1
0
        /// <summary>
        /// 指定マスを空マスと入れ替える
        /// </summary>
        /// <param name="index">移動する指定マスのインデックス</param>
        /// <param name="countRecord">スライド回数をカウントするかどうか</param>
        /// <returns>指定マスが移動したログを返す</returns>
        public MoveLog Move(int index, bool countRecord = true)
        {
            Direction direction = this.MovableDirection(index);
            MoveLog   moveLog   = new MoveLog(this.Board[index], direction);

            if (direction != Direction.None)
            {
                this.Board[this.SpaceIndex] = this.Board[index];
                this.Board[index]           = -1;
                this.SpaceIndex             = index;

                if (countRecord)
                {
                    this.SlideCount++;
                }
            }
            return(moveLog);
        }
Beispiel #2
0
        /// <summary>
        /// ランダムなマスを移動(移動モーション無し)
        /// </summary>
        /// <param name="index">移動するマスのインデックス</param>
        private void RandomMovePicture()
        {
            // 移動判定フラグが真なら終了
            if (this.PictureMoving)
            {
                return;
            }
            this.PictureMoving = true;

            // パズルを回転
            MoveLog moveLog = this.MainPuzzle.RandomMove();

            // 移動に成功したら画面の画像を同期
            if (moveLog.MoveDirection != Direction.None)
            {
                // 方角を計算して画像を動かす
                int topLocation  = this.BoardPictures[moveLog.MoveIndex].Location.Y;
                int leftLocation = this.BoardPictures[moveLog.MoveIndex].Location.X;

                if (moveLog.MoveDirection == Direction.W)
                {
                    topLocation -= this.MainPuzzle.MassWidth;
                }
                else if (moveLog.MoveDirection == Direction.S)
                {
                    topLocation += this.MainPuzzle.MassWidth;
                }

                if (moveLog.MoveDirection == Direction.A)
                {
                    leftLocation -= this.MainPuzzle.MassWidth;
                }
                else if (moveLog.MoveDirection == Direction.D)
                {
                    leftLocation += this.MainPuzzle.MassWidth;
                }

                this.BoardPictures[moveLog.MoveIndex].Location = new Point(leftLocation, topLocation);
            }

            // 移動判定フラグを偽にする
            this.PictureMoving = false;
        }
Beispiel #3
0
        /// <summary>
        /// 指定したマスのインデックスが移動可能なら移動(移動モーション有り)
        /// </summary>
        /// <param name="index">移動するマスのインデックス</param>
        private async void MovePicture(int index)
        {
            // 移動判定フラグが真なら終了
            if (this.PictureMoving || this.State != PuzzleState.PLAYING)
            {
                return;
            }
            this.PictureMoving = true;

            // パズルを回転
            MoveLog moveLog = this.MainPuzzle.Move(index);

            // 移動に成功したら画面の画像を同期
            if (moveLog.MoveDirection != Direction.None)
            {
                // 方角を計算
                int topDirection = 0, leftDirection = 0;

                if (moveLog.MoveDirection == Direction.W)
                {
                    topDirection = -1;
                }
                else if (moveLog.MoveDirection == Direction.S)
                {
                    topDirection = 1;
                }

                if (moveLog.MoveDirection == Direction.A)
                {
                    leftDirection = -1;
                }
                else if (moveLog.MoveDirection == Direction.D)
                {
                    leftDirection = 1;
                }

                // 滑らかに移動
                for (int i = 0; i < this.MainPuzzle.MassWidth / 2; i++)
                {
                    this.BoardPictures[moveLog.MoveIndex].Top  += 2 * topDirection;
                    this.BoardPictures[moveLog.MoveIndex].Left += 2 * leftDirection;
                    await Task.Run(() => System.Threading.Thread.Sleep(1));
                }

                // 余りが出た場合の調整
                if (this.MainPuzzle.MassWidth % 2 == 1)
                {
                    this.BoardPictures[moveLog.MoveIndex].Top  += 1 * topDirection;
                    this.BoardPictures[moveLog.MoveIndex].Left += 1 * leftDirection;
                }

                // スライド回数をラベルに反映
                this.SlideCountLabel.Text = this.MainPuzzle.SlideCount + "回";

                // ゲームクリア判定
                if (this.MainPuzzle.ClearCheck())
                {
                    this.SetState(PuzzleState.CLEAR);
                    this.BoardPictures[this.MainPuzzle.MassCount - 1].Visible = true;
                    MessageBox.Show("経過時間:" + this.ProgressTime +
                                    "秒\r\n回転回数:" + this.MainPuzzle.SlideCount + "回",
                                    "ゲームクリア", MessageBoxButtons.OK);
                }
            }

            // 移動判定フラグを偽にする
            this.PictureMoving = false;
        }