public ShotResult TakeShot(Player playerTakingShot, GeoCoordinate shotLocation) { if (playerTakingShot != NextPlayerToTakeShot) { return ShotResult.IllegalPlayer; } if (LastShotWasHit()) { return ShotResult.GameAlreadyOver; } var targetPlayer = NextPlayerToTakeShot == Player1 ? Player2 : Player1; if (targetPlayer.Location == null) { return ShotResult.TargetHasNoLocation; } if (ShotOutsideTargetZone(targetPlayer, shotLocation)) { return ShotResult.OutsideTargetZone; } //Take shot var shot = ShotOnTarget(targetPlayer, shotLocation) ? new Shot(playerTakingShot, shotLocation, ShotResult.Hit) : new Shot(playerTakingShot, shotLocation, ShotResult.Miss); //Push to stack shots.Push(shot); NextPlayerToTakeShot = targetPlayer; return shot.ShotResult; }
private Game FindGameAndPlayer(Guid gameId, string playerEmail, out Player player) { Game game = FindGame(gameId); player = FindPlayerByEmail(game, playerEmail); return game; }
public Guid CreateGame(string gameName, string initiatingPlayerName, string initiatingPlayerEmail, string acceptingPlayerName, string acceptingPlayerEmail) { var initiatingPlayer = new Player(initiatingPlayerEmail, initiatingPlayerName); var acceptingPlayer = new Player(acceptingPlayerEmail, acceptingPlayerName); var game = new Game(gameName, initiatingPlayer, acceptingPlayer, PlayerTargetZoneRadius, ShotBlastRadius); games.Add(game.Id, game); return game.Id; }
public Game(string name, Player initiatingPlayer, Player acceptingPlayer, double playerTargetZoneRadius, double shotBlastRadius) { Id = Guid.NewGuid(); Name = name; Player1 = initiatingPlayer; Player2 = acceptingPlayer; NextPlayerToTakeShot = acceptingPlayer; this.playerTargetZoneRadius = playerTargetZoneRadius; this.shotBlastRadius = shotBlastRadius; }
public static void Main() { var p1 = new Player("*****@*****.**", "A"); var p2 = new Player("*****@*****.**", "B"); const double playerTargetZoneRadius = 2.0; const double shotBlastRadius = 1.0; var game = new Game("Test", p1, p2, playerTargetZoneRadius, shotBlastRadius); p1.UpdateLocation(new GeoCoordinate(0.0, 0.0), playerTargetZoneRadius); p2.UpdateLocation(new GeoCoordinate(5.0, 5.0), playerTargetZoneRadius); var result = game.TakeShot(p2, p1.Location); Console.WriteLine(result); result = game.TakeShot(p2, p1.Location); Console.WriteLine(result); result = game.TakeShot(p1, p1.Location); Console.WriteLine(result); Console.ReadKey(); }
private bool ShotOutsideTargetZone(Player targetPlayer, GeoCoordinate shotLocation) { return GetGeoDistanceBetween(shotLocation, targetPlayer.Location) > playerTargetZoneRadius; }
private bool ShotOnTarget(Player targetPlayer, GeoCoordinate shotLocation) { return GetGeoDistanceBetween(shotLocation, targetPlayer.Location) < shotBlastRadius; }
private Game CreateGame(out Player player1, out Player player2) { player1 = new Player("*****@*****.**", "A"); player2 = new Player("*****@*****.**", "B"); var game = new Game("Test", player1, player2, playerTargetZoneRadius, shotBlastRadius); return game; }
private static GeoCoordinate GetOffTargetShot(Player targetPlayer, double offset = 0.1) { return new GeoCoordinate(targetPlayer.Location.Latitude + shotBlastRadius + offset, targetPlayer.Location.Longitude + shotBlastRadius + offset); }
public Shot(Player playerTakingShot, GeoCoordinate location, ShotResult shotResult) { PlayerTakingShot = playerTakingShot; Location = location; ShotResult = shotResult; }