//************************ Events reçus ************************************************/ public override void OnRefBoxMsgReceived(object sender, WorldMap.RefBoxMessageArgs e) { var command = e.refBoxMsg.command; var targetTeam = e.refBoxMsg.targetTeam; switch (command) { case RefBoxCommand.START: gameState = GameState.PLAYING; stoppedGameAction = StoppedGameAction.NONE; break; case RefBoxCommand.STOP: gameState = GameState.STOPPED; break; case RefBoxCommand.GOTO: if (e.refBoxMsg.robotID == robotId) { gameState = GameState.STOPPED_GAME_POSITIONING; externalRefBoxPosition = new Location(e.refBoxMsg.posX, e.refBoxMsg.posY, e.refBoxMsg.posTheta, 0, 0, 0); if (targetTeam == teamIpAddress) { stoppedGameAction = StoppedGameAction.GOTO; } else { stoppedGameAction = StoppedGameAction.GOTO_OPPONENT; } } else { } break; case RefBoxCommand.PLAYLEFT: //currentGameState = GameState.STOPPED_GAME_POSITIONING; if (targetTeam == teamIpAddress) { playingSide = PlayingSide.Left; } else { playingSide = PlayingSide.Right; } break; case RefBoxCommand.PLAYRIGHT: //currentGameState = GameState.STOPPED_GAME_POSITIONING; if (targetTeam == teamIpAddress) { playingSide = PlayingSide.Right; } else { playingSide = PlayingSide.Left; } break; } }
private void UpdatePlayingSide(int robotId, PlayingSide playSide) { if (TeamMatesDisplayDictionary.ContainsKey(robotId)) { TeamMatesDisplayDictionary[robotId].SetPlayingSide(playSide); } else { Console.WriteLine("UpdateRobotPlayingSide : Robot non trouvé"); } }
public override void OnRefBoxMsgReceived(object sender, WorldMap.RefBoxMessageArgs e) { var command = e.refBoxMsg.command; //var robotId = e.refBoxMsg.robotID; var targetTeam = e.refBoxMsg.targetTeam; switch (command) { case RefBoxCommand.START: gameState = GameState.PLAYING; stoppedGameAction = StoppedGameAction.NONE; break; case RefBoxCommand.STOP: gameState = GameState.STOPPED; break; case RefBoxCommand.DROP_BALL: gameState = GameState.STOPPED_GAME_POSITIONING; stoppedGameAction = StoppedGameAction.DROPBALL; break; case RefBoxCommand.HALF_TIME: break; case RefBoxCommand.END_GAME: break; case RefBoxCommand.GAME_OVER: break; case RefBoxCommand.PARK: gameState = GameState.STOPPED_GAME_POSITIONING; stoppedGameAction = StoppedGameAction.PARK; break; case RefBoxCommand.FIRST_HALF: break; case RefBoxCommand.SECOND_HALF: break; case RefBoxCommand.FIRST_HALF_OVER_TIME: break; case RefBoxCommand.RESET: break; case RefBoxCommand.WELCOME: break; case RefBoxCommand.KICKOFF: gameState = GameState.STOPPED_GAME_POSITIONING; if (targetTeam == teamIpAddress) { stoppedGameAction = StoppedGameAction.KICKOFF; } else { stoppedGameAction = StoppedGameAction.KICKOFF_OPPONENT; } break; case RefBoxCommand.FREEKICK: gameState = GameState.STOPPED_GAME_POSITIONING; if (targetTeam == teamIpAddress) { stoppedGameAction = StoppedGameAction.FREEKICK; } else { stoppedGameAction = StoppedGameAction.FREEKICK_OPPONENT; } break; case RefBoxCommand.GOALKICK: gameState = GameState.STOPPED_GAME_POSITIONING; if (targetTeam == teamIpAddress) { stoppedGameAction = StoppedGameAction.GOALKICK; } else { stoppedGameAction = StoppedGameAction.GOALKICK_OPPONENT; } break; case RefBoxCommand.THROWIN: gameState = GameState.STOPPED_GAME_POSITIONING; if (targetTeam == teamIpAddress) { stoppedGameAction = StoppedGameAction.THROWIN; } else { stoppedGameAction = StoppedGameAction.THROWIN_OPPONENT; } break; case RefBoxCommand.CORNER: gameState = GameState.STOPPED_GAME_POSITIONING; if (targetTeam == teamIpAddress) { stoppedGameAction = StoppedGameAction.CORNER; } else { stoppedGameAction = StoppedGameAction.CORNER_OPPONENT; } break; case RefBoxCommand.PENALTY: gameState = GameState.STOPPED_GAME_POSITIONING; if (targetTeam == teamIpAddress) { stoppedGameAction = StoppedGameAction.PENALTY; } else { stoppedGameAction = StoppedGameAction.PENALTY_OPPONENT; } break; case RefBoxCommand.GOAL: break; case RefBoxCommand.SUBGOAL: break; case RefBoxCommand.REPAIR: break; case RefBoxCommand.YELLOW_CARD: break; case RefBoxCommand.DOUBLE_YELLOW: break; case RefBoxCommand.RED_CARD: break; case RefBoxCommand.SUBSTITUTION: break; case RefBoxCommand.IS_ALIVE: gameState = GameState.STOPPED_GAME_POSITIONING; if (targetTeam == teamIpAddress) { stoppedGameAction = StoppedGameAction.KICKOFF; } else { stoppedGameAction = StoppedGameAction.KICKOFF_OPPONENT; } break; case RefBoxCommand.GOTO: if (e.refBoxMsg.robotID == robotId) { gameState = GameState.STOPPED_GAME_POSITIONING; externalRefBoxPosition = new Location(e.refBoxMsg.posX, e.refBoxMsg.posY, e.refBoxMsg.posTheta, 0, 0, 0); if (targetTeam == teamIpAddress) { stoppedGameAction = StoppedGameAction.GOTO; } else { stoppedGameAction = StoppedGameAction.GOTO_OPPONENT; } } else { } break; case RefBoxCommand.PLAYLEFT: //currentGameState = GameState.STOPPED_GAME_POSITIONING; if (targetTeam == teamIpAddress) { playingSide = PlayingSide.Left; } else { playingSide = PlayingSide.Right; } break; case RefBoxCommand.PLAYRIGHT: //currentGameState = GameState.STOPPED_GAME_POSITIONING; if (targetTeam == teamIpAddress) { playingSide = PlayingSide.Right; } else { playingSide = PlayingSide.Left; } break; } }
public void SetPlayingSide(PlayingSide playSide) { this.playingSide = playSide; }
public static void Main(string[] args) { bool playAgain = true; while (playAgain) { playAgain = false; Console.WriteLine("Shall we play some Tennis?"); Console.Write("How many sides: "); string numberOfPlayers = Console.ReadLine(); int number = 0; if (!Int32.TryParse(numberOfPlayers, out number)) { Console.WriteLine("Sorry, the number of sides could not be understood. Please try again"); return; } if (number <= 0) { Console.WriteLine("Sorry, the number of sides must be positive. Please try again"); return; } var matches = new List <IPlayMatch>(); var sides = new List <ISide>(); var random = new Random(); for (int i = 0; i < number; i++) { Console.Write("Team Name: "); string name = Console.ReadLine(); ISide newSide = new PlayingSide(); newSide.TeamName = name; newSide.Strength = random.Next(100); newSide.ServingStrength = random.Next(50); newSide.ReturningStrength = random.Next(25); sides.Add(newSide); Console.Write(" added with strength: {0}, serving: {1}, returning: {2}\n", newSide.Strength, newSide.ServingStrength, newSide.ReturningStrength); if (i == number - 1) { if (number % 2 == 1) { // let the last odd team play themselves ISide anotherSide = new PlayingSide(); anotherSide.TeamName = name; anotherSide.Strength = random.Next(100); anotherSide.ServingStrength = random.Next(50); anotherSide.ReturningStrength = random.Next(25); } } } Console.Write("To Start Tournament Press <Enter>"); Console.ReadLine(); for (int i = 0; i < sides.Count; i = i + 2) { matches.Add(new PlayMatch(new PlaySet(new PlayGame(new DetermineWinner(sides[i], sides[i + 1]))), sides[i], sides[i + 1])); } IPlayTournament playTournament = new PlayTournament(matches); ISide champion = playTournament.Play(); IEnumerable <MatchScore> matchScores = playTournament.GetMatchScores(); PrintMatchScores(matchScores); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("And the champion is....{0}, strength: {1}, serving: {2}, returning: {3}", champion.TeamName, champion.Strength, champion.ServingStrength, champion.ReturningStrength); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("----------------------------------------------------------------"); Console.Write("Play Again? (Y or N): "); string again = Console.ReadLine(); if (again == "Y" || again == "y") { playAgain = true; } } }
public static void Main(string[] args) { bool playAgain = true; while (playAgain) { playAgain = false; Console.WriteLine("Shall we play some Tennis?"); Console.Write("How many sides: "); string numberOfPlayers = Console.ReadLine(); int number = 0; if (!Int32.TryParse(numberOfPlayers, out number)) { Console.WriteLine("Sorry, the number of sides could not be understood. Please try again"); return; } if (number <= 0) { Console.WriteLine("Sorry, the number of sides must be positive. Please try again"); return; } var matches = new List<IPlayMatch>(); var sides = new List<ISide>(); var random = new Random(); for (int i = 0; i < number; i++) { Console.Write("Team Name: "); string name = Console.ReadLine(); ISide newSide = new PlayingSide(); newSide.TeamName = name; newSide.Strength = random.Next(100); newSide.ServingStrength = random.Next(50); newSide.ReturningStrength = random.Next(25); sides.Add(newSide); Console.Write(" added with strength: {0}, serving: {1}, returning: {2}\n", newSide.Strength, newSide.ServingStrength, newSide.ReturningStrength); if (i == number - 1) { if (number%2 == 1) { // let the last odd team play themselves ISide anotherSide = new PlayingSide(); anotherSide.TeamName = name; anotherSide.Strength = random.Next(100); anotherSide.ServingStrength = random.Next(50); anotherSide.ReturningStrength = random.Next(25); } } } Console.Write("To Start Tournament Press <Enter>"); Console.ReadLine(); for (int i = 0; i < sides.Count; i = i + 2) { matches.Add(new PlayMatch(new PlaySet(new PlayGame(new DetermineWinner(sides[i], sides[i + 1]))), sides[i], sides[i + 1])); } IPlayTournament playTournament = new PlayTournament(matches); ISide champion = playTournament.Play(); IEnumerable<MatchScore> matchScores = playTournament.GetMatchScores(); PrintMatchScores(matchScores); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("And the champion is....{0}, strength: {1}, serving: {2}, returning: {3}", champion.TeamName, champion.Strength, champion.ServingStrength, champion.ReturningStrength); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("----------------------------------------------------------------"); Console.Write("Play Again? (Y or N): "); string again = Console.ReadLine(); if (again == "Y" || again == "y") { playAgain = true; } } }