public Score AddRefereeScore() { while (true) { var value = Convert.ToSingle(Console.ReadLine()); try { if (value < 0 || value > 10 || (value * 10) % 5 != 0) { throw new Exception("Fel inmatning. Försök igen!"); } var score = new Score(value); return score; } catch (FormatException formatException) { Console.WriteLine(formatException.Message); } catch (Exception e) { Console.WriteLine(e.Message); } } }
public Assessment(int id, Score score, Dive dive, Referee referee) : base(id) { Point = score; DiveId = dive.Id; RefereeId = referee.Id; }
public Assessment() { Point = new Score(); DiveId = -1; RefereeId = -1; CompetitionId = -1; }
public void TestCalculateCompetitionPoints() { var diver = new Diver(3, "Johan", "Sweden", 23, "Man", 365); var dive1 = new Dive(1, 3.6f, 0, 1, diver.DiverId); var dive2 = new Dive(1, 6.2f, 0, 2, diver.DiverId); var dive3 = new Dive(1, 1.2f, 0, 3, diver.DiverId); var dive4 = new Dive(1, 3.0f, 0, 4, diver.DiverId); var dive5 = new Dive(1, 4.7f, 0, 5, diver.DiverId); diver.AddDive(dive1); diver.AddDive(dive2); diver.AddDive(dive3); diver.AddDive(dive4); diver.AddDive(dive5); Assert.AreEqual(5, diver.ListDive.Count); var score1 = new Score(5.5f); var score2 = new Score(2.5f); var score3 = new Score(8.0f); var score4 = new Score(5.0f); var score5 = new Score(2.5f); var allRefScores = new List<Score> { score1, score2, score3, score4, score5 }; diver.ListDive[0].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[0].Type.Difficulty); diver.ListDive[1].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[1].Type.Difficulty); diver.ListDive[2].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[2].Type.Difficulty); diver.ListDive[3].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[3].Type.Difficulty); diver.ListDive[4].TotalPoints.CalculateCompleteScore(allRefScores, diver.ListDive[4].Type.Difficulty); diver.SummarizeDivePoints(); //Assert.AreEqual(243.1, Math.Round(diver._competitionScore, 2)); }
public void AssessDive(Score score, Dive dive) { //Console.WriteLine($"Give points to dive {dive.DiveCode} by {dive.DiverId}"); //var score = AddRefereeScore(); var assessment = new Assessment(score, dive, this); var str = ClientNetworkHandler.SendAndReceive(assessment); //Console.WriteLine(str); }
public Diver(int id, string name, string country, int age, string gender, int diverId) : base(id, name, country) { Age = age; Gender = gender; DiverId = diverId; CompetitionScore = new Score(); }
public Dive(string diveCode, int diverid) { Order = -1; TotalPoints = new Score(); Name = ""; DiverId = diverid; Type.Code = diveCode; }
public Assessment(int id, float scoreValue, int diveId, int refereeId, int competitionId) : base(id) { Point = new Score(scoreValue); DiveId = diveId; RefereeId = refereeId; CompetitionId = competitionId; }
public Diver() { Age = -1; DiverId = -1; Rank = -1; Gender = ""; ListDive = new List<Dive>(); CompetitionScore = new Score(); }
public Dive(int id, float difficulty, float totalPoints, int order, int diverId) : base(id) { DiverId = diverId; Type.Difficulty = difficulty; TotalPoints = new Score(totalPoints); Order = order; //_name = Name; //Skall anropa en funktion som genererar namnet på hoppet från koden. }
public Dive(int id, DiveType diveType, float totalPoints, int order, int diverId) : base(id) { Assessments = new List<Assessment>(); DiverId = diverId; Type = diveType; TotalPoints = new Score(totalPoints); Order = order; //_name = Name; //Skall anropa en funktion som genererar namnet på hoppet från koden. }
public void TestFullCompetition() { var competitionObject = new Competition(1, "Örebro Mästerskapen", "20160217", "Örebro", "DM", 3); var diver = new Diver(4, "Klas", "Uganda", 59, "Man", 3); var diver2 = new Diver(5, "Susanna", "Sweden", 27, "Kvinna", 12); var diver3 = new Diver(2, "Klas-Göran", "Sweden", 22, "Man", 321); competitionObject.AddDiver(diver); competitionObject.AddDiver(diver2); competitionObject.AddDiver(diver3); Assert.AreEqual(3, competitionObject.ListDiver.Count); var dive1 = new Dive(1, 3.6f, 0, 1, diver.DiverId); var dive2 = new Dive(2, 6.2f, 0, 2, diver.DiverId); var dive3 = new Dive(3, 1.2f, 0, 3, diver.DiverId); diver.AddDive(dive1); diver.AddDive(dive2); diver.AddDive(dive3); var dive4 = new Dive(4, 2.6f, 0, 1, diver2.DiverId); var dive5 = new Dive(5, 3.7f, 0, 2, diver2.DiverId); var dive6 = new Dive(6, 9.2f, 0, 3, diver2.DiverId); diver2.AddDive(dive4); diver2.AddDive(dive5); diver2.AddDive(dive6); var dive7 = new Dive(7, 4.9f, 0, 1, diver3.DiverId); var dive8 = new Dive(8, 6.2f, 0, 2, diver3.DiverId); var dive9 = new Dive(9, 1.2f, 0, 3, diver3.DiverId); diver3.AddDive(dive7); diver3.AddDive(dive8); diver3.AddDive(dive9); if (competitionObject.CheckIfSameAmountOfDives()) { var allRefScores = new List<Score>(); var score1 = new Score(5.5f); var score2 = new Score(2.5f); var score3 = new Score(8.0f); var score4 = new Score(5.0f); var score5 = new Score(2.5f); allRefScores.Add(score1); allRefScores.Add(score2); allRefScores.Add(score3); allRefScores.Add(score4); allRefScores.Add(score5); for (var i = 0; i < competitionObject.Rounds; i++) { foreach (var contestant in competitionObject.ListDiver) { contestant.ListDive[i].TotalPoints.CalculateCompleteScore(allRefScores, contestant.ListDive[i].Type.Difficulty); } } foreach (var contestant in competitionObject.ListDiver) { contestant.SummarizeDivePoints(); } Assert.AreEqual("Susanna", competitionObject.GetWinner()); } }
/// <summary> /// Summera alla poäng från alla hopp /// </summary> public Score SummarizeDivePoints() { var points = new Score(0); foreach (var dive in ListDive) { if (dive.TotalPoints.Value != -1) points.Value += dive.TotalPoints.Value; } return points; }
public Dive() { TotalPoints = new Score(); Order = -1; Name = ""; }
public Assessment(Score score, Dive dive, Referee referee) { this.Point = score; this.DiveId = dive.Id; this.RefereeId = referee.Id; }
private void OnEventClickSendButton(object sender, EventArgs e) { try { if (RefereeAssessment.refScoreTextBox.Text.Length == 0) throw new FormatException(); var dialogResult = MessageBox.Show( $"Skicka {RefereeAssessment.refScoreTextBox.Text} poäng?", "Skicka poäng", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { var refScore = RefereeAssessment.refScoreTextBox.Text; var judgeScore = float.Parse(refScore, CultureInfo.InvariantCulture.NumberFormat); var score = new Score(judgeScore); var dive = new Dive(); var assessment = new Assessment(score, dive, LoggedInUser); var str = ClientNetworkHandler.SendAndReceive(assessment); MessageBox.Show($"{judgeScore} poäng skickad", "Meddelande"); } } catch (FormatException) { ErrorMessageBox("Ogiltig inmatning", "Ange poäng!"); } RefereeAssessment.RefSendScoreButton.Enabled = false; var tDive = WaitForDiveToJudge(); RefereeAssessment.RefereeCurrentDiveInfoLabel.Text = tDive.ToString(); SystemSounds.Beep.Play(); RefereeAssessment.RefSendScoreButton.Enabled = true; }