예제 #1
0
        public void Test_Load_Save()
        {
            Game game1 = new Game(false);

            game1.Initialize();
            game1.Player.Xcoor        = 23.17;
            game1.Player.Ycoor        = 23.17;
            game1.StableWells[3].Orbs = 4;
            GameLoader.Save(game1, Path.Combine(Directory.GetCurrentDirectory(), "Saved Games/temp.json"));
            Game game2 = GameLoader.Load(Path.Combine(Directory.GetCurrentDirectory(), "Saved Games/temp.json"), false);

            Assert.AreEqual(game1.Orbs.Count, game2.Orbs.Count);
            for (int i = 0; i < game2.Orbs.Count; i++)
            {
                Assert.AreEqual(game1.Orbs[i].Color, game2.Orbs[i].Color);
                Assert.AreEqual(game1.Orbs[i].Xcoor, game2.Orbs[i].Xcoor, 0.5);
                Assert.AreEqual(game1.Orbs[i].Ycoor, game2.Orbs[i].Ycoor, 0.5);
            }

            for (int i = 0; i < game2.StableWells.Count; i++)
            {
                Assert.AreEqual(game1.StableWells[i].Strength, game2.StableWells[i].Strength, 0.5);
                Assert.AreEqual(game1.StableWells[i].Xcoor, game2.StableWells[i].Xcoor, 0.5);
                Assert.AreEqual(game1.StableWells[i].Ycoor, game2.StableWells[i].Ycoor, 0.5);
                Assert.AreEqual(game1.StableWells[i].TicksLeft, game2.StableWells[i].TicksLeft);
                Assert.AreEqual(game1.StableWells[i].Orbs, game2.StableWells[i].Orbs);
            }
            for (int i = 0; i < game2.UnstableWells.Count; i++)
            {
                Assert.AreEqual(game1.UnstableWells[i].Strength, game2.UnstableWells[i].Strength, 0.5);
                Assert.AreEqual(game1.UnstableWells[i].Xcoor, game2.UnstableWells[i].Xcoor, 0.5);
                Assert.AreEqual(game1.UnstableWells[i].Ycoor, game2.UnstableWells[i].Ycoor, 0.5);
                Assert.IsTrue(game2.UnstableWells[i].IsStable);
                Assert.AreEqual(game1.UnstableWells[i].TicksLeft, game2.UnstableWells[i].TicksLeft);
            }
            Assert.IsTrue(Enumerable.SequenceEqual(game1.Player.Orbs, game2.Player.Orbs));
            Assert.AreEqual(game1.Player.Points, game2.Player.Points);
            Assert.AreEqual(game1.Player.Xcoor, game2.Player.Xcoor, 0.5);
            Assert.AreEqual(game1.Player.Ycoor, game2.Player.Ycoor, 0.5);

            File.Delete(Path.Combine(Directory.GetCurrentDirectory(), "Saved Games/temp.json"));
        }