Esempio n. 1
0
        //Loads a game from the save file and starts it.
        //Accepts normal eventhandler args.
        //Returns nothing.
        private void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            if (txtBxUser.Text != "" && txtBxUser.Text != null)
            {
                try
                {
                    Game     g         = GameLoader.Load(SaveFileName, false);
                    GamePage newWindow = new GamePage(g.IsCheat, g, this, window);
                    for (int i = 0; i < g.StableWells.Count; ++i)
                    {
                        newWindow.UpdateAnimation(this, new AnimationEventArgs(false, AnimationType.Stable, g.StableWells.Count, g.StableWells[i].Orbs, 0));
                    }

                    for (int i = 0; i < g.UnstableWells.Count; ++i)
                    {
                        newWindow.UpdateAnimation(this, new AnimationEventArgs(false, AnimationType.Unstable, g.StableWells.Count, 0, 0));
                    }

                    for (int i = 0; i < g.AIShips.Count; ++i)
                    {
                        newWindow.UpdateAnimation(this, new AnimationEventArgs(false, AnimationType.AI, g.AIShips.Count, 0, 0));
                    }
                    this.NavigationService.Navigate(newWindow);
                }
                catch (ArgumentException)
                {
                    MessageBox.Show("Cannot find file.");
                }
            }

            else
            {
                MessageBox.Show("You must enter a username!");
            }
        }
Esempio n. 2
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"));
        }