-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ladder.cs
62 lines (57 loc) · 1.66 KB
/
Ladder.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Labyrinth
{
class Ladder
{
private const int TOP_RESULTS_CAPACITY = 5;
private List<Result> topResults;
public Ladder()
{
topResults = new List<Result>();
topResults.Capacity = TOP_RESULTS_CAPACITY;
}
public void PrintLadder()
{
if (topResults.Count == 0)
{
Console.WriteLine(UserInputAndOutput.SCOREBOARD_EMPTY_MSG);
}
else
{
for (int index = 0; index < topResults.Count; index++)
{
Console.WriteLine("{0}. {1} --> {2} moves", index + 1,
topResults[index].PlayerName, topResults[index].MovesCount);
}
}
}
public bool ResultQualifiesInLadder(int result)
{
if (topResults.Count < TOP_RESULTS_CAPACITY )
{
return true;
}
if (result < topResults.Max().MovesCount)
{
return true;
}
return false;
}
public void AddResultInLadder(int movesCount, string playerName)
{
Result result = new Result(movesCount, playerName);
if (topResults.Count == topResults.Capacity)
{
topResults[topResults.Count - 1] = result;
}
else
{
topResults.Add(result);
}
topResults.Sort();
}
}
}