//this method is required for saving results in files public void SetResult(int[] scoreA, int[] scoreB) { scoreTeamA = scoreA; scoreTeamB = scoreB; int resultCheck = 0, scoreDiff = 0; for (int i = 0; i < 3; i++) { if (scoreA[i] > scoreB[i]) { resultCheck++; } else if (scoreTeamA[i] < scoreTeamB[i]) { resultCheck--; } scoreDiff = scoreTeamA[i] - scoreTeamB[i]; } if (Winner == TeamA) { TeamA.SetMatchResult(true, false, false, (1 + Math.Abs(resultCheck)).ToString() + ", " + (scoreDiff).ToString()); TeamB.SetMatchResult(false, false, false, (2 - Math.Abs(resultCheck)).ToString() + ", " + (-scoreDiff).ToString()); } if (Winner == TeamB) { TeamA.SetMatchResult(false, false, false, (2 - Math.Abs(resultCheck)).ToString() + ", " + (-scoreDiff).ToString()); TeamB.SetMatchResult(true, false, false, (1 + Math.Abs(resultCheck)).ToString() + ", " + (scoreDiff).ToString()); } }
/// <summary> /// Method to enter the scores of the Game (once the game is finished). /// It automatically calculates the Winner (or Draw) and adds points to the winning team. /// If the scores were already entered, it updates the scores, the winner and recalculates the points given to each team (cancels the previouses and adds the new ones) /// </summary> /// <remarks> /// 3 points for a victory /// 1 point for a draw /// 0 point for a defeat /// + score*0.001 for each team /// </remarks> /// <param name="scoreA"></param> /// <param name="scoreB"></param> public void EnterScore(int scoreA, int scoreB) { //If the scores have already been entered, we delete them to enter new scores if (Winner != null) { CancelPreviousEnterScore(); } this.ScoreA = scoreA; this.ScoreB = scoreB; TeamA.ScoresSum += ScoreA; TeamB.ScoresSum += ScoreB; if (ScoreA - ScoreB > 0) //TeamA wins { Winner = Convert.ToString(TeamA.Id); TeamA.PointsOfVictoriesAndDraws += 3; } else if (ScoreA - ScoreB == 0) //Draw { Winner = "Match nul"; TeamA.PointsOfVictoriesAndDraws += 1; TeamB.PointsOfVictoriesAndDraws += 1; } else //TeamB wins { Winner = Convert.ToString(TeamB.Id); TeamB.PointsOfVictoriesAndDraws += 3; } TeamA.ComputeTotalScore(); TeamB.ComputeTotalScore(); }
//This is based on the assumption that stat is going to be in seconds (possibly with miliseconds) public override void SetResult(string stat, TTeam.ITeam winner) { float tmp = matchLength; //a safety check just in case stat is not a number try { matchLength = float.Parse(stat); if (matchLength < 0) { matchLength = 0; throw new NegativeMatchLengthException(CreateCopy()); } } //float.parse throws FormatException if stat can't be converted catch (FormatException) { throw new NotNumberMatchLengthException(CreateCopy()); } winner.SetMatchResult(true, tmp != 0, tmp != 0 && this.Winner == winner, stat + " - " + tmp.ToString()); if (winner == TeamA) { TeamB.SetMatchResult(false, tmp != 0, tmp != 0 && this.Winner == TeamB, stat + " - " + tmp.ToString()); } else { TeamA.SetMatchResult(false, tmp != 0, tmp != 0 && this.Winner == TeamA, stat + " - " + tmp.ToString()); } base.SetResult(stat, winner); }
private void HitStepByStep() { if (IsTeamATurn) { var player = TeamA.GetRandomAliveUnit(); if (!player.IsStunned) { DisplayFightDialog(); if (IsExitDone) { return; } Console.WriteLine($"Your opponent is {ChosenOpponent}"); } player.Attack(TeamB.AliveUnits[ChosenOpponent]); } else { TeamB.GetRandomAliveUnit().Attack(TeamA.GetRandomAliveUnit()); } IsTeamATurn = !IsTeamATurn; Console.WriteLine(); IsAnyChange = true; }
public Result ReschuduleMachDate(DateTime newMatchDate) { Guard.Against.Null(newMatchDate, nameof(newMatchDate)); Guard.Against.Default(newMatchDate, nameof(newMatchDate)); Guard.Against.DateBeforeNow(newMatchDate, nameof(newMatchDate)); if (MatchDate == newMatchDate) { return(Result.Success()); } var canReschuduleResult = TeamA.CanReschuduleMatchDate(this, newMatchDate); if (canReschuduleResult.IsFailure) { Result.Failure(canReschuduleResult.Error); } canReschuduleResult = TeamB.CanReschuduleMatchDate(this, newMatchDate); if (canReschuduleResult.IsFailure) { Result.Failure(canReschuduleResult.Error); } MatchDate = newMatchDate; return(Result.Success()); }
public void SetResult(float matchLength) { this.matchLength = matchLength; if (Winner != null) { TeamA.SetMatchResult(TeamA == Winner, false, false, matchLength + " - " + 0.ToString()); TeamB.SetMatchResult(TeamB == Winner, false, false, matchLength + " - " + 0.ToString()); } }
public TwentyNineLobby(string LobbyId, Player lobbyMaker, int winningScore = 3) : base(LobbyId, lobbyMaker) { /* Game Policies * Winning score will be set by lobby maker only * LobbyMaker will be default host */ WinningScore = winningScore; TeamA.Add(lobbyMaker); }
//NotifyCollectionChangedEventHandler UpdateStatsHandler; private void CrudeTeamSettings() //TODO: change to sth meaningfull { TeamA = Players.Take(4).ToList(); TeamB = Players.TakeLast(4).ToList(); TeamAOnCourt = new ObservableCollection <Player>(TeamA.Take(3).ToList()); TeamBOnCourt = new ObservableCollection <Player>(TeamB.Take(3).ToList()); TeamABench = new ObservableCollection <Player>(TeamA.TakeLast(1).ToList()); TeamBBench = new ObservableCollection <Player>(TeamB.TakeLast(1).ToList()); }
static void Main(string[] args) { Team teamA = new TeamA("A"); teamA.Players = new List <Player>() { new Player() { Team = teamA, Name = "playerA" } }; Team teamB = new TeamB("B"); teamA.Players = new List <Player>() { new Player() { Team = teamB, Name = "playerB" } }; Match m = new Match(WinningSet.BEST_OF_FIVE) { MatchName = "Tournament ABC", TeamA = teamA, TeamB = teamB }; System.Console.WriteLine("match has started, enter team name (A or B):"); while (true) { string team = System.Console.ReadLine(); if (team != "a" && team != "b" && team != "A" && team != "B") { System.Console.WriteLine("Equipe invalide, doit-être A ou B"); } else { m.TeamScores(team.ToUpper()); System.Console.Write("score in game is " + m.CurrentSet.CurrentGame.ScoreGame.GameScore); if (m.CurrentSet.TieBreak != null) { System.Console.WriteLine("[" + m.CurrentSet.TieBreak.ScoreTieBreak.TieScore + "]"); } else { System.Console.WriteLine(""); } System.Console.WriteLine("score games in set is " + m.CurrentSet.ScoreSet.SetScore); System.Console.WriteLine("Sets are " + m.ScoreMatch.MatchScore); } } }
private void DisplayWinner() { if (TeamA.IsAllUnitsAlive) { TeamA.PrintAliveUnits(); } else if (TeamB.IsAllUnitsAlive) { TeamB.PrintAliveUnits(); } }
private void ValidateTeamA() { if (TeamA.IsValid()) { return; } foreach (var error in TeamA.ValidationResult.Errors) { ValidationResult.Errors.Add(error); } }
public void PlayTurn() { foreach (var character in TeamA) { var enemy = TeamB.ElementAt(TeamA.IndexOf(character)); character.Attack(enemy); enemy.Attack(character); if (enemy is Healer) { var healer = enemy as Healer; healer.OnCastSpell(); } } }
public void DisplayScore() { var winner = TeamA.TrueForAll(c => !c.IsAlive()) ? TeamA : TeamB; var builder = new StringBuilder(); foreach (var character in winner) { builder.Append(character.Name); builder.Append(", "); } Console.WriteLine("L'équipe avec {0}a gagné !", builder); }
private void SpawnPawns() { for (int i = 0; i < BoardManager.BOARD_COLS; i++) { Pawn newPawnA = Instantiate(pawnPrefabA, pawnParent).GetComponent <Pawn>(); Pawn newPawnB = Instantiate(pawnPrefabB, pawnParent).GetComponent <Pawn>(); newPawnA.Init(GameManager.Board.GetTile(0, i), Teams.TeamA); newPawnB.Init(GameManager.Board.GetTile(BoardManager.BOARD_ROWS - 1, i), Teams.TeamB); TeamA.Add(newPawnA); TeamB.Add(newPawnB); } }
public void SetResult(int wPlayersLeft) { winnerPlayersLeft = wPlayersLeft; if (Winner == TeamA) { TeamA.SetMatchResult(TeamA == Winner, false, false, winnerPlayersLeft + ", " + 6); TeamB.SetMatchResult(TeamB == Winner, false, false, 0 + ", " + (6 - winnerPlayersLeft)); } if (Winner == TeamB) { TeamB.SetMatchResult(TeamB == Winner, false, false, winnerPlayersLeft + ", " + 6); TeamA.SetMatchResult(TeamA == Winner, false, false, 0 + ", " + (6 - winnerPlayersLeft)); } }
private void HitStepByStep() { if (IsTeamBTurn) { TeamB.GetRandomAliveUnit().Attack(TeamA); } else { TeamA.GetRandomAliveUnit().Attack(TeamB); } IsTeamBTurn = !IsTeamBTurn; TeamA.ActEachTurn(); TeamB.ActEachTurn(); Console.WriteLine(); }
public override void SetResult(string stat, TTeam.ITeam winner) { int playersEliminatedChange = 0, playersLeftChange = 0; if (this.Winner == winner) { playersLeftChange = winnerPlayersLeft; } else { if (this.Winner != null) { playersEliminatedChange = 6 - winnerPlayersLeft; } } //if stat is not a number parse will throw format exception try { winnerPlayersLeft = int.Parse(stat); if (winnerPlayersLeft <= 0) { winnerPlayersLeft = 0; throw new NegativePlayersNumberException(CreateCopy()); } if (winnerPlayersLeft > 6) { winnerPlayersLeft = 0; throw new TooHighPlayersLeftException(CreateCopy()); } } catch (FormatException) { throw new NotIntPlayersException(CreateCopy()); } winner.SetMatchResult(true, playersEliminatedChange != 0 || playersLeftChange != 0, (playersEliminatedChange != 0 || playersLeftChange != 0) && this.Winner == winner, (winnerPlayersLeft - playersLeftChange).ToString() + ", " + playersEliminatedChange.ToString()); if (winner == TeamA) { TeamB.SetMatchResult(false, playersEliminatedChange != 0 || playersLeftChange != 0, (playersEliminatedChange != 0 || playersLeftChange != 0) && this.Winner == TeamB, (-playersLeftChange).ToString() + ", " + (6 - winnerPlayersLeft - playersEliminatedChange).ToString()); } else { TeamA.SetMatchResult(false, playersEliminatedChange != 0 || playersLeftChange != 0, (playersEliminatedChange != 0 || playersLeftChange != 0) && this.Winner == TeamA, (-playersLeftChange).ToString() + ", " + (6 - winnerPlayersLeft - playersEliminatedChange).ToString()); } base.SetResult(stat, winner); }
internal void DisplayScore() { TeamA.PrintAliveUnits(); Console.WriteLine(); TeamB.PrintAliveUnits(); }
public void ResetGame() { HasGameStarted = false; TeamA.SelectNextCoder(); TeamB.SelectNextCoder(); }
public bool HasEnded() { return(TeamA.TrueForAll(c => !c.IsAlive()) || TeamB.TrueForAll(c => !c.IsAlive())); }
//the expected format is "team1.Name: scoreInSet1, scoreInSet2, scoreInSet3(0 if not played). team2.Name: scoreInSet1, scoreInSet2, scoreInSet3(0 if not played)" public override void SetResult(string stat, TTeam.ITeam winner) { int resultCheck = 0, scoreDiff = 0; int earlierScoreDiff = 0, earlierPoints = 0; if (WasPlayed()) { for (int i = 0; i < 3; i++) { earlierScoreDiff += scoreTeamA[i] - scoreTeamB[i]; if (scoreTeamA[i] > scoreTeamB[i]) { earlierPoints++; } if (scoreTeamA[i] < scoreTeamB[i]) { earlierPoints--; } } if (earlierPoints > 0) { earlierPoints++; } else { earlierPoints += 2; } } //split the strings into strings containing name of the teams and their scores string[] tmp = stat.Split(new string[] { ". ", ", ", ": " }, StringSplitOptions.RemoveEmptyEntries); //string should split into 8 smaller string (2 for names of teams, 6 in total for scores in sets) if (tmp.Length != 8) { throw new WrongStatFormatException(CreateCopy()); } for (int i = 0; i < 3; i++) { int scoreRequired; if (i != 2) { scoreRequired = 21; } else { scoreRequired = 15; } try { if (tmp[0].Equals(TeamA.Name) && tmp[4].Equals(TeamB.Name)) { scoreTeamA[i] = int.Parse(tmp[i + 1]); scoreTeamB[i] = int.Parse(tmp[i + 5]); } else { if (tmp[0].Equals(TeamB.Name) && tmp[4].Equals(TeamA.Name)) { scoreTeamB[i] = int.Parse(tmp[i + 1]); scoreTeamA[i] = int.Parse(tmp[i + 5]); } else { if (TeamA.Name.Equals(tmp[0]) || TeamB.Name.Equals(tmp[0])) { Console.WriteLine(TeamA.Name + " " + TeamB.Name); throw new WrongNameInStatException(CreateCopy(), tmp[4]); } else { ToString(); throw new WrongNameInStatException(CreateCopy(), tmp[0]); } } } //score should be equal or higher than 0, but equal or lower than 21 in first two sets //and equal or lower than 15 in the third set if (scoreTeamA[i] < 0 || scoreTeamB[i] < 0) { for (int j = 0; j < 3; j++) { scoreTeamA[j] = 0; scoreTeamB[j] = 0; } throw new NegativeScoreException(CreateCopy()); } if (scoreTeamA[i] > scoreRequired || scoreTeamB[i] > scoreRequired) { for (int j = 0; j < 3; j++) { scoreTeamA[j] = 0; scoreTeamB[j] = 0; } throw new TooHighScoreException(CreateCopy()); } } catch (FormatException) { throw new NonIntScoreException(CreateCopy()); } //Checking whether the score makes sense and reflects the winner //if a team has won in 2 sets third one should end 0:0 if (Math.Abs(resultCheck) == 2) { if (scoreTeamA[i] != 0 || scoreTeamB[i] != 0) { if (resultCheck > 0) { for (int j = 0; j < 3; j++) { scoreTeamA[j] = 0; scoreTeamB[j] = 0; } throw new ThirdSetException(CreateCopy(), TeamA); } else { for (int j = 0; j < 3; j++) { scoreTeamA[j] = 0; scoreTeamB[j] = 0; } throw new ThirdSetException(CreateCopy(), TeamB); } } } //Checking if exactly one team has reached the required points else { if (scoreTeamA[i] == scoreTeamB[i] || (scoreTeamA[i] < scoreRequired && scoreTeamB[i] < scoreRequired)) { throw new NoSetWinnerException(CreateCopy(), i + 1); } if (scoreTeamA[i] == scoreRequired) { resultCheck++; } if (scoreTeamB[i] == scoreRequired) { resultCheck--; } scoreDiff += scoreTeamA[i] - scoreTeamB[i]; } } //checking if a team which should have won by what the stat indicates was set as a winner if ((resultCheck > 0 && TeamA != winner) || (resultCheck < 0 && TeamB != winner)) { for (int j = 0; j < 3; j++) { scoreTeamA[j] = 0; scoreTeamB[j] = 0; } throw new WrongWinnerException(CreateCopy(), winner); } int temp = 0; if (WasPlayed()) { temp = 3 - earlierPoints; } if (winner == TeamA) { TeamA.SetMatchResult(true, earlierScoreDiff != 0, earlierScoreDiff != 0 && this.Winner == TeamA, (1 + Math.Abs(resultCheck) - earlierPoints).ToString() + ", " + (scoreDiff - earlierScoreDiff).ToString()); TeamB.SetMatchResult(false, earlierScoreDiff != 0, earlierScoreDiff != 0 && this.Winner == TeamB, (2 - Math.Abs(resultCheck) - temp).ToString() + ", " + (earlierScoreDiff - scoreDiff).ToString()); } else { TeamA.SetMatchResult(false, earlierScoreDiff != 0, earlierScoreDiff != 0 && this.Winner == TeamA, (2 - Math.Abs(resultCheck) - temp).ToString() + ", " + (earlierScoreDiff - scoreDiff).ToString()); TeamB.SetMatchResult(true, earlierScoreDiff != 0, earlierScoreDiff != 0 && this.Winner == TeamB, (1 + Math.Abs(resultCheck) - earlierPoints).ToString() + ", " + (scoreDiff - earlierScoreDiff).ToString()); } base.SetResult(stat, winner); }