Пример #1
0
 protected void generarRompecabezas()
 {
     for (int y = 0; y < cortes; y++)
     {
         for (int x = 0; x < cortes; x++)
         {
             if (x == xx && y == yy)
             {
                 pieza [x, y] = new Pieza(x, y, new Rectangle(texture.Width + 5, texture.Height + 5, anchoCorte - 5, altoCorte - 5), true);
             }
             else
             {
                 pieza [x, y] = new Pieza(x, y, new Rectangle(anchoCorte * x + 5, altoCorte * y + 5, anchoCorte - 5, altoCorte - 5), false);
             }
         }
     }
 }
Пример #2
0
        protected void mesclarPiezas()
        {
            //Precargar en vector auxiliar

            Pieza[,] piezaAux = new Pieza[nPiezas, nPiezas];

            for (int y = 0; y < cortes; y++)
            {
                for (int x = 0; x < cortes; x++)
                {
                    piezaAux [x, y] = pieza [x, y];
                }
            }

            //Mesclar piezas
            for (int y = 0; y < cortes; y++)
            {
                for (int x = 0; x < cortes; x++)
                {
                    pieza [x, y] = piezaAux [y, x];
                }
            }
        }
Пример #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))
            {
                this.Exit();
            }

            TouchCollection touchCollection = TouchPanel.GetState();

            foreach (TouchLocation tl in touchCollection)
            {
                if ((tl.State == TouchLocationState.Pressed) || (tl.State == TouchLocationState.Moved))
                {
                    if (movimiento == 0)
                    {
                        posIniX = tl.Position.X;
                        posIniY = tl.Position.Y;
                    }
                    movimiento++;
                    if (movimiento == 2)
                    {
                        if (tl.Position.X - posIniX > 10)
                        {
                            accion = 'R';
                        }

                        if (tl.Position.X - posIniX < -10)
                        {
                            accion = 'L';
                        }

                        if (tl.Position.Y - posIniY > 10)
                        {
                            accion = 'D';
                        }

                        if (tl.Position.Y - posIniY < -10)
                        {
                            accion = 'U';
                        }

                        movimiento = 0;
                    }
                }
                else
                {
                    Console.WriteLine(accion);
                    fueMovido = true;
                }
            }


            Pieza piezaAux = new Pieza();

            if (!ganador && fueMovido)
            {
                fueMovido = false;

                if (accion == 'U' && yy + 1 < cortes)
                {
                    piezaAux           = pieza [xx, yy];
                    pieza [xx, yy]     = pieza [xx, yy + 1];
                    pieza [xx, yy + 1] = piezaAux;
                    yy++;
                }

                if (accion == 'D' && yy - 1 >= 0)
                {
                    piezaAux           = pieza [xx, yy];
                    pieza [xx, yy]     = pieza [xx, yy - 1];
                    pieza [xx, yy - 1] = piezaAux;
                    yy--;
                }


                if (accion == 'R' && xx - 1 >= 0)
                {
                    piezaAux           = pieza [xx, yy];
                    pieza [xx, yy]     = pieza [xx - 1, yy];
                    pieza [xx - 1, yy] = piezaAux;
                    xx--;
                }


                if (accion == 'L' && xx + 1 < cortes)
                {
                    piezaAux           = pieza [xx, yy];
                    pieza [xx, yy]     = pieza [xx + 1, yy];
                    pieza [xx + 1, yy] = piezaAux;
                    xx++;
                }
            }

            base.Update(gameTime);
        }
Пример #4
0
 protected void generarRompecabezas()
 {
     for (int y = 0; y < cortes; y++) {
         for (int x = 0; x < cortes; x++) {
             if (x == xx && y == yy) {
                 pieza [x, y] = new Pieza (x, y, new Rectangle (texture.Width + 5, texture.Height + 5, anchoCorte - 5, altoCorte - 5), true);
             } else {
                 pieza [x, y] = new Pieza (x, y, new Rectangle (anchoCorte * x + 5, altoCorte * y + 5, anchoCorte - 5, altoCorte - 5), false);
             }
         }
     }
 }
Пример #5
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)) {
                this.Exit ();

            }

            TouchCollection touchCollection = TouchPanel.GetState ();
            foreach (TouchLocation tl in touchCollection) {
                if ((tl.State == TouchLocationState.Pressed) || (tl.State == TouchLocationState.Moved)) {
                    if (movimiento == 0) {
                        posIniX = tl.Position.X;
                        posIniY = tl.Position.Y;
                    }
                    movimiento++;
                    if (movimiento == 2) {
                        if (tl.Position.X - posIniX > 10) {
                            accion = 'R';
                        }

                        if (tl.Position.X - posIniX < -10) {
                            accion = 'L';
                        }

                        if (tl.Position.Y - posIniY > 10) {
                            accion = 'D';
                        }

                        if (tl.Position.Y - posIniY < -10) {
                            accion = 'U';
                        }

                        movimiento = 0;
                    }
                } else {
                    Console.WriteLine (accion);
                    fueMovido = true;
                }
            }

            Pieza piezaAux = new Pieza ();

            if (!ganador && fueMovido) {

                fueMovido = false;

                if (accion =='U' && yy + 1 < cortes) {
                    piezaAux = pieza [xx, yy];
                    pieza [xx, yy] = pieza [xx, yy + 1];
                    pieza [xx, yy + 1] = piezaAux;
                    yy++;
                }

                if (accion =='D' && yy - 1 >= 0) {
                    piezaAux = pieza [xx, yy];
                    pieza [xx, yy] = pieza [xx, yy - 1];
                    pieza [xx, yy - 1] = piezaAux;
                    yy--;
                }

                if (accion =='R' && xx - 1 >= 0) {
                    piezaAux = pieza [xx, yy];
                    pieza [xx, yy] = pieza [xx - 1, yy];
                    pieza [xx - 1, yy] = piezaAux;
                    xx--;
                }

                if (accion =='L' && xx + 1 < cortes) {
                    piezaAux = pieza [xx, yy];
                    pieza [xx, yy] = pieza [xx + 1, yy];
                    pieza [xx + 1, yy] = piezaAux;
                    xx++;
                }

            }

            base.Update (gameTime);
        }
Пример #6
0
        protected void mesclarPiezas()
        {
            //Precargar en vector auxiliar

            Pieza[,] piezaAux = new Pieza[nPiezas, nPiezas];

            for (int y = 0; y < cortes; y++) {
                for (int x = 0; x < cortes; x++) {
                    piezaAux [x, y] = pieza [x, y];
                }
            }

            //Mesclar piezas
            for (int y = 0; y < cortes; y++) {
                for (int x = 0; x < cortes; x++) {
                    pieza [x, y] = piezaAux [y, x];
                }
            }
        }