private static void BuildAtX(Match game, Player player, int x)
        {
            var ship = player.Ship;
            var deltaY = player.PlayerNumber == 1 ? -1 : 1;
            List<Alien> explosions = new List<Alien>();

            for (var shieldX = x; shieldX < x + ship.Width; shieldX++)
            {
                var shieldY = ship.Y + deltaY;
                for (var counter = 0; counter < 3; counter++)
                {
                    var entity = game.Map.GetEntity(shieldX, shieldY);
                    if (entity == null)
                    {
                        game.Map.AddEntity(new Shield(player.PlayerNumber) {X = shieldX, Y = shieldY});
                    }
                    else if (entity.Type == EntityType.Alien)
                    {
                        explosions.Add((Alien) entity);
                    }
                    else if ((entity.Type == EntityType.Bullet) ||
                             (entity.Type == EntityType.Missile))
                    {
                        entity.Destroy();
                    }

                    shieldY += deltaY;
                }
            }

            foreach (var alien in explosions)
            {
                Alien.Explode(alien.X, alien.Y);
            }
        }
 protected static void AssertBuildingAdded(Match game)
 {
     var ship = game.GetPlayer(1).Ship;
     Assert.IsNotNull(game.Map.GetEntity(ship.X, ship.Y + 1), "Building was not added.");
     Assert.IsNotNull(game.Map.GetEntity(ship.X + 1, ship.Y + 1), "Building was not added.");
     Assert.IsNotNull(game.Map.GetEntity(ship.X + 2, ship.Y + 1), "Building was not added.");
 }
        public void AddPlayerDetailsToLines(Player player, Match match, List<string> lines)
        {
            var width = match.Map.Width;

            AddLineToLines(String.Format("# Round: {0,3} ", match.RoundNumber), lines, width);
            AddLineToLines(String.Format("# Kills: {0,3} ", player.Kills), lines, width);
            AddLineToLines(String.Format("# Lives: {0,1} ", player.Lives), lines, width);
            AddLineToLines(String.Format("# Missiles: {0,1}/{1,1} ", player.Missiles.Count, player.MissileLimit), lines, width);
        }
 public override object GetValue(Match match)
 {
     return match.GetPlayer(1).AlienWaveSize;
 }
 private void BuildBuilding(Ship ship, Match game)
 {
     ship.Command = GetCommandForBuildingUnderTest();
     game.Update();
 }
 public abstract Object GetValue(Match match);
 public BuildingTestResult(Match game, Object initialValue, Object finalValue)
 {
     Game = game;
     InitialValue = initialValue;
     FinalValue = finalValue;
 }
示例#8
0
        private void LogMatchState(Match match)
        {
            Log("Game state:");
            Log(String.Format("\tRound Number: {0}", match.RoundNumber));

            foreach (var player in match.Players)
            {
                LogPlayerState(player);
            }
        }
 protected string RenderMapAdvanced(Match match)
 {
     var output = new StringBuilder();
     RenderPlayerDetailsAdvanced(match, 2, output);
     RenderMap(match.Map, output);
     RenderPlayerDetailsAdvanced(match, 1, output);
     return output.ToString();
 }
 public static void SetInstance(Match instance)
 {
     _instance = instance;
 }
        public static Match GetInstance()
        {
            if (_instance != null) return _instance;

            _instance = new Match();
            _instance.StartNewGame();
            return _instance;
        }
 protected static Dictionary<string, object> RenderPlayer(Match match, int playerNumber)
 {
     var player = match.GetPlayer(playerNumber);
     var result = new Dictionary<string, object>
     {
         {"Number", playerNumber},
         {"Name", player.PlayerName},
         {"Kills", player.Kills}
     };
     return result;
 }
 protected string RenderState(Match match)
 {
     return JsonConvert.SerializeObject(
         match,
         Formatting.Indented,
         new JsonSerializerSettings
         {
             ReferenceLoopHandling = ReferenceLoopHandling.Ignore
         }
         );
 }
 protected void RenderPlayerDetailsAdvanced(Match match, int playerNumber, StringBuilder output)
 {
     var player = match.GetPlayer(playerNumber);
     var width = match.Map.Width;
     var lines = new List<string>();
     AddBorderAndPlayerNameToLines(player, width, lines);
     AddPlayerAdvancedDetailsToLines(player, width, lines);
     AddPlayerDetailsToLines(player, match, lines);
     AddPlayerLinesToOutput(player, lines, output);
 }
 public override object GetValue(Match match)
 {
     return match.GetPlayer(1).MissileLimit;
 }
        public IMatch GetFlippedCopyOfMatch()
        {
            var flippedEntities = new Dictionary<int, Entity>();
            var flipper = new CoordinateFlipper(Map.Width, Map.Height);
            var flipped = new Match
            {
                BuildingsAvailable = BuildingsAvailable,
                RoundLimit = RoundLimit,
                RoundNumber = RoundNumber
            };

            flipped.Players.Clear();
            flipped.Map = Map.CopyAndFlip(Map, flipper, flippedEntities);
            flipped.Players.Add(Player.CopyAndFlip(GetPlayer(2), flipper, flippedEntities));
            flipped.Players.Add(Player.CopyAndFlip(GetPlayer(1), flipper, flippedEntities));

            return flipped;
        }
        protected static void RenderWinDetails(MatchSummary result, Match match)
        {
            if (match.GetResult() == MatchResult.Tie)
            {
                result.Winner = 1;
                result.WinReason = "Match was a tie, so player 1 wins by default.";
                return;
            }

            var winner = match.GetResult() == MatchResult.PlayerOneWins ? match.GetPlayer(1) : match.GetPlayer(2);
            var opponent = match.GetResult() == MatchResult.PlayerOneWins ? match.GetPlayer(2) : match.GetPlayer(1);

            result.Winner = winner.PlayerNumber;

            if (((opponent.Lives <= 0) && (opponent.Ship == null)) &&
                ((winner.Lives > 0) || (winner.Ship != null)))
            {
                result.WinReason = String.Format("Player {0} ran out of lives.", opponent.PlayerNumber);
            }
            else
            {
                result.WinReason = String.Format("Player {0} had more kills than player {1}.", winner.PlayerNumber,
                    opponent.PlayerNumber);
            }
        }