public static AlienManager CopyAndFlip(AlienManager alienManager, CoordinateFlipper flipper,
                                               Dictionary <int, Entity> flippedEntities)
        {
            var copy = new AlienManager(alienManager)
            {
                PlayerNumber = alienManager.PlayerNumber == 1 ? 2 : 1,
                DeltaX       = -alienManager.DeltaX
            };

            // Clear default copy of waves
            foreach (var wave in copy.Waves)
            {
                wave.Clear();
            }
            copy.Waves.Clear();

            // Copy waves flipped
            for (var i = alienManager.Waves.Count - 1; i >= 0; i--)
            {
                var wave     = alienManager.Waves[i];
                var waveList = new List <Alien>();
                copy.Waves.Add(waveList);

                foreach (var alien in wave)
                {
                    waveList.Add(Alien.CopyAndFlip(alien, flipper, flippedEntities));
                }
            }

            return(copy);
        }
예제 #2
0
        public static Wall CopyAndFlip(Wall wall, CoordinateFlipper flipper, Dictionary <int, Entity> flippedEntities)
        {
            if (flippedEntities.ContainsKey(wall.Id))
            {
                return((Wall)flippedEntities[wall.Id]);
            }

            var copy = new Wall(wall)
            {
                X = flipper.CalculateFlippedX(wall.X),
                Y = flipper.CalculateFlippedY(wall.Y)
            };

            flippedEntities.Add(copy.Id, copy);
            return(copy);
        }
예제 #3
0
        public static Ship CopyAndFlip(Ship ship, CoordinateFlipper flipper, Dictionary <int, Entity> flippedEntities)
        {
            if (flippedEntities.ContainsKey(ship.Id))
            {
                return((Ship)flippedEntities[ship.Id]);
            }

            var copy = new Ship(ship)
            {
                PlayerNumber = ship.PlayerNumber == 1 ? 2 : 1,
                X            = flipper.CalculateFlippedX(ship.X + (ship.Width - 1)),
                Y            = flipper.CalculateFlippedY(ship.Y)
            };

            flippedEntities.Add(copy.Id, copy);
            return(copy);
        }
        public static Missile CopyAndFlip(Missile missile, CoordinateFlipper flipper,
                                          Dictionary <int, Entity> flippedEntities)
        {
            if (flippedEntities.ContainsKey(missile.Id))
            {
                return((Missile)flippedEntities[missile.Id]);
            }

            var copy = new Missile(missile)
            {
                PlayerNumber = missile.PlayerNumber == 1 ? 2 : 1,
                X            = flipper.CalculateFlippedX(missile.X),
                Y            = flipper.CalculateFlippedY(missile.Y)
            };

            flippedEntities.Add(copy.Id, copy);
            return(copy);
        }
        public static Shield CopyAndFlip(Shield shield, CoordinateFlipper flipper,
                                         Dictionary <int, Entity> flippedEntities)
        {
            if (flippedEntities.ContainsKey(shield.Id))
            {
                return((Shield)flippedEntities[shield.Id]);
            }

            var copy = new Shield(shield)
            {
                PlayerNumber = shield.PlayerNumber == 1 ? 2 : 1,
                X            = flipper.CalculateFlippedX(shield.X),
                Y            = flipper.CalculateFlippedY(shield.Y)
            };

            flippedEntities.Add(copy.Id, copy);
            return(copy);
        }
        public static Bullet CopyAndFlip(Bullet bullet, CoordinateFlipper flipper,
                                         Dictionary <int, Entity> flippedEntities)
        {
            if (flippedEntities.ContainsKey(bullet.Id))
            {
                return((Bullet)flippedEntities[bullet.Id]);
            }

            var copy = new Bullet(bullet)
            {
                PlayerNumber = bullet.PlayerNumber == 1 ? 2 : 1,
                X            = flipper.CalculateFlippedX(bullet.X),
                Y            = flipper.CalculateFlippedY(bullet.Y)
            };

            flippedEntities.Add(copy.Id, copy);
            return(copy);
        }
예제 #7
0
        public static AlienFactory CopyAndFlip(AlienFactory alienFactory, CoordinateFlipper flipper,
                                               Dictionary <int, Entity> flippedEntities)
        {
            if (flippedEntities.ContainsKey(alienFactory.Id))
            {
                return((AlienFactory)flippedEntities[alienFactory.Id]);
            }

            var copy = new AlienFactory(alienFactory)
            {
                PlayerNumber = alienFactory.PlayerNumber == 1 ? 2 : 1,
                X            = flipper.CalculateFlippedX(alienFactory.X + (alienFactory.Width - 1)),
                Y            = flipper.CalculateFlippedY(alienFactory.Y)
            };

            flippedEntities.Add(copy.Id, copy);
            return(copy);
        }
        public static Alien CopyAndFlip(Alien alien, CoordinateFlipper flipper, Dictionary <int, Entity> flippedEntities)
        {
            if (flippedEntities.ContainsKey(alien.Id))
            {
                return((Alien)flippedEntities[alien.Id]);
            }

            var copy = new Alien(alien)
            {
                PlayerNumber = alien.PlayerNumber == 1 ? 2 : 1,
                DeltaX       = -alien.DeltaX,
                DeltaY       = -alien.DeltaY,
                X            = flipper.CalculateFlippedX(alien.X),
                Y            = flipper.CalculateFlippedY(alien.Y)
            };

            flippedEntities.Add(copy.Id, copy);
            return(copy);
        }
        private static Match CreateInterestingGameState(out CoordinateFlipper flipper)
        {
            var game = Match.GetInstance();

            game.StartNewGame();
            var map = game.Map;

            flipper = new CoordinateFlipper(map.Width, map.Height);
            var ship1 = game.GetPlayer(1).Ship;
            var ship2 = game.GetPlayer(2).Ship;

            // A rather lengthy sequence of moves to ensure every type of entity is on the map, including alien bullets...
            ship1.Command = ship2.Command = ShipCommand.MoveLeft;
            game.Update();

            ship1.Command = ShipCommand.BuildAlienFactory;
            ship2.Command = ShipCommand.BuildMissileController;
            game.Update();

            ship1.Command = ShipCommand.BuildShield;
            ship2.Command = ShipCommand.MoveRight;
            game.Update();

            ship1.Command = ship2.Command = ShipCommand.MoveRight;
            game.Update();

            ship1.Command = ship2.Command = ShipCommand.MoveRight;
            game.Update();

            ship1.Command = ship2.Command = ShipCommand.Shoot;
            game.Update();

            ship1.Command = ShipCommand.Nothing;
            ship2.Command = ShipCommand.MoveRight;
            game.Update();

            ship1.Command = ShipCommand.Nothing;
            ship2.Command = ShipCommand.Shoot;
            game.Update();
            return(game);
        }