-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameAccount.cs
75 lines (67 loc) · 2.24 KB
/
GameAccount.cs
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
75
using System;
using System.Collections.Generic;
namespace Lr_2
{
public class GameAccount
{
private string username;
public int currentrating;
public int gamecount;
public List<GameStats> data = new List<GameStats>();
public string UserName
{
get { return username; }
set
{
if (value.Length < 1)
{
throw new ArgumentException("Your nickname must be longer");
}
username = value;
}
}
public GameAccount(string username)
{
UserName = username;
currentrating = 1;
gamecount = 0;
}
public virtual void WinGame(string opponentName, int rating, string gameName)
{
var res = new GameStats(opponentName, "Win", rating, gameName);
data.Add(res);
currentrating += rating;
gamecount++;
}
public void LoseGame(string opponentname, int rating, string gameName)
{
var res = new GameStats(opponentname, "Lose", rating, gameName);
data.Add(res);
if (currentrating - rating <= 1)
{
currentrating = 1;
}
else
{
currentrating -= rating;
}
gamecount++;
}
public string GetStatus()
{
var report = new System.Text.StringBuilder();
report.AppendLine($"Username: {UserName}");
report.AppendLine("Opponent\t\tGame type\tResult\tRating");
foreach (var item in data)
{
if(item.GameName == "Classic")
report.AppendLine($"{item.OpponentName}\t\t{item.GameName}\t\t\t{item.Result}\t{item.Rating}");
else
report.AppendLine($"{item.OpponentName}\t\t{item.GameName}\t\t{item.Result}\t{item.Rating}");
}
report.AppendLine("\nCurrent rating\tGames count");
report.AppendLine($"{currentrating}\t\t{gamecount}");
return report.ToString();
}
}
}