Dunkleosteus - Listina.cs
C# .NET
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using System.IO;
using System.Windows;
using Microsoft.Win32;
namespace Dunkleosteus
{
public class Listina
{
public int Skore { get; private set; } // Bodové skóre
public int Pocitadlo { get; private set; } // Počítadlo řešitelů
public string Cesta { get; private set; } // Cesta k souboru
public string NovyZapis { get; private set; } // Nový zápis do žebříčku
public string Retezec { get; private set; } // Výpis řešitelů
public string VratVypis { get; private set; } // To, co pošleme zpátky
public List<Hrac> SeznamHracu { get; private set; } // List na řešitele
public Listina()
{
SeznamHracu = new List<Hrac>();
Skore = 0;
NovyZapis = "";
Cesta = "vysledky.xml";
Retezec = String.Empty;
}
public string UkazListinu()
{
Nacti();
VypisVysledky();
return VratVypis;
}
// Načteme dokument
public void Nacti()
{
XmlSerializer serializer = new XmlSerializer(SeznamHracu.GetType());
if (File.Exists(Cesta))
{
using (StreamReader sr = new StreamReader(Cesta))
{
// Když jsme něco načetli, aktualizujeme SeznamHracu
SeznamHracu = (List<Hrac>)serializer.Deserialize(sr);
}
}
else
{
// Když jsme nic nenačetli, vytvoříme jej jako prázdný
SeznamHracu = new List<Hrac>();
}
}
// Vypsání výsledků
public void VypisVysledky()
{
Seradit();
Retezec = "";
Pocitadlo = 0;
foreach (Hrac i in SeznamHracu)
{
Pocitadlo++;
Retezec += String.Format("{0}. {1} .... score: {2}, level: {3}, km: {4}\n", Pocitadlo, i.Jmeno, i.Skore, i.Uroven, i.Vzdalenost);
if (Pocitadlo > 25) { break; }
}
if (Pocitadlo > 0)
{
VratVypis = Retezec;
}
}
public void Seradit()
{
SeznamHracu = SeznamHracu.OrderBy(o => o.Skore).Reverse().ToList();
}
}
}
Neformátovaný
Přidáno: 4.8.2021
Expirace: Neuvedeno