-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRatingSystem.cs
More file actions
74 lines (66 loc) · 2.02 KB
/
RatingSystem.cs
File metadata and controls
74 lines (66 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WpfTournament
{
public delegate int SortByRatingDel(string Raiting1, string Raiting2);
class Game
{
public string Name;
public List<Player> PlayersOfGame;
private SortByRatingDel RatingCompareFunction;
public Game(string Name,SortByRatingDel RatingCompareFunction)
{
this.RatingCompareFunction = RatingCompareFunction;
this.Name = Name;
PlayersOfGame = new List<Player>();
}
public void SortByName()
{
PlayersOfGame.Sort(
delegate(Player p1, Player p2)
{
return String.Compare(p1.Surname, p2.Surname);
}
);
}
public void SortByAge()
{
PlayersOfGame.Sort(delegate(Player p1, Player p2)
{
if (p1.Age > p2.Age)
return 1;
else if (p1.Age < p2.Age)
return -1;
else
return 0;
});
}
public void SortByLevel()
{
PlayersOfGame.Sort(delegate(Player p1, Player p2) { return this.RatingCompareFunction(p1.Rating, p2.Rating); });
}
public void UpdateByAnotherList(List<Player> ListToAdd)
{
bool WasFound;
for (int i = 0; i < ListToAdd.Count; i++)
{
WasFound = false;
for (int j = 0; j < PlayersOfGame.Count; j++)
{
if (PlayersOfGame[i].ID == ListToAdd[i].ID)
{
PlayersOfGame[i] = ListToAdd[j].Clone();
WasFound = true;
break;
}
}
if (!WasFound)
{
PlayersOfGame.Add(ListToAdd[i]);
}
}
}
}
}