mirror of
https://github.com/bvanroll/cs-oo-project.git
synced 2025-08-29 20:12:40 +00:00
Events added for ploegen.cs (reset json files for next boot)
This commit is contained in:
@@ -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)
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user