Exemplo n.º 1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);


            font = Content.Load <SpriteFont>("SpriteFont");

            pixel = new Texture2D(GraphicsDevice, 1, 1);
            pixel.SetData(new Color[] { Color.White });

            tile   = Content.Load <Texture2D>("tile");
            square = Content.Load <Texture2D>("Box");

            start      = new Game26();
            start.grid = new int[, ]  //setupGrid(start.gridSizeX, start.gridSizeY);
            {
                { 6, 2, 12, 4 },
                { 14, 7, 10, 8 },
                { 9, 3, 1, 11 },
                { 16, 13, 15, 5 }
            };


            int sizex = (graphics.PreferredBackBufferWidth / start.grid.GetLength(1));
            int sizey = (graphics.PreferredBackBufferHeight / start.grid.GetLength(0));

            scale = new Vector2(sizex / (float)square.Width, sizey / (float)square.Height);

            game = new Game25(graphics, StaticVariables.Random, square, tile, font, start.grid, scale);
        }
 public void reset()
 {
     visited       = false;
     distance      = double.PositiveInfinity;
     finalDistance = double.PositiveInfinity;
     founder       = null;
 }
Exemplo n.º 3
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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            elapsedTime += gameTime.ElapsedGameTime;

            if (solution != null && solution.Count != 0)
            {
                if (elapsedTime >= delayTime)
                {
                    game = solution.Dequeue();

                    elapsedTime = TimeSpan.Zero;
                }
            }

            KeyboardState kb = Keyboard.GetState();
            MouseState    ms = Mouse.GetState();

            if ((solution == null || solution.Count == 0) && (kb.IsKeyDown(Keys.R) && lastKeyboardState.IsKeyUp(Keys.R)))
            {
                start.MatchGrid(game);
                start.randomizeGrid(50);
                game.matchGrid(start.grid);
            }

            if (kb.IsKeyDown(Keys.Space) && (solution == null || solution.Count == 0))
            {
                Window.Title = "Loading";
                start.MatchGrid(game);
                Stack <Game26> result = BStar.SolvePuzzle(start, setupGrid(start.gridSizeX, start.gridSizeY));

                solution = new Queue <Game25>();

                Game25 last = null;

                while (result.Count > 0)
                {
                    var yoot = result.Pop();

                    Game25 yeet = new Game25(graphics, StaticVariables.Random, square, tile, font, yoot.grid, scale);

                    solution.Enqueue(yeet);
                    last = yeet;
                }

                start.MatchGrid(last);

                Window.Title = "";
            }

            if ((solution == null || solution.Count == 0))
            {
                game?.update(ms, lastMouseState);
            }

            lastKeyboardState = kb;
            lastMouseState    = ms;

            base.Update(gameTime);
        }