Esempio n. 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //EXIT APPLICATION
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            //START NEW SEARCH
            if (Keyboard.GetState().IsKeyDown(Keys.Space) && searched == true && pressed == false)
            {
                myGraph = new Graph();
                myGraph.initialize(graphics, gridSize, this, spriteBatch);
                searched = false;
                pressed = true;
            }
            if (Keyboard.GetState().IsKeyUp(Keys.Space) && pressed == true)
            {
                pressed = false;
            }

            while (searched == false)
            {
                
                Random rnd = new Random();
                myGraph.AndrewBreadthFirst(myGraph.nodes[rnd.Next(0,31), rnd.Next(0,23)], myGraph.nodes[rnd.Next(0,31), rnd.Next(0,23)]);
                searched = true;
            }

                base.Update(gameTime);
        }
Esempio n. 2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            myGraph = new Graph();
            myGraph.initialize(graphics, gridSize, this, spriteBatch);         
        }
Esempio n. 3
0
 public void getEdges(Graph graph)
 {
     if(graph.nodes[iValue, jValue].jValue - 1 >= 0) //Get Adjacent Node to North
     {
         neighborStack.Push(graph.nodes[iValue, jValue - 1]);
     }
     if (graph.nodes[iValue, jValue].jValue + 1 < graph.columns) //Get Adjacent Node to South
     {
         neighborStack.Push(graph.nodes[iValue, jValue +1]);
     }
     if (graph.nodes[iValue, jValue].iValue - 1 >= 0) //Get Adjacent Node to West
     {
         neighborStack.Push(graph.nodes[iValue - 1, jValue]);
     }
     if (graph.nodes[iValue, jValue].iValue + 1 < graph.rows) //Get Adjacent Node to East
     {
         neighborStack.Push(graph.nodes[iValue + 1, jValue]);
     }
 }