Пример #1
0
 private void AbortTracing()
 {
     if (SoundManager.IsPlaying(SoundLoop.Tracing))
     {
         SoundManager.PlayOnce(Sound.AbortTracing);
     }
     SoundManager.StopLoop(SoundLoop.Tracing);
     SoundManager.StopLoop(SoundLoop.PathComplete);
     panelState.ResetToNeutral();
     line = lineMirror = null;
 }
Пример #2
0
        public override void SetScreenSize(Point screenSize)
        {
            base.SetScreenSize(screenSize);

            // Save some info needed to rebuild lines
            int mainStartPointIndex = -1, mirrorStartPointIndex = -1;

            if (line != null)
            {
                mainStartPointIndex = startPoints.FindIndex(x => x == line.StartCircle);
            }
            if (lineMirror != null)
            {
                mirrorStartPointIndex = startPoints.FindIndex(x => x == lineMirror.StartCircle);
            }

            Point oldPanelZeroPoint = renderer.PuzzleConfig.Location;
            int   oldNodePadding    = renderer.NodePadding;

            // Update renderer
            renderer.SetScreenSize(screenSize);
            startPoints = renderer.StartPoints;
            endPoints   = renderer.EndPoints;
            walls       = renderer.Walls;

            // Update textures size
            backgroundTexture       = new RenderTarget2D(GraphicsDevice, screenSize.X, screenSize.Y);
            tempLineTexture         = new RenderTarget2D(GraphicsDevice, screenSize.X, screenSize.Y);
            lineTexture             = new RenderTarget2D(GraphicsDevice, screenSize.X, screenSize.Y);
            lineFadeTexture         = new RenderTarget2D(GraphicsDevice, screenSize.X, screenSize.Y);
            errorsBlinkTexture      = new RenderTarget2D(GraphicsDevice, screenSize.X, screenSize.Y);
            eliminatedErrorsTexture = new RenderTarget2D(GraphicsDevice, screenSize.X, screenSize.Y);

            // Update bloom fx
            bloomFilter?.UpdateResolution(screenSize.X, screenSize.Y);
            // Redraw background
            renderer.RenderPanelToTexture(backgroundTexture, true);

            UpdateButtonsPosition();

            // Update lines
            if (line != null)
            {
                line.UpdateHitboxes(renderer.LineWidth, startPoints[mainStartPointIndex], panel.Width, oldPanelZeroPoint, oldNodePadding, renderer.PuzzleConfig.Location, renderer.NodePadding);
            }
            if (lineMirror != null)
            {
                lineMirror.UpdateHitboxes(renderer.LineWidth, startPoints[mirrorStartPointIndex], panel.Width, oldPanelZeroPoint, oldNodePadding, renderer.PuzzleConfig.Location, renderer.NodePadding);
                SolutionLine.SynchronizeLines(line, lineMirror, renderer.PuzzleConfig.Location, renderer.NodePadding);
            }
        }
Пример #3
0
 public void LoadNewPanel(Puzzle panel)
 {
     if (renderer.SetPanel(panel))
     {
         line       = lineMirror = null;
         this.panel = panel;
         panelState.ResetToNeutral();
         startPoints = renderer.StartPoints;
         endPoints   = renderer.EndPoints;
         walls       = renderer.Walls;
         renderer.RenderPanelToTexture(backgroundTexture, true);
         UpdateButtonsColor();
         UpdateButtonsPosition();
     }
 }
Пример #4
0
        private void HandleScreenTap()
        {
            Point?tap = GetTapPosition();

            if (tap.HasValue)
            {
                if (!(panelState.State.HasFlag(PanelStates.EliminationStarted) && !panelState.State.HasFlag(PanelStates.EliminationFinished)))
                {
                    if (line == null || panelState.State.HasFlag(PanelStates.Solved))
                    {
                        foreach (Rectangle startPoint in startPoints)
                        {
                            if (startPoint.Contains(tap.Value))
                            {
                                InputManager.LockMouse();
                                panelState.ResetToNeutral();
                                SoundManager.PlayOnce(Sound.StartTracing);
                                SoundManager.PlayLoop(SoundLoop.Tracing);
                                line = new SolutionLine(startPoint.Center - (new Point(renderer.LineWidth / 2)), renderer.LineWidth, startPoint);
                                if (panel is SymmetryPuzzle symPanel)
                                {
                                    if (symPanel.Y_Mirrored)
                                    {
                                        Point     mirPoint      = renderer.PuzzleConfig.Location + renderer.PuzzleConfig.Location + renderer.PuzzleConfig.Size - startPoint.Center - (new Point(renderer.LineWidth / 2));
                                        Rectangle mirStartPoint = startPoints.Find(x => x.Contains(mirPoint));
                                        lineMirror = new SolutionLine(RectifyLinePosition(mirPoint), renderer.LineWidth, mirStartPoint);
                                    }
                                    else
                                    {
                                        Point     mirPoint      = new Point(renderer.PuzzleConfig.Location.X * 2 + renderer.PuzzleConfig.Size.X - startPoint.Center.X - renderer.LineWidth / 2, startPoint.Center.Y - renderer.LineWidth / 2);
                                        Rectangle mirStartPoint = startPoints.Find(x => x.Contains(mirPoint));
                                        lineMirror = new SolutionLine(RectifyLinePosition(mirPoint), renderer.LineWidth, mirStartPoint);
                                    }
                                }

                                break;
                            }
                        }
                    }
                    else
                    {
                        InputManager.UnlockMouse();
                        SoundManager.StopLoop(SoundLoop.Tracing);
                        SoundManager.StopLoop(SoundLoop.PathComplete);

                        // Check if line head is in the end point
                        foreach (var endPoint in endPoints)
                        {
                            if (endPoint.IntercetionPercent(line.Head) > 0.4f)
                            {
                                // Place line head rignt in the end, nice and tight
                                Point headOffset = endPoint.Rectangle.Location - line.Head.Location;
                                MoveLine(headOffset.ToVector2());

                                // Retrieve Solution from the line and check for errors
                                List <Error> errors   = null;
                                List <int>   solution = line.GetSolution(panel.Width, renderer.PuzzleConfig.Location, renderer.NodePadding);
                                if (panel.SetSolution(solution))
                                {
                                    errors = panel.CheckForErrors();
                                }

                                // Split errors into true errors and the ones, that are eliminated by respective rules
                                var trueErrors       = errors.Where(x => x.IsEliminated == false).ToList();
                                var eliminatedErrors = errors.Where(x => x.IsEliminated == true).ToList();

                                // If there are eliminated errors, initialize elimination process
                                if (eliminatedErrors.Count() > 0)
                                {
                                    SoundManager.PlayOnce(Sound.PotentialFailure);
                                    // Draw all errors in red as for now
                                    renderer.RenderErrorsToTexture(errorsBlinkTexture, errors, false);

                                    // Begin black line fade out as if there was an error
                                    RenderLinesToTexture(lineFadeTexture);
                                    panelState.InvokeFadeOut(true);
                                    // And start elimination timer
                                    panelState.InitializeElimination();

                                    // This event will be executed a few seconds later, after elimination is complete
                                    Action handler = null;
                                    handler = () =>
                                    {
                                        SoundManager.PlayOnce(Sound.EliminatorApply);
                                        // Re-draw true errors in red and eliminated errors separately
                                        renderer.RenderErrorsToTexture(errorsBlinkTexture, trueErrors, false);
                                        renderer.RenderErrorsToTexture(eliminatedErrorsTexture, eliminatedErrors, true);

                                        // If there are no true errors, then panel is solved
                                        if (trueErrors.Count() == 0)
                                        {
                                            // Setting success will stop lines fading process, but retain eliminated errors intact
                                            SetPanelSuccess();
                                        }
                                        else
                                        {
                                            // If there are true errors => delete the lines
                                            // They will continue to fade out and errors will continue to blink
                                            line = lineMirror = null;
                                            SoundManager.PlayOnce(Sound.Failure);
                                        }

                                        // Don't forget to unsubscribe ffs!
                                        panelState.EliminationFinished -= handler;
                                    };
                                    panelState.EliminationFinished += handler;
                                }
                                // If there are no eliminated errors, everything happens instantly
                                else
                                {
                                    // If there are no true errors, then panel is solved
                                    if (trueErrors.Count() == 0)
                                    {
                                        SetPanelSuccess();
                                    }
                                    else
                                    {
                                        // If there are true errors => start fading process and delete the lines
                                        RenderLinesToTexture(lineFadeTexture);
                                        renderer.RenderErrorsToTexture(errorsBlinkTexture, errors, false);
                                        panelState.InvokeFadeOut(true);
                                        line = lineMirror = null;
                                        SoundManager.PlayOnce(Sound.Failure);
                                    }
                                }

                                return;
                            }
                        }

                        // If we looked through every endpoint and line head is not in any of them
                        // Then simply delete lines and fade them out without errors
                        RenderLinesToTexture(lineFadeTexture);
                        panelState.InvokeFadeOut(false);
                        line = lineMirror = null;
                        SoundManager.PlayOnce(Sound.AbortTracing);
                    }
                }
            }
        }