Exemplo n.º 1
0
        public static void EndSession()
        {
            if (renderTarget != null)
            {
                renderTarget.Dispose();
                renderTarget = null;
            }

            if (puzzleSet != null)
            {
                for (int i = 0; i < puzzleSet.Puzzles.Count; i++)
                {
                    if (puzzleSet.Puzzles[i] != null &&
                        puzzleSet.Puzzles[i].PortraitTexture != null)
                    {
                        puzzleSet.Puzzles[i].PortraitTexture.Dispose();
                    }
                }

                if (puzzleSet.TileTexture != null)
                {
                    puzzleSet.TileTexture.Dispose();
                }
                puzzleSet = null;
            }
        }
Exemplo n.º 2
0
        public void PuzzleSet_Subset_Superset_Tests1()
        {
            var sut1       = new PuzzleSet(PuzzleSize.NineByNine);
            var allNumbers = new PuzzleSet(PuzzleSize.NineByNine);

            sut1.AddRange(new byte[] { 1, 2, 3, 4 });
            allNumbers.AddRange(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });

            TestContext.WriteLine("lowNumbers overlaps allNumbers: {0}",
                                  sut1.Overlaps(allNumbers));

            TestContext.WriteLine("allNumbers and lowNumbers are equal sets: {0}",
                                  allNumbers.SetEquals(sut1));

            // Show the results of sub/superset testing
            Assert.True(sut1.IsSubsetOf(allNumbers));
            Assert.True(allNumbers.IsSupersetOf(sut1));
            Assert.True(sut1.IsProperSubsetOf(allNumbers));
            Assert.True(allNumbers.IsProperSupersetOf(sut1));

            // Modify allNumbers to remove numbers that are not in sut1.
            allNumbers.IntersectWith(sut1);

            Assert.True(allNumbers.SetEquals(sut1));

            Assert.True(sut1.IsSubsetOf(allNumbers));
            Assert.True(allNumbers.IsSupersetOf(sut1));
            Assert.False(sut1.IsProperSubsetOf(allNumbers));
            Assert.False(allNumbers.IsProperSupersetOf(sut1));
        }
Exemplo n.º 3
0
        public Player(PlayerSaveData playerData, ContentManager content)
            : this(playerData.SlotNumber)
        {
            if (playerData == null)
            {
                throw new ArgumentNullException("playerData");
            }
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            name = playerData.PlayerName;

            // load starting puzzleset
            PuzzleSet puzzleSet = content.Load <PuzzleSet>(playerData.PuzzleSetSaveData.assetName).Clone() as PuzzleSet;

            puzzleSet.LoadContent(content);

            // apply saved items to puzzleset
            puzzleSet.Statistics = playerData.PuzzleSetSaveData.puzzleSetStatistics;

            for (int i = 0; i < puzzleSet.Puzzles.Count; i++)
            {
                puzzleSet.Puzzles[i].IsCleared        = playerData.PuzzleSetSaveData.IsPuzzleCleared[i];
                puzzleSet.Puzzles[i].IsLocked         = playerData.PuzzleSetSaveData.IsPuzzleLocked[i];
                puzzleSet.Puzzles[i].Statistics       = playerData.PuzzleSetSaveData.AllPuzzleStatistics[i];
                puzzleSet.Puzzles[i].PlayerSolution   = playerData.PuzzleSetSaveData.PlayerSolutions[i];
                puzzleSet.Puzzles[i].IsRenderPortrait = true;
            }
            PuzzleEngine.IsCheckRender = true;

            // load updated puzzleset
            PuzzleEngine.LoadContent(content, puzzleSet);
        }
Exemplo n.º 4
0
        public void PuzzleSet_IntersectWith_Test1()
        {
            var sut1 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut2 = new PuzzleSet(PuzzleSize.NineByNine);

            sut1.AddRange(new byte[] { 1, 2, 3, 4, 5 });
            sut2.AddRange(new byte[] { 3, 4, 5, 6, 7, 8, 9 });

            sut2.IntersectWith(sut1);

            Assert.Equal(new byte[] { 3, 4, 5 }, sut2);
        }
Exemplo n.º 5
0
        public void PuzzleSet_Ctor_BitsInitializes_Test1()
        {
            var sut = new PuzzleSet(PuzzleSize.FourByFour);

            Assert.Equal(4, sut.Bits.Length);

            sut = new PuzzleSet(PuzzleSize.NineByNine);
            Assert.Equal(9, sut.Bits.Length);

            sut = new PuzzleSet(PuzzleSize.SixteenBySixteen);
            Assert.Equal(16, sut.Bits.Length);
        }
Exemplo n.º 6
0
        public void PuzzleSet_GetEnumerator_Test1()
        {
            var sut  = new PuzzleSet(PuzzleSize.NineByNine);
            var list = new List <byte>();

            for (byte i = 1; i < 6; i++)
            {
                sut.Add(i);
                list.Add(i);
            }

            Assert.Equal(sut, list);
        }
Exemplo n.º 7
0
        /// Creates a new PlayerData object from the given Player object.
        public PlayerSaveData(Player player, PuzzleSet puzzleSet)
            : this()
        {
            // check the parameter
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }

            PlayerName        = player.Name;
            SlotNumber        = player.SlotNumber;
            PuzzleSetSaveData = new PuzzleSetSaveData(puzzleSet);
        }
Exemplo n.º 8
0
        public void PuzzleSet_Overlaps_Test1()
        {
            var sut1 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut2 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut3 = new PuzzleSet(PuzzleSize.NineByNine);

            sut1.AddRange(new byte[] { 1, 2, 3 });
            sut2.AddRange(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            sut3.AddRange(new byte[] { 7, 8, 9 });

            Assert.True(sut1.Overlaps(sut2));
            Assert.True(sut2.Overlaps(sut3));
            Assert.False(sut1.Overlaps(sut3));
        }
Exemplo n.º 9
0
        public void PuzzleSet_Ctor_IsValidSize_Test1()
        {
            Assert.Throws <ArgumentOutOfRangeException>(() => new PuzzleSet(PuzzleSize.Undefined));

            var sut = new PuzzleSet(PuzzleSize.FourByFour);

            Assert.Equal(4, sut.MaxValue);

            sut = new PuzzleSet(PuzzleSize.NineByNine);
            Assert.Equal(9, sut.MaxValue);

            sut = new PuzzleSet(PuzzleSize.SixteenBySixteen);
            Assert.Equal(16, sut.MaxValue);
        }
Exemplo n.º 10
0
        public void PuzzleSet_AddRangeCheck_Test1()
        {
            var sut = new PuzzleSet(PuzzleSize.FourByFour);

            Assert.Throws <ArgumentOutOfRangeException>(() => sut.Add(0));
            Assert.Throws <ArgumentOutOfRangeException>(() => sut.Add(5));

            sut = new PuzzleSet(PuzzleSize.NineByNine);
            Assert.Throws <ArgumentOutOfRangeException>(() => sut.Add(0));
            Assert.Throws <ArgumentOutOfRangeException>(() => sut.Add(10));

            sut = new PuzzleSet(PuzzleSize.SixteenBySixteen);
            Assert.Throws <ArgumentOutOfRangeException>(() => sut.Add(0));
            Assert.Throws <ArgumentOutOfRangeException>(() => sut.Add(17));
        }
Exemplo n.º 11
0
        public PuzzleSetSaveData(PuzzleSet puzzleSet)
            : this()
        {
            this.assetName = puzzleSet.AssetName;

            this.puzzleSetStatistics = puzzleSet.Statistics;

            foreach (Puzzle puzzle in puzzleSet.Puzzles)
            {
                AllPuzzleStatistics.Add(puzzle.Statistics);
                PlayerSolutions.Add(puzzle.PlayerSolution);
                IsPuzzleCleared.Add(puzzle.IsCleared);
                IsPuzzleLocked.Add(puzzle.IsLocked);
            }
        }
        public byte PickRandomValueFromPuzzleSet(PuzzleSet puzzleSet)
        {
            byte rv      = 0;
            var  choices = Enumerable.Range(1, puzzleSet.MaxValue)
                           .Select(Convert.ToByte)
                           .Where(puzzleSet.Contains)
                           .ToArray();

            if (choices.Any())
            {
                var index = Random.GetRandomNumber() % choices.Length;
                rv = choices[index];
            }

            return(rv);
        }
Exemplo n.º 13
0
        public void PuzzleSet_UnionWith_Test1()
        {
            var sut1 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut2 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut3 = new PuzzleSet(PuzzleSize.NineByNine);

            sut1.AddRange(new byte[] { 1, 2, 3 });
            sut2.AddRange(new byte[] { 4, 5, 6 });
            sut3.AddRange(new byte[] { 7, 8, 9 });

            sut1.UnionWith(sut3);
            Assert.Equal(new byte[] { 1, 2, 3, 7, 8, 9 }, sut1);

            sut1.UnionWith(sut2);
            Assert.Equal(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, sut1);
        }
Exemplo n.º 14
0
 public void PuzzleSet_AddSyncsWithCount_Test1()
 {
     foreach (var size in new[]
     {
         PuzzleSize.FourByFour,
         PuzzleSize.NineByNine,
         PuzzleSize.SixteenBySixteen
     })
     {
         var sut = new PuzzleSet(size);
         foreach (var value in Enumerable.Range(1, sut.MaxValue).Select(Convert.ToByte))
         {
             Assert.True(sut.Add(value));
             Assert.Equal(value, sut.Count);
         }
     }
 }
Exemplo n.º 15
0
        public static void LoadContent(ContentManager content, PuzzleSet newPuzzleSet)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }
            if (newPuzzleSet == null)
            {
                throw new ArgumentNullException("newPuzzleSet");
            }
            if (newPuzzleSet.Puzzles.Count == 0)
            {
                throw new ArgumentException("No puzzles in puzzleSet");
            }

            cursor.LoadContent(content);
            puzzleSet = newPuzzleSet;            // shoudl i clone here?
        }
Exemplo n.º 16
0
        public void PuzzleSet_Clear_Test1()
        {
            foreach (var size in new[]
            {
                PuzzleSize.FourByFour,
                PuzzleSize.NineByNine,
                PuzzleSize.SixteenBySixteen
            })
            {
                var sut = new PuzzleSet(size);

                Assert.True(sut.AddRange(Enumerable.Range(1, sut.MaxValue).Select(Convert.ToByte)));
                Assert.NotEmpty(sut);
                Assert.Equal(sut.MaxValue, sut.Count);

                sut.Clear();
                Assert.Empty(sut);
            }
        }
Exemplo n.º 17
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];
        }
Exemplo n.º 18
0
        public void PuzzleSet_CopyTo_Test1()
        {
            foreach (var size in new[]
            {
                PuzzleSize.FourByFour,
                PuzzleSize.NineByNine,
                PuzzleSize.SixteenBySixteen
            })
            {
                var sut = new PuzzleSet(size);
                Assert.True(sut.AddRange(Enumerable.Range(1, sut.MaxValue).Select(Convert.ToByte)));

                var actual = new byte[sut.MaxValue];
                sut.CopyTo(actual, 0);

                var expected = Enumerable.Range(1, sut.MaxValue).Select(Convert.ToByte).ToArray();
                Assert.Equal(expected, actual);
            }
        }
Exemplo n.º 19
0
        public void PuzzleSet_Contains_Test1()
        {
            foreach (var size in new[]
            {
                PuzzleSize.FourByFour,
                PuzzleSize.NineByNine,
                PuzzleSize.SixteenBySixteen
            })
            {
                var sut = new PuzzleSet(size);
                foreach (var value in Enumerable.Range(1, sut.MaxValue).Select(Convert.ToByte))
                {
                    Assert.True(sut.Add(value));
                    Assert.Contains(value, sut);

                    sut.Clear();
                    Assert.DoesNotContain(value, sut);
                }
            }
        }
Exemplo n.º 20
0
        public void PuzzleSet_SetEquals_Test1()
        {
            var sut1 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut2 = new PuzzleSet(PuzzleSize.NineByNine);
            var sut3 = new PuzzleSet(PuzzleSize.NineByNine);

            sut1.AddRange(new byte[] { 1, 2, 3 });
            sut2.AddRange(new byte[] { 1, 2, 3 });

            Assert.True(sut1.SetEquals(sut1));
            Assert.True(sut1.SetEquals(sut2));
            Assert.True(sut2.SetEquals(sut1));

            sut2.AddRange(new byte[] { 4, 5, 6 });

            sut2.AddRange(new byte[] { 7, 8, 9 });
            sut3.AddRange(new byte[] { 7, 8, 9 });

            Assert.False(sut1.SetEquals(sut2));
            Assert.False(sut2.SetEquals(sut3));
            Assert.False(sut1.SetEquals(sut3));
        }
        /// <summary>
        /// Seed the second box.
        ///
        /// This is more difficult, but still quick.
        ///
        /// B2's 1st row can be any from B1's 2nd or 3rd
        /// B2's 2nd row must include any remaining from B2's 3rd row, fill in with B1's 1st row
        /// B2's 3rd row is all remaining
        /// </summary>
        public void SeedSecondBox()
        {
            var boxSize    = PuzzleGrid.Size.BoxSize();
            var puzzleSize = PuzzleGrid.Size.ToInt32();

            var firstBoxUsed = CreateArray(boxSize, () => new PuzzleSet(PuzzleGrid.Size));

            // load first box used values
            foreach (var boxCell in Enumerable.Range(0, puzzleSize))
            {
                var cell      = PuzzleBoxes[0][boxCell];
                var cellValue = cell.Value
                                ?? throw new Exception($"Cell at {cell.Coordinate} is null");

                firstBoxUsed[cell.Coordinate.Row].Add(cellValue);
            }

            var usedByRow = CreateArray(boxSize, () => new PuzzleSet(PuzzleGrid.Size));

            // chose values for first row of second box (from first box, second and third rows)
            var firstRowPossibilities = new PuzzleSet(firstBoxUsed[1]);

            firstRowPossibilities.UnionWith(firstBoxUsed[2]);
            for (var i = 0; i < boxSize; i++)
            {
                var value = PickRandomValueFromPuzzleSet(firstRowPossibilities);

                usedByRow[0].Add(value);
                firstRowPossibilities.Remove(value);
            }

            // chose values for second row of the second box
            var secondRowPossibilities = new PuzzleSet(firstBoxUsed[0]);

            secondRowPossibilities.UnionWith(firstBoxUsed[2]);
            secondRowPossibilities.ExceptWith(usedByRow[0]);

            var thirdRowPossibilities = new PuzzleSet(firstBoxUsed[0]);

            thirdRowPossibilities.UnionWith(firstBoxUsed[1]);
            thirdRowPossibilities.ExceptWith(usedByRow[0]);

            while (thirdRowPossibilities.Count > 3)
            {
                var value = PickRandomValueFromPuzzleSet(secondRowPossibilities);

                usedByRow[1].Add(value);
                secondRowPossibilities.Remove(value);
                thirdRowPossibilities.Remove(value);
            }

            // Value for bottom row
            secondRowPossibilities.ExceptWith(thirdRowPossibilities);

            usedByRow[1].UnionWith(secondRowPossibilities);
            usedByRow[2].UnionWith(thirdRowPossibilities);

            // assign values to each row of the box
            for (var row = 0; row < boxSize; row++)
            {
                for (var col = boxSize; col < 2 * boxSize; col++)
                {
                    var value = PickRandomValueFromPuzzleSet(usedByRow[row]);

                    PuzzleGrid[new PuzzleCoordinate(row, col)] = Convert.ToByte(value);
                    usedByRow[row].Remove(value);
                }
            }
        }