Beispiel #1
0
        public static void StartGame(string name)
        {
            try
            {
                GameManager.ListPlayers = DataXML.Load("HighScores.xml");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception error : " + e.Message);
            }

            Player player = Search_Player(name);

            //Player is loaded from the file
            if (player != null)
            {
                if (player.IsDead())
                {
                    CurrentPlayer = new Player(name, 100);
                }
                else
                {
                    CurrentPlayer = player;
                }
            }
            else   //Player is not found
            {
                CurrentPlayer = new Player(name, 100);
            }
        }
Beispiel #2
0
        public static void SaveGame()
        {
            CurrentPlayer.Enemy = null;
            Player player = Search_Player(CurrentPlayer.Name);

            //Player is found
            if (player != null)
            {
                if (player.Gp < CurrentPlayer.Gp)
                {
                    ListPlayers.Remove(player);     // remove the existing player with lower score
                    ListPlayers.Add(CurrentPlayer); //save the player of highest score in List
                }
            }
            else                                //Player is not found
            {
                ListPlayers.Add(CurrentPlayer); //save the player in List
            }
            //Save the List in XML file
            DataXML.Save("HighScores.xml", GameManager.ListPlayers);
        }