예제 #1
0
 /// <summary>
 /// 迷路の開始地点を決める
 /// </summary>
 /// <remarks>
 /// 開始地点は外周以外の偶数を選択
 /// </remarks>
 private void GetFirstPoint()
 {
     StartPoint = new MapPoint(GetRandomEvenPoint(2, SizeX - 3),
                               GetRandomEvenPoint(2, SizeY - 3));
     DungeonMap[StartPoint.X, StartPoint.Y] = LoadStatus.Load;
     LoadEvenPoint.Add(StartPoint);
 }
예제 #2
0
        /// <summary>
        /// 再帰呼び出しで道を作る
        /// </summary>
        /// <param name="startPointIndex">掘削の起点ポイント</param>
        public void RecursiveLoad(MapPoint startPointIndex)
        {
            //掘る方向を決める
            LoadDirection dir = GetDirection(startPointIndex);
            //掘る2マス先のポイントと中間地点を格納する変数
            MapPoint target, subTarget;

            //2マス先と中間マスを取得する
            switch (dir)
            {
            case LoadDirection.Top:
                target    = new MapPoint(startPointIndex.X, startPointIndex.Y - 2);
                subTarget = new MapPoint(startPointIndex.X, startPointIndex.Y - 1);
                break;

            case LoadDirection.Bottom:
                target    = new MapPoint(startPointIndex.X, startPointIndex.Y + 2);
                subTarget = new MapPoint(startPointIndex.X, startPointIndex.Y + 1);
                break;

            case LoadDirection.Left:
                target    = new MapPoint(startPointIndex.X - 2, startPointIndex.Y);
                subTarget = new MapPoint(startPointIndex.X - 1, startPointIndex.Y);
                break;

            case LoadDirection.Right:
                target    = new MapPoint(startPointIndex.X + 2, startPointIndex.Y);
                subTarget = new MapPoint(startPointIndex.X + 1, startPointIndex.Y);
                break;

            default:
                //もう掘れない場合は自分を掘削リストから削除して
                //既存のポイントから掘削を再開する
                //最初の一回目をゴールとする
                if (isGoalSet == false)
                {
                    isGoalSet = true;
                    GoalPoint = new MapPoint(startPointIndex.X, startPointIndex.Y);
                }
                LoadEvenPoint.Remove(startPointIndex);
                if (LoadEvenPoint.Count > 0)
                {
                    RecursiveLoad(LoadEvenPoint[rnd.Next(LoadEvenPoint.Count)]);
                }
                //掘削ポイントがもうない場合は終了する
                return;
            }
            //掘る先を掘削リストに追加
            LoadEvenPoint.Add(target);
            //対象と中間を掘る
            DungeonMap[target.X, target.Y]       = LoadStatus.Load;
            DungeonMap[subTarget.X, subTarget.Y] = LoadStatus.Load;
            //堀った先を中心に再帰
            RecursiveLoad(target);
        }