public override void AddNumber(int score) { var path = $@"..\{Name}.txt"; using (StreamWriter sr = File.AppendText(path)) { sr.WriteLine(score); ScoreAdded?.Invoke(this, new EventArgs()); sr.Close(); } if (score == 0) { var zeroWarningPath = $@"C:\Users\T430\Desktop\Damian\Scores\{Name}.txt"; using (StreamWriter sr = File.AppendText(zeroWarningPath)) { sr.WriteLine($"score, added {DateTime.UtcNow}"); ZeroScoreWarning?.Invoke(this, new EventArgs()); sr.Close(); } } }
public override void AddNumber(int input) { if (input >= 0 && input <= 100) { _scores.Add(input); //jeżeli ScoreAdded jest nullem to znaczy, że nikt nie nasłuchuje tego eventu //this informuje, że to ta metoda wywołuje ten event ScoreAdded?.Invoke(this, new EventArgs()); } else { throw new ArgumentException($"Invalid argument {nameof(input)}"); } }
public void AddScore(object sender, PositionEventArgs e) { switch (e.Position) { case PlayerPosition._1: Score += 2; break; case PlayerPosition._2: Score += 3; break; default: throw new NotImplementedException(); } ScoreAdded?.Invoke(this, new EventArgs()); }
public void AddScore() { _score++; ScoreAdded?.Invoke(_score); }