/// <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(); } KeyboardState newState = Keyboard.GetState(); Pieza piezaAux = new Pieza(); if (!ganador) { if (newState.IsKeyDown(Keys.Up) && !oldState.IsKeyDown(Keys.Up) && yy + 1 < cortes) { piezaAux = pieza [xx, yy]; pieza [xx, yy] = pieza [xx, yy + 1]; pieza [xx, yy + 1] = piezaAux; yy++; } if (newState.IsKeyDown(Keys.Down) && !oldState.IsKeyDown(Keys.Down) && yy - 1 >= 0) { piezaAux = pieza [xx, yy]; pieza [xx, yy] = pieza [xx, yy - 1]; pieza [xx, yy - 1] = piezaAux; yy--; } if (newState.IsKeyDown(Keys.Right) && !oldState.IsKeyDown(Keys.Right) && xx - 1 >= 0) { piezaAux = pieza [xx, yy]; pieza [xx, yy] = pieza [xx - 1, yy]; pieza [xx - 1, yy] = piezaAux; xx--; } if (newState.IsKeyDown(Keys.Left) && !oldState.IsKeyDown(Keys.Left) && xx + 1 < cortes) { piezaAux = pieza [xx, yy]; pieza [xx, yy] = pieza [xx + 1, yy]; pieza [xx + 1, yy] = piezaAux; xx++; } } oldState = newState; base.Update(gameTime); }
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); } } } }
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]; } } }
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); } } } }
/// <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 (); } KeyboardState newState = Keyboard.GetState(); Pieza piezaAux = new Pieza (); if (!ganador) { if (newState.IsKeyDown (Keys.Up) && !oldState.IsKeyDown (Keys.Up) && yy + 1 < cortes) { piezaAux = pieza [xx, yy]; pieza [xx, yy] = pieza [xx, yy + 1]; pieza [xx, yy + 1] = piezaAux; yy++; } if (newState.IsKeyDown (Keys.Down) && !oldState.IsKeyDown (Keys.Down) && yy - 1 >= 0) { piezaAux = pieza [xx, yy]; pieza [xx, yy] = pieza [xx, yy - 1]; pieza [xx, yy - 1] = piezaAux; yy--; } if (newState.IsKeyDown (Keys.Right) && !oldState.IsKeyDown (Keys.Right) && xx - 1 >= 0) { piezaAux = pieza [xx, yy]; pieza [xx, yy] = pieza [xx - 1, yy]; pieza [xx - 1, yy] = piezaAux; xx--; } if (newState.IsKeyDown (Keys.Left) && !oldState.IsKeyDown (Keys.Left) && xx + 1 < cortes) { piezaAux = pieza [xx, yy]; pieza [xx, yy] = pieza [xx + 1, yy]; pieza [xx + 1, yy] = piezaAux; xx++; } } oldState = newState; base.Update(gameTime); }