Exemplo n.º 1
0
        public static Player CopyAndFlip(Player player, CoordinateFlipper flipper,
                                         Dictionary <int, Entity> flippedEntities)
        {
            var copy = new Player(player)
            {
                PlayerNumber = player.PlayerNumber == 1 ? 2 : 1
            };

            copy.Missiles.Clear();
            foreach (var missile in player.Missiles)
            {
                copy.Missiles.Add(flippedEntities.ContainsKey(missile.Id)
                    ? (Missile)flippedEntities[missile.Id]
                    : Missile.CopyAndFlip(missile, flipper, flippedEntities));
            }

            if (player.MissileController != null)
            {
                copy.MissileController = MissileController.CopyAndFlip(player.MissileController, flipper, flippedEntities);
            }

            if (player.AlienFactory != null)
            {
                copy.AlienFactory = AlienFactory.CopyAndFlip(player.AlienFactory, flipper, flippedEntities);
            }

            copy.AlienManager = AlienManager.CopyAndFlip(player.AlienManager, flipper, flippedEntities);

            if (player.Ship != null)
            {
                copy.Ship = Ship.CopyAndFlip(player.Ship, flipper, flippedEntities);
            }

            return(copy);
        }
        public Map CopyAndFlip(Map map, CoordinateFlipper flipper, Dictionary <int, Entity> flippedEntities)
        {
            var copy = new Map(map);

            // Copy all entities including walls
            for (var y = 0; y < map.Height; y++)
            {
                for (var x = 0; x < map.Width; x++)
                {
                    var entity = map.GetEntity(x, y);

                    if (entity == null)
                    {
                        continue;
                    }

                    Entity flippedEntity = null;
                    if (entity.GetType() == typeof(Alien))
                    {
                        flippedEntity = Alien.CopyAndFlip((Alien)entity, flipper, flippedEntities);
                    }
                    else if (entity.GetType() == typeof(Missile))
                    {
                        flippedEntity = Missile.CopyAndFlip((Missile)entity, flipper, flippedEntities);
                    }
                    else if (entity.GetType() == typeof(Bullet))
                    {
                        flippedEntity = Bullet.CopyAndFlip((Bullet)entity, flipper, flippedEntities);
                    }
                    else if (entity.GetType() == typeof(Shield))
                    {
                        flippedEntity = Shield.CopyAndFlip((Shield)entity, flipper, flippedEntities);
                    }
                    else if (entity.GetType() == typeof(Ship))
                    {
                        flippedEntity = Ship.CopyAndFlip((Ship)entity, flipper, flippedEntities);
                    }
                    else if (entity.GetType() == typeof(AlienFactory))
                    {
                        flippedEntity = AlienFactory.CopyAndFlip((AlienFactory)entity, flipper, flippedEntities);
                    }
                    else if (entity.GetType() == typeof(MissileController))
                    {
                        flippedEntity = MissileController.CopyAndFlip((MissileController)entity, flipper,
                                                                      flippedEntities);
                    }
                    else if (entity.GetType() == typeof(Wall))
                    {
                        flippedEntity = Wall.CopyAndFlip((Wall)entity, flipper, flippedEntities);
                    }

                    if ((flippedEntity != null) && (copy.GetEntity(flippedEntity.X, flippedEntity.Y) == null))
                    {
                        copy.AddEntity(flippedEntity);
                    }
                }
            }

            return(copy);
        }