private static void puzzleCleared(int shapesUsed) { mainScreen.HelpPanel.Off(true); ResetCurrentPuzzleShapes(true, false); CurrentPuzzle.IsCleared = true; CurrentPuzzleSet.UnlockNextPuzzle(); // update statistics & build solution PlayerSolution solution = new PlayerSolution(); solution.PuzzleKey = CurrentPuzzle.Key; solution.SolutionShapes = new List <PlayerSolutionShape>(); foreach (Shape shape in CurrentPuzzleSet.ShapesDict.Values) { if (shape.IsValid) { Vector2 position = new Vector2(shape.DestRect.X, shape.DestRect.Y); PlayerSolutionShape userShape = new PlayerSolutionShape(); userShape.ShapeKey = shape.Key; userShape.OriginPoint = PuzzleEngine.GetPuzzleTilePosition(new Vector2(shape.DestRect.X, shape.DestRect.Y)); userShape.IsFlippedHorizontal = shape.IsFlippedHorizontal; userShape.IsFlippedVertical = shape.IsFlippedVertical; userShape.RotationIdx = shape.CurrentRotationIdx; solution.SolutionShapes.Add(userShape); CurrentPuzzle.Statistics.ShapesUsedKeys.Add(shape.Key); } } CurrentPuzzle.PlayerSolution = solution; CurrentPuzzle.SetCompletedStats(shapesUsed, PuzzleTimer); CurrentPuzzleSet.Statistics += CurrentPuzzle.Statistics; Cursor.CursorMode = CursorState.Hidden; CurrentPuzzle.IsRenderPortrait = true; SelectedPickerEntry.IsRenderEntry = true; IsCheckRender = true; MainScreen.PuzzlePanel.ResetPuzzleName(); MainScreen.PuzzlePanel.InitSolutionDict(solution.SolutionShapes); MainScreen.PuzzlePanel.PanelState = PuzzlePanel.PuzzlePanelState.Cleared; MainScreen.PuzzlePanel.ClearedState = PuzzlePanel.PuzzleClearedState.Prepare; }
public static void DrawTileLayers(SpriteBatch spriteBatch, Puzzle puzzle, Vector2 basePosition) { // check the parameters if (spriteBatch == null) { throw new ArgumentNullException("spriteBatch"); } Rectangle destinationRectangle = new Rectangle(0, 0, puzzle.TileSize.X, puzzle.TileSize.Y); for (int y = 0; y < puzzle.Dimensions.Y; y++) { for (int x = 0; x < puzzle.Dimensions.X; x++) { destinationRectangle.X = (int)(basePosition.X + TILE_OFFSET.X + (puzzle.IsGridShiftX ? puzzle.TileSize.X / 2 : 0)) + x * puzzle.TileSize.X; destinationRectangle.Y = (int)(basePosition.Y + TILE_OFFSET.Y + (puzzle.IsGridShiftY ? puzzle.TileSize.Y / 2 : 0)) + y * puzzle.TileSize.Y; Point puzzlePoint = new Point(x, y); Rectangle tileSourceRectangle = puzzle.GetTileLayerSourceRectangle(puzzlePoint); if (puzzle.GetPuzzleLayerValue(puzzlePoint) == 0) { Rectangle bgSourceRectangle = puzzle.GetBackgroundSourceRectangle(puzzlePoint); spriteBatch.Draw(CurrentPuzzleSet.GetBackgroundTex(puzzle.BackgroundTextureName), destinationRectangle, bgSourceRectangle, Color.White); } if (tileSourceRectangle != Rectangle.Empty) { spriteBatch.Draw(puzzleSet.TileTexture, destinationRectangle, tileSourceRectangle, Color.White); } } } }
/// Update the tile engine. public static void UpdatePuzzle(GameTime gameTime) { if (!isTimerDisabled) { PuzzleEngine.PuzzleTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; } cursor.Update(gameTime); CurrentPuzzleSet.Update(gameTime); hintManager.Update(gameTime); // checkSolved will be set by shapeDropped handleInput action because any dropped shape can trigger a solution if (checkForSolved) { int solution = CurrentPuzzle.CheckSolved(CurrentPuzzleSet.ShapesDict); if (solution != 0) { puzzleCleared(solution); } checkForSolved = false; } }