This repository has been archived by the owner on Dec 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cs
80 lines (73 loc) · 2.98 KB
/
Player.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
76
77
78
79
80
using System;
using static System.Console;
namespace Labyrinth
{
/// <summary>The player class</summary>
public class Player
{
#region Attributes
/// <summary>The name of the player.</summary>
public string Name {get; set;}
/// <summary>The scores of the player in the different labyrinths.</summary>
public List <TimeSpan> Scores {get; set;}
/// <summary>The current session the player is in.</summary>
public static string? s_SessionName {get; private set;}
#endregion
#region Constructor
/// <summary>This method is used to initialize a new instance of the <see cref="T:Labyrinth.Player"/> class.</summary>
/// <param name="name">The name of the player is optional. You can either set it from the instance, or define it later on.</param>
public Player(string name = "")
{
Name = name;
Scores = new List<TimeSpan>(){TimeSpan.Zero,TimeSpan.Zero,TimeSpan.Zero,TimeSpan.Zero};
}
#endregion
#region Properties
/// <summary>This property is used to get the name of the player whithout the visual spaces.</summary>
public static string CutName
{
set
{
s_SessionName = value;
while(s_SessionName[s_SessionName.Length-1] == ' ')s_SessionName = s_SessionName.Substring(0,s_SessionName.Length-1);
}
}
#endregion
#region Utility Methods
/// <summary>This method is used to display the scores of the player.</summary>
public override string ToString()
{
string text = Name;
for (int i = 0; i < Scores.Count; i++)
{
text += ";" + Scores[i] ;
}
return text;
}
/// <summary>This method is used to check in the list of player if the player is already in it.</summary>
/// <returns>Wether the player is in the list or not.</returns>
public bool IsNewPlayer()
{
string[] documentLines = File.ReadAllLines(Ranking.s_StoredPath);
for (int i = 0; i < documentLines.Length; i++)
{
string[] playerData = documentLines[i].Split(';');
if (playerData[0] == Name)return false;
}
return true;
}
/// <summary>This method is used to get the index of the player in the list.</summary>
/// <returns>The index of the player in the list.</returns>
public int IndexOfPlayer()
{
string[] documentLines = File.ReadAllLines(Ranking.s_StoredPath);
for (int i = 0; i < documentLines.Length; i++)
{
string[] playerData = documentLines[i].Split(';');
if (playerData[0] == Name)return i;
}
return -1;
}
#endregion
}
}