Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        private Game FindGameAndPlayer(Guid gameId, string playerEmail, out Player player)
        {
            Game game = FindGame(gameId);
            player = FindPlayerByEmail(game, playerEmail);

            return game;
        }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
        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;
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
 private bool ShotOutsideTargetZone(Player targetPlayer, GeoCoordinate shotLocation)
 {
     return GetGeoDistanceBetween(shotLocation, targetPlayer.Location) > playerTargetZoneRadius;
 }
Esempio n. 7
0
 private bool ShotOnTarget(Player targetPlayer, GeoCoordinate shotLocation)
 {
     return GetGeoDistanceBetween(shotLocation, targetPlayer.Location) < shotBlastRadius;
 }
Esempio n. 8
0
        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;
        }
Esempio n. 9
0
 private static GeoCoordinate GetOffTargetShot(Player targetPlayer, double offset = 0.1)
 {
     return new GeoCoordinate(targetPlayer.Location.Latitude + shotBlastRadius + offset, targetPlayer.Location.Longitude + shotBlastRadius + offset);
 }
Esempio n. 10
0
 public Shot(Player playerTakingShot, GeoCoordinate location, ShotResult shotResult)
 {
     PlayerTakingShot = playerTakingShot;
     Location = location;
     ShotResult = shotResult;
 }