コード例 #1
0
ファイル: Level.cs プロジェクト: raysjoshua/TreasureHunter
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="Width">Unit width of the maze</param>
        /// <param name="Height">Unit height of the maze</param>
        /// <param name="ScaleX">Unit width of maze cell</param>
        /// <param name="ScaleY">Unit height of maze cell</param>
        /// <param name="Seconds">Time required to complete</param>
        public Level(int Width, int Height, int ScaleX, int ScaleY, int Seconds)
        {
            width      = Width;
            height     = Height;
            scaleX     = ScaleX;
            scaleY     = ScaleY;
            discovered = 0;
            death      = 0;
            MazeGenerator levelRef = new MazeGenerator(width, height, ScaleX, ScaleY);

            scaledWidth  = levelRef.ScaledWidth();
            scaledHeight = levelRef.ScaledHeight();
            ObjectList   = new List <GameObject>();

            List <MazeBlock> walkables = new List <MazeBlock>();

            radar = new Radar(levelRef.maze);

            foreach (GameObject Obj in levelRef.maze)
            {
                MazeBlock temp = Obj as MazeBlock;
                if (temp.Walkable)
                {
                    walkables.Add(temp);
                    walkableSpace++;
                }
                InsertGameObject(Obj);
            }



            firstPosition = walkables.ElementAt <MazeBlock>(0).kinetics.position;
            treasure      = new Treasure(walkables.ElementAt <MazeBlock>(walkables.Count - 1));
            InsertGameObject(treasure);
            walkables.RemoveAt(0);

            Random rand = new Random(DateTime.Now.Millisecond);

            if (walkables.Count > 0)
            {
                walkables.RemoveAt(walkables.Count - 1);
                int index = walkables.Count / 10;
                while (index > 0)
                {
                    MazeBlock block = walkables.ElementAt <MazeBlock>(rand.Next(0, walkables.Count));
                    if (Vector2.Distance(firstPosition, block.kinetics.position) > 500)
                    {
                        InsertGameObject(new Enemy(block));
                        index--;
                    }
                }
            }

            timeLeft = new Timer(Seconds, true);
        }
コード例 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="Width">Unit width of the maze</param>
        /// <param name="Height">Unit height of the maze</param>
        /// <param name="ScaleX">Unit width of maze cell</param>
        /// <param name="ScaleY">Unit height of maze cell</param>
        /// <param name="Seconds">Time required to complete</param>
        public Level(int Width, int Height, int ScaleX, int ScaleY, int Seconds)
        {
            unitWidth  = Width;
            unitHeight = Height;
            cellWidth  = ScaleX;
            cellHeight = ScaleY;
            combo      = 0;
            MaxCombo   = 0;
            discovered = 0;
            death      = 0;
            List <MazeBlock> walkables = new List <MazeBlock>();

            UpdateList = new List <GameObject>();
            UpdateList = new List <GameObject>();
            DrawList   = new List <GameObject>();

            while (walkables.Count() < 1)
            {
                MazeGenerator levelRef = new MazeGenerator(unitWidth, unitHeight, ScaleX, ScaleY);
                walkables   = new List <MazeBlock>();
                UpdateList  = new List <GameObject>();
                radar       = new Radar(levelRef.maze);
                levelWidth  = levelRef.MazeWidth();
                levelHeight = levelRef.MazeHeight();

                foreach (GameObject Obj in levelRef.maze)
                {
                    if (Obj == null)
                    {
                        continue;
                    }
                    MazeBlock temp = Obj as MazeBlock;
                    if (temp.Walkable)
                    {
                        walkables.Add(temp);
                        walkableSpace++;
                        InsertGameObjectDraw(Obj);
                    }
                    InsertGameObject(Obj);
                }
            }

            firstPosition = walkables.ElementAt <MazeBlock>(0).kinetics.position;
            treasure      = new Treasure(walkables.ElementAt <MazeBlock>(walkables.Count - 1));
            InsertGameObject(treasure);
            walkables.RemoveAt(0);

            PlaceEnemies(walkables, 10);
            timeLeft   = new Timer(Seconds, true);
            comboTimer = new Timer(1);
        }