Events added for ploegen.cs (reset json files for next boot)

This commit is contained in:
Beppe
2019-08-03 21:29:23 +02:00
parent b3a4a7441a
commit 1fb0e5801b
5 changed files with 68 additions and 16 deletions

View File

@@ -11,38 +11,62 @@ namespace Globals.classes
[JsonConstructor]
public Game(int Id, Ploeg home, Ploeg away, DateTime date)
{
homeSetBool = false;
awaySetBool = false;
this.Id = Id;
this.home = home;
this.away = away;
this.home.scoreChanged += homeSet;
this.away.scoreChanged += awaySet;
this.date = date;
}
public Game(Ploeg home, Ploeg away, DateTime d)
{
homeSetBool = false;
awaySetBool = false;
this.home = home;
this.away = away;
this.home.scoreChanged += homeSet;
this.away.scoreChanged += awaySet;
this.date = d;
}
public Game(Ploeg home, Ploeg away, DateTime d, int scoreHome, int scoreAway)
{
homeSetBool = false;
awaySetBool = false;
this.home = home;
this.away = away;
this.home.score = scoreHome;
this.away.score = scoreAway;
this.home.scoreChanged += homeSet;
this.away.scoreChanged += awaySet;
this.home.setScore(scoreHome);
this.away.setScore(scoreAway);
this.date = d;
}
public Game(int id, Ploeg home, Ploeg away)
{
homeSetBool = false;
awaySetBool = false;
Id = id;
this.home = home ?? throw new ArgumentNullException(nameof(home));
this.away = away ?? throw new ArgumentNullException(nameof(away));
this.home.scoreChanged += homeSet;
this.away.scoreChanged += awaySet;
}
public Game(int id, Ploeg home, Ploeg away, int scoreHome, int scoreAway)
{
homeSetBool = false;
awaySetBool = false;
Id = id;
this.home = home ?? throw new ArgumentNullException(nameof(home));
this.away = away ?? throw new ArgumentNullException(nameof(away));
this.home.score = scoreHome;
this.away.score = scoreAway;
this.home.scoreChanged += homeSet;
this.away.scoreChanged += awaySet;
this.home.setScore(scoreHome);
this.away.setScore(scoreAway);
}
[JsonProperty("id")]
public int Id { get; set; }
@@ -53,6 +77,18 @@ namespace Globals.classes
[JsonProperty("Date")]
public DateTime date { get; set; } //y m d
private bool homeSetBool;
private bool awaySetBool;
private void homeSet (object s, EventArgs e)
{
homeSetBool = true;
}
private void awaySet(object s, EventArgs e)
{
awaySetBool = true;
}
public state getWinner()
{
if (!this.home.scoreSet || !this.away.scoreSet)

View File

@@ -34,9 +34,11 @@ namespace Globals.classes
public int Id { get; set; }
public string naam { get; set; }
public int score { get; set; }
public bool scoreSet { get => this.score != int.MinValue; }
public int score { get; private set; }
public bool scoreSet { get; }
public event EventHandler scoreChanged;
public override bool Equals(object obj)
{
try
@@ -66,5 +68,15 @@ namespace Globals.classes
return this.Id + ": " + this.naam + score;
}
public void setScore(int i)
{
EventHandler h = scoreChanged;
if (null != h) h(this, EventArgs.Empty);
this.score = i;
}
public int getScore()
{
return this.score;
}
}
}

View File

@@ -11,5 +11,6 @@ namespace Globals.Interfaces
Ploeg away { get; set; }
DateTime date { get; set; }
state getWinner();
}
}

View File

@@ -5,7 +5,10 @@ namespace Globals.Interfaces
{
int Id { get; set; }
string naam { get; set; }
int score { get; set; }
int score { get; }
bool scoreSet { get; }
event EventHandler scoreChanged;
void setScore(int i);
int getScore();
}
}