private void confirmBackToPickerPanel()
        {
            helpPanel.Off(true);

            puzzlePanel.ResetPuzzleName();
            PuzzleEngine.ResetCurrentPuzzleStatistics();
            PuzzleEngine.ResetCurrentPuzzleShapes(false, false);
            puzzlePanel.PanelState = PuzzlePanel.PuzzlePanelState.PreShutdown;
        }
        private void endSession()
        {
            Session.EndSession();
            PuzzleEngine.EndSession();

            puzzlePanel  = null;
            pickerPanel  = null;
            creditsPanel = new CreditsPanel(this);
            sessionReset();
        }
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Process
        ///</summary>
        public void ProcessIntersectionEliminateProcessTestHelper <TKey>()
        {
            Keys <int> group1In = new Keys <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            Keys <int> group2In = new Keys <int>()
            {
                1, 2, 3, 10, 11, 12, 19, 20, 21
            };
            ISpace <int> space = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            for (int i = 1; i < 22; i++)
            {
                space.Add(i, new Possible()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                });
            }
            // remove 1 from part of row1
            for (int i = 4; i < 10; i++)
            {
                space[i].Values.Remove(1);
            }
            space[1].Values.Remove(5);
            space[2].Values.Remove(5);
            space[3].Values.Remove(5);
            IPuzzle <int>       puzzle = new PuzzleBase <int>(space);
            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

            // Action
            int jobsAdded = ConstraintMutuallyExclusive <int> .CreateCompleteIntersectActions(group1In, group2In, engine);

            // Tests
            Assert.AreEqual(1, jobsAdded, "Incorrect filter job count");
            Keys <int> expected = new Keys <int>()
            {
                10, 11, 12, 19, 20, 21
            };
            IJobFilter <int> job = engine.Peek() as IJobFilter <int>;

            Assert.IsNotNull(job);
            Assert.AreEqual(6, job.Keys.Count, "Unexpected key change.");
            Assert.IsTrue(expected.SetEquals(job.Keys), "Unexpected Keys Changed. Should be 10,11,12,19,20,21");
            Possible expectedValues = new Possible()
            {
                1
            };

            Assert.IsTrue(expectedValues.SetEquals(job.Filter), "Unexpected values. Should have eliminated 1");
        }
Exemple #4
0
        //
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for CreateSearchJobs
        ///</summary>
        public void ApplyConstraintsTestHelper <TKey>()
        {
            // Initialise Space
            ISpace <int> space = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            for (int i = 1; i < 82; i++)
            {
                space.Add(i, new Possible()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                });
            }

            IConstraints <int> constraints = new Constraints <int>();
            Keys <int>         group       = new Keys <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            IConstraint <int> constraint = new ConstraintMutuallyExclusive <int>("row1", group);
            Keys <int>        group2     = new Keys <int>()
            {
                1, 2, 3, 10, 11, 12, 19, 20, 21
            };

            IConstraint <int> constraint2 = new ConstraintMutuallyExclusive <int>("grid1", group2);

            constraints.Add(constraint);
            constraints.Add(constraint2);

            IPuzzle <int> puzzle = new PuzzleBase <int>();

            puzzle.Space       = space;
            puzzle.Constraints = constraints;
            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

            ISpace <int> init = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            init[1] = new Possible()
            {
                1
            };
            engine.SetInitialValues(init);
            Assert.AreEqual(1, engine.Count, "Constraint not added to queue");
            engine.DoNextJob();
            // this brings back keys 2 and 3 with constraint grid1? is
            Assert.AreEqual(2, engine.Count, "MutuallyExclusive constraint did not create jobs");
        }
        public void RunAlgorithmTest()
        {
            // Initialise Space
            ISpace <int> space = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            for (int i = 1; i < 82; i++)
            {
                space.Add(i, new Possible()
                {
                    1, 2, 3, 4, 5, 6, 7, 8, 9
                });
            }

            // Initialise one group (top row)
            Keys <int> group = new Keys <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            IPuzzle <int>       puzzle = new PuzzleBase <int>(space);
            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

            // Action
            space[1].SetValue(1);
            Keys <int> keysInner = new Keys <int>()
            {
                1
            };
            int jobsAdded = ConstraintMutuallyExclusive <int> .CreateCompleteSetActions(keysInner, group, engine);


            // Test
            Keys <int> expectedK = new Keys <int>()
            {
                2, 3, 4, 5, 6, 7, 8, 9
            };
            Possible expectedV = new Possible()
            {
                1
            };
            IJobFilter <int> job    = engine.Peek() as IJobFilter <int>;
            Keys <int>       actual = job.Keys;
            IPossible        filter = job.Filter;

            // Check the algorithm returned 8 changes
            Assert.AreEqual(8, actual.Count(), "Algorithm Eliminate did not return 8 changes");
            Assert.IsTrue(expectedK.SetEquals(actual));
            Assert.AreEqual(1, filter.Count, "Filter value incorrect");
            Assert.IsTrue(expectedV.SetEquals(filter), "Filter values incorrect");
        }
        public void Update(GameTime gameTime)
        {
            switch (panelState)
            {
            case PickerPanelState.Closed:
                if (StorageManager.Instance.IsRefreshRequired)
                {
                    StorageManager.Instance.RefreshSaveGameDescriptions();
                    StorageManager.Instance.IsRefreshRequired = false;
                }

                if (PuzzleEngine.IsOnReplay)
                {
                    PuzzleEngine.ResetCurrentPuzzleOnReplay();

                    Session.QuickSave();

                    PuzzleEngine.IsOnReplay = false;
                }

                if (isReadyForPuzzle)
                {
                    isReadyForPuzzle = false;
                    parentScreen.IsReadyForPuzzle = true;
                }
                break;

            case PickerPanelState.Opening:
                basePosition.Y += SPEED_PANEL;
                if (basePosition.Y >= ANCHOR_PANELOPEN_Y)
                {
                    basePosition.Y = ANCHOR_PANELOPEN_Y;
                    panelState     = PickerPanelState.Open;
                }
                break;

            case PickerPanelState.Open:
                parentScreen.HelpPanel.On();
                updateRotation(gameTime);
                pickerConsole.Update(gameTime);
                break;

            case PickerPanelState.Closing:
                basePosition.Y -= SPEED_PANEL;
                if (basePosition.Y <= ANCHOR_PANELCLOSED_Y)
                {
                    basePosition.Y = ANCHOR_PANELCLOSED_Y;
                    panelState     = PickerPanelState.Closed;
                }
                break;
            }
        }
Exemple #7
0
        /// Starting a New Session
        /// Start a new session based on the data provided.
        public static void StartNewSession(GameStartDescription gameStartDescription, ScreenManager screenManager, MainGameScreen introScreen)
        {
            // check the parameters
            if (gameStartDescription == null)
            {
                throw new ArgumentNullException("gameStartDescripton");
            }
            if (screenManager == null)
            {
                throw new ArgumentNullException("screenManager");
            }
            if (introScreen == null)
            {
                throw new ArgumentNullException("gameplayScreen");
            }

            // end any existing session
            EndSession();

            // create a new singleton
            singleton = new Session(screenManager);

            ContentManager sessionContent = screenManager.SessionContent;

            singleton.player = new Player(gameStartDescription.SaveSlotNumber);

            PuzzleSet puzzleSet = sessionContent.Load <PuzzleSet>(Path.Combine(@"PuzzleSets", gameStartDescription.PuzzleSetContentName)).Clone() as PuzzleSet;

            puzzleSet.LoadContent(sessionContent);

            puzzleSet.ResetPuzzleLocks();

            PuzzleEngine.LoadContent(sessionContent, puzzleSet);
            PuzzleEngine.MainScreen.CreditsPanel.LoadContent(sessionContent);

            foreach (Puzzle puzzle in puzzleSet.Puzzles)
            {
                puzzle.IsRenderPortrait = true;
            }
            PuzzleEngine.IsCheckRender = true;

//            gamer = SignedInGamer.SignedInGamers[InputManager.PlayerIndex];
        }
        public void RunAlgorithmEliminateTest1()
        {
            // Initialise Possible
            IPossible possibleAll = new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };

            // Initialise Space
            ISpace <int> space = new Space <int>(new Possible()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            });

            for (int i = 1; i < 82; i++)
            {
                space.Add(i, new Possible(possibleAll));
            }

            // Initialise one group (top row)
            Keys <int> group = new Keys <int>();

            for (int i = 1; i < 10; i++)
            {
                group.Add(i);
            }
            IPuzzle <int>       puzzle = new PuzzleBase <int>(space);
            IPuzzleEngine <int> engine = new PuzzleEngine <int>(puzzle);

            // Action
            Possible values2To9 = new Possible(possibleAll);

            values2To9.Remove(1);
            Keys <int> keysInner = new Keys <int>();

            for (int j = 2; j < 10; j++)
            {
                keysInner.Add(j);
                space[j] = new Possible(values2To9);
            }
            int jobsAdded = ConstraintMutuallyExclusive <int> .CreateCompleteSetActions(keysInner, group, engine);

            Assert.AreEqual(1, engine.Count);

            // Test
            Keys <int> expectedK = new Keys <int>()
            {
                1
            };
            IPossible expectedV = new Possible()
            {
                2, 3, 4, 5, 6, 7, 8, 9
            };

            IJobFilter <int> job    = engine.Peek() as IJobFilter <int>;
            Keys <int>       actual = job.Keys;
            IPossible        filter = job.Filter;

            Assert.AreEqual(1, actual.Count(), "Algorithm Eliminate did not return 8 changes");
            Assert.IsTrue(expectedK.SetEquals(actual));
            Assert.AreEqual(8, filter.Count, "Filter value incorrect");
            Assert.IsTrue(expectedV.SetEquals(filter), "Filter values incorrect");
        }
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if (!InputManager.IsPlayerIndexDetected)
            {
//                System.Diagnostics.Debug.WriteLine($"-BEFOR- IsPlayerIndexDetected: {InputManager.IsPlayerIndexDetected}");
                InputManager.DetectPlayerIndex();
//                System.Diagnostics.Debug.WriteLine($"-AFTER- IsPlayerIndexDetected: {InputManager.IsPlayerIndexDetected}");
            }

            StorageManager.Instance.Update(gameTime);

            if (PuzzleEngine.IsCheckRender)
            {
                PuzzleEngine.RenderTextures();
            }

            switch (mode)
            {
            case MainGameScreenMode.ShowSignIn:
                if (signInTask == null)
                {
                    signInTask = SignInManager.Instance.SignIn();
                }

                /*
                 * else if (signInTask.IsCompleted)
                 * {
                 *  if (signInTask.Result)
                 *  {
                 *      // sign-in successful
                 *      mode = MainGameScreenMode.Closed;
                 *  }
                 *  else
                 *  {
                 *      // sign-in failure
                 *      mode = MainGameScreenMode.HandleSignInFailure;
                 *  }
                 *  signInTask = null;
                 * }
                 */
                else
                {
                    ShowSigningInMessage();
                    mode = MainGameScreenMode.SigningIn;
                }
                break;

            case MainGameScreenMode.SigningIn:
                if (signInTask.IsCompleted)
                {
                    signingInScreen.ExitScreen();

                    if (signInTask.Result)
                    {
                        // sign-in successful
                        mode = MainGameScreenMode.Closed;
                    }
                    else
                    {
                        // sign-in failure
                        mode = MainGameScreenMode.HandleSignInFailure;
                    }
                    signInTask = null;
                }
                break;

            case MainGameScreenMode.HandleSignInFailure:
//                    if (!Guide.IsVisible)
//                    {
                ShowSignInWarning();
                mode = MainGameScreenMode.Closed;
//                    }

                break;

            case MainGameScreenMode.ShowSignedOutMessage:
                //#if XBOX
                //                    if (!Guide.IsVisible)
                //#endif
                ShowSignOutWarning();
                mode = MainGameScreenMode.Closed;
//                    signInTask = null;
//                    }
                break;

/*
 *              case MainGameScreenMode.HandleSignedOutResult:
 *                  if (signedOutResult.IsCompleted)
 *                  {
 *                      mode = MainGameScreenMode.ResetGame;
 *                  }
 *                  break;
 */



            case MainGameScreenMode.ResetGame:
                InputManager.Initialize();
                InputManager.ClearPlayerIndex();
                StorageManager.Instance.Reset();
                endSession();

                ScreenManager.AddScreen(new SplashScreen(false));

                slotPanel.Reset();
                AudioManager.StopMusic();

                doorRightPosition       = new Vector2(ANCHOR_DOORCLOSED_RIGHT_X, 0);
                doorRightShadowPosition = new Vector2(ANCHOR_DOORSHADOWCLOSED_RIGHT_X, 0);
                doorLeftPosition        = Vector2.Zero;
                doorLeftShadowPosition  = Vector2.Zero;

                helpPanel.Off(false);

                mode = MainGameScreenMode.Closed;

                break;

            case MainGameScreenMode.Open:
                break;

            case MainGameScreenMode.Closed:
                if (!isStorageMessageDisplayed && IsActive && StorageManager.Instance.IsFirstPassDone)
                {
                    ShowStorageWarning(StorageDeviceWarningType.AutoSaveWarn);
                }
                break;

            case MainGameScreenMode.DelayOpening:
                openingDelayTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (openingDelayTimer >= OPENING_DELAY_MAX)
                {
                    openingDelayTimer = 0;
                    mode = MainGameScreenMode.Opening;
                    slotPanel.Open();
                }
                break;

            case MainGameScreenMode.Opening:
                if (StorageManager.Instance.IsRefreshRequired)
                {
                    StorageManager.Instance.RefreshSaveGameDescriptions();
                    StorageManager.Instance.IsRefreshRequired = false;
                }

                doorRightPosition.X       += DEFAULT_DOORSPEED_RIGHT;
                doorRightShadowPosition.X += DEFAULT_DOORSPEED_RIGHT;
                doorLeftPosition.X        -= DEFAULT_DOORSPEED_LEFT;
                doorLeftShadowPosition.X  -= DEFAULT_DOORSPEED_LEFT;

                if (doorRightPosition.X >= ANCHOR_DOOROPEN_RIGHT_X)
                {
                    doorRightPosition.X = ANCHOR_DOOROPEN_RIGHT_X;
                }
                if (doorLeftPosition.X <= ANCHOR_DOOROPEN_LEFT_X)
                {
                    doorLeftPosition.X = ANCHOR_DOOROPEN_LEFT_X;
                }
                if (doorLeftPosition.X == ANCHOR_DOOROPEN_LEFT_X &&
                    doorRightPosition.X == ANCHOR_DOOROPEN_RIGHT_X)
                {
                    mode = MainGameScreenMode.SlotPanel;
                }
                break;

            case MainGameScreenMode.SlotPanel:
                if (isReadyToLoad)
                {
                    isLoadConfirmed = false;

                    AudioManager.PopMusic();

                    stopCogs(true);
                    resetTexture();

                    mode        = MainGameScreenMode.Loading;
                    loadingMode = LoadingMode.Starting;
                }
                break;

            case MainGameScreenMode.PickerPanel:
                if (isReadyForPuzzle)
                {
                    PuzzleEngine.SetPuzzle();

                    mode = MainGameScreenMode.PuzzlePanel;
                    puzzlePanel.Open();
                    isReadyForPuzzle = false;
                }
                break;

            case MainGameScreenMode.PuzzlePanel:
                if (isBackToPicker)
                {
                    mode = MainGameScreenMode.PickerPanel;
                    pickerPanel.Open();
                    isBackToPicker = false;
                }
                break;

            case MainGameScreenMode.CreditsPanel:

                break;

            case MainGameScreenMode.Closing:
                doorRightPosition.X       -= DEFAULT_DOORSPEED_RIGHT;
                doorRightShadowPosition.X -= DEFAULT_DOORSPEED_RIGHT;
                doorLeftPosition.X        += DEFAULT_DOORSPEED_LEFT;
                doorLeftShadowPosition.X  += DEFAULT_DOORSPEED_LEFT;

                if (doorRightPosition.X <= ANCHOR_DOORCLOSED_RIGHT_X)
                {
                    doorRightPosition.X = ANCHOR_DOORCLOSED_RIGHT_X;
                }
                if (doorLeftPosition.X >= ANCHOR_DOORCLOSED_LEFT_X)
                {
                    doorLeftPosition.X = ANCHOR_DOORCLOSED_LEFT_X;
                }
                if (doorLeftPosition.X == ANCHOR_DOORCLOSED_LEFT_X &&
                    doorRightPosition.X == ANCHOR_DOORCLOSED_RIGHT_X)
                {
                    mode = MainGameScreenMode.Closed;

                    AudioManager.PopMusic();

                    endSession();
                }
                break;

            case MainGameScreenMode.Exiting:
                if (ScreenState == ScreenState.FinishedExiting)
                {
                    ScreenManager.Game.Exit();
                }
                break;

            case MainGameScreenMode.Loading:
                switch (loadingMode)
                {
                case LoadingMode.Starting:
                    loadingAlpha += LOAD_ALPHA_STEP;
                    if (loadingAlpha >= 1)
                    {
                        loadingMode  = LoadingMode.Processing;
                        loadingAlpha = 1;
                    }
                    break;

                case LoadingMode.Finishing:
                    loadingPauseTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;

                    if (loadingPauseTimer >= LOADING_PAUSE_LIMIT)
                    {
                        loadingAlpha -= LOAD_ALPHA_STEP;
                        if (loadingAlpha <= 0)
                        {
                            loadingPauseTimer = 0;

                            loadingAlpha = 0;
                            startCogs(true);

                            AudioManager.PlayMusic("bgCogsTurning");

                            loadingMode = LoadingMode.Finished;
                        }
                    }
                    break;

                case LoadingMode.Finished:
                    mode = MainGameScreenMode.PickerPanel;
                    pickerPanel.Open();
                    break;

                case LoadingMode.Processing:
                    // load new or saved game
                    if (isNewGame)
                    {
                        GameStartDescription gsd = ScreenManager.GlobalContent.Load <GameStartDescription>("NewGameDescription");
                        gsd.SaveSlotNumber = slotPanel.CurrentSlot.SlotNumber;
                        pickerPanel        = new PickerPanel(this, gsd);
                        puzzlePanel        = new PuzzlePanel(this);
                        pickerPanel.LoadContent(ScreenManager.SessionContent);
                        puzzlePanel.LoadContent(ScreenManager.SessionContent);

                        Session.QuickSave();

                        LoadProcessingComplete();
                    }
                    else if (!isLoadProcessingFirstPassDone)
                    {
                        pickerPanel = new PickerPanel(this, slotPanel.CurrentSlot.SaveGameDescription);
                        puzzlePanel = new PuzzlePanel(this);
                        pickerPanel.LoadContent(ScreenManager.SessionContent);
                        puzzlePanel.LoadContent(ScreenManager.SessionContent);
                        isLoadProcessingFirstPassDone = true;
                    }

                    break;
                }
                break;

            case MainGameScreenMode.Paused:

                switch (pauseMode)
                {
                case PauseMode.Waiting:
                    break;

                case PauseMode.Starting:
                    pauseAlpha += PAUSE_ALPHA_STEP;
                    if (pauseAlpha >= 1)
                    {
                        pauseMode  = PauseMode.Paused;
                        pauseAlpha = 1;
                    }
                    break;

                case PauseMode.Paused:
                    break;

                case PauseMode.Stopping:
                    pauseAlpha -= PAUSE_ALPHA_STEP;
                    if (pauseAlpha <= 0)
                    {
                        pauseMode = PauseMode.Waiting;
                        mode      = MainGameScreenMode.PuzzlePanel;
                        startCogs(true);

                        AudioManager.PlayMusic("bgCogsTurning");

                        puzzlePanel.startCogs();
                        PuzzleEngine.IsTimerDisabled = false;
                        pauseAlpha = 0;

                        IsPaused = false;
                    }
                    break;
                }
                break;
            }

            if (mode != MainGameScreenMode.Closed && mode != MainGameScreenMode.Exiting)
            {
                if (helpPanel != null)
                {
                    helpPanel.Update(gameTime);
                }
                if (slotPanel != null)
                {
                    slotPanel.Update(gameTime);
                }
                if (pickerPanel != null)
                {
                    pickerPanel.Update(gameTime);
                }
                if (puzzlePanel != null)
                {
                    puzzlePanel.Update(gameTime);
                }
                if (creditsPanel != null)
                {
                    creditsPanel.Update(gameTime);
                }
            }

            if (cogSpritesList != null)
            {
                foreach (BackgroundCogSprite cog in cogSpritesList)
                {
                    cog.Update(gameTime);
                }
            }
        }