private void EndGame()
        {
            string now = DateTime.Now.ToString("dd/MM/yy H:mm:ss");
            Info person = new Info(Gameplay.Username,Gameplay.UserScore,Gameplay.Level,now);

            if (File.Exists("persons.xml"))
            {
                string input = WorkWithFile.SimpleRead1();
                string inputxml = WorkWithFile.Decrypt(input, "HelloWorld");
                WorkWithFile.SimpleWrite1(inputxml);
            }

            Info[] from = WorkWithFile.SimpleRead();
            Info[] persons={person};
            if (from[0] != null)
            {
                persons = new Info[from.Length + 1];
                for (int i = 0; i < persons.Length - 1; i++)
                {
                    persons[i] = from[i];
                }
                persons[persons.Length - 1] = person;
            }

            WorkWithFile.SimpleWrite(persons);
            string output = WorkWithFile.SimpleRead1();
            string outputxml = WorkWithFile.Encrypt(output, "HelloWorld");
            WorkWithFile.SimpleWrite1(outputxml);

            var w1 = new ResultTable();
            w1.Show();
            Close();
        }
Esempio n. 2
0
 /// <summary>
 /// Write data to file
 /// </summary>
 public static void SimpleWrite(Info[] persons)
 {
     XmlSerializer formatter = new XmlSerializer(typeof(Info[]));
     // получаем поток, куда будем записывать сериализованный объект
     using (FileStream fs = new FileStream("persons.xml", FileMode.OpenOrCreate))
     {
        formatter.Serialize(fs, persons);
     }
 }