Ejemplo n.º 1
0
        internal static FrameworkElement PlayerControlFactory(Player player, List <string> imageNames, double scale)
        {
            AnimatedImage playerControl = new AnimatedImage(imageNames, TimeSpan.FromMilliseconds(300));

            playerControl.Width  = player.Size.Width * scale;
            playerControl.Height = player.Size.Height * scale;
            SetCanvasLocation(playerControl, player.Location.X * scale, player.Location.Y * scale);
            return(playerControl);
        }
Ejemplo n.º 2
0
        // SOLVED problem: was not passing the INVADER object Size properties to
        // this method; it takes them from the AnimatedImage control directly!
        internal static FrameworkElement InvaderControlFactory(Invader invader, List <string> imageNames, double scale)
        {
            AnimatedImage invaderControl = new AnimatedImage(imageNames, TimeSpan.FromMilliseconds(200));

            invaderControl.Width  = invader.Size.Width * scale;
            invaderControl.Height = invader.Size.Width * scale;
            SetCanvasLocation(invaderControl, invader.Location.X * scale, invader.Location.Y * scale);
            return(invaderControl);
        }
Ejemplo n.º 3
0
        internal static FrameworkElement ShotControlFactory(Shot shot, List <string> imageNames, double scale)
        {
            AnimatedImage shotControl = new AnimatedImage(imageNames, TimeSpan.FromMilliseconds(100));

            shotControl.Width  = Shot.ShotSize.Width * scale;
            shotControl.Height = Shot.ShotSize.Height * scale;
            SetCanvasLocation(shotControl, shot.Location.X * scale, shot.Location.Y * scale);
            return(shotControl);
        }
Ejemplo n.º 4
0
        internal static FrameworkElement InvaderControlFactory(Invader invader, double scale)
        {
            IEnumerable <string> imageNames     = CreateImageList(invader.InvaderType);
            AnimatedImage        invaderControl = new AnimatedImage(imageNames, TimeSpan.FromSeconds(.75));

            invaderControl.Width  = invader.Size.Width * scale;
            invaderControl.Height = invader.Size.Height * scale;
            SetCanvasLocation(invaderControl, invader.Location.X * scale, invader.Location.Y * scale);

            return(invaderControl);
        }
Ejemplo n.º 5
0
        internal static FrameworkElement PlayerControlFactory(Player player, double scale)
        {
            AnimatedImage playerControl = new AnimatedImage(new List <string>()
            {
                "player.png", "player.png"
            }, TimeSpan.FromSeconds(1));

            playerControl.Width  = player.Size.Width * scale;
            playerControl.Height = player.Size.Height * scale;
            SetCanvasLocation(playerControl, player.Location.X * scale, player.Location.Y * scale);
            return(playerControl);
        }
        public static AnimatedImage PlayerFactory(double width, double height, double scale, TimeSpan moveInterval)
        {
            List <string> imageNames = new List <string>();

            imageNames.Add("player.png");

            AnimatedImage player = new AnimatedImage(imageNames, moveInterval);

            player.Width  = width * scale;
            player.Height = height * scale;
            return(player);
        }
Ejemplo n.º 7
0
        public static AnimatedImage InvaderControlFactory(InvaderType type, Point location, double scale)
        {
            List <string> imageNames = new List <string>
            {
                type + "1.png",
                type + "2.png",
                type + "3.png",
                type + "4.png",
            };
            AnimatedImage invader = new AnimatedImage(imageNames, TimeSpan.FromMilliseconds(100));

            ResizeElement(invader, Invader.InvaderSize.Width, Invader.InvaderSize.Height, scale);
            SetCanvasLocation(invader, location, scale);
            return(invader);
        }
        public static AnimatedImage InvaderFactory(int invaderType, double width, double height, double scale, TimeSpan moveInterval)
        {
            List <string> imageNames = new List <string>();
            string        fileName   = "";

            switch (invaderType)
            {
            case 0:
                fileName = "star";
                break;

            case 1:
                fileName = "satellite";
                break;

            case 2:
                fileName = "flyingsaucer";
                break;

            case 3:
                fileName = "bug";
                break;

            case 4:
                fileName = "spaceship";
                break;

            default:
                fileName = "star";
                break;
            }

            imageNames.Add(fileName + "1.png");
            imageNames.Add(fileName + "2.png");
            imageNames.Add(fileName + "3.png");
            imageNames.Add(fileName + "4.png");

            AnimatedImage invader = new AnimatedImage(imageNames, moveInterval);

            invader.Width  = width * scale;
            invader.Height = height * scale;
            return(invader);
        }
Ejemplo n.º 9
0
        public static FrameworkElement ShipControlFactory(Ship ship, double scale)
        {
            AnimatedImage shipControl = new AnimatedImage();

            if (ship is Invader)
            {
                Invader invaderShip = ship as Invader;
                shipControl = new AnimatedImage(CreateInvaderImageList(invaderShip.InvaderType), TimeSpan.FromMilliseconds(500));
            }
            else if (ship is Player)
            {
                Player        playerShip = ship as Player;
                List <string> imageNames = new List <string>();
                imageNames.Add("player.png");
                shipControl = new AnimatedImage(imageNames, TimeSpan.FromSeconds(1));
            }

            shipControl.Width  = ship.Size.Width * scale;
            shipControl.Height = ship.Size.Height * scale;
            SetCanvasLocation(shipControl, ship.Location.X * scale, ship.Location.Y * scale);
            return(shipControl);
        }
Ejemplo n.º 10
0
        public static AnimatedImage PlayerControlFactory(int batteryCharge, Point location, double scale)
        {
            string imageName;

            switch (batteryCharge)
            {
            case 0:
                imageName = "playerWithCharge0.png";
                break;

            case 1:
                imageName = "playerWithCharge1.png";
                break;

            case 2:
                imageName = "playerWithCharge2.png";
                break;

            case 3:
                imageName = "playerWithCharge3.png";
                break;

            default:
                imageName = "playerWithCharge0.png";
                break;
            }
            List <string> imageNames = new List <string>
            {
                imageName,
            };
            AnimatedImage player = new AnimatedImage(imageNames, TimeSpan.FromMilliseconds(1000));

            ResizeElement(player, Player.PlayerSize.Width, Player.PlayerSize.Height, scale);
            SetCanvasLocation(player, location, scale);
            return(player);
        }
Ejemplo n.º 11
0
        public static AnimatedImage InvaderFactory(int invaderType, double width, double height, double scale, TimeSpan moveInterval)
        {
            List<string> imageNames = new List<string>();
            string fileName = "";
            switch (invaderType)
            {
                case 0:
                    fileName = "star";
                    break;
                case 1:
                    fileName = "satellite";
                    break;
                case 2:
                    fileName = "flyingsaucer";
                    break;
                case 3:
                    fileName = "bug";
                    break;
                case 4:
                    fileName = "spaceship";
                    break;
                default:
                    fileName = "star";
                    break;
            }

            imageNames.Add(fileName + "1.png");
            imageNames.Add(fileName + "2.png");
            imageNames.Add(fileName + "3.png");
            imageNames.Add(fileName + "4.png");

            AnimatedImage invader = new AnimatedImage(imageNames, moveInterval);
            invader.Width = width * scale;
            invader.Height = height * scale;
            return invader;
        }
 internal static void ResizeElement(AnimatedImage uiElement, double width, double height, double scale)
 {
     uiElement.Width  = width * scale;
     uiElement.Height = height * scale;
 }
Ejemplo n.º 13
0
        public static AnimatedImage PlayerFactory(double width, double height, double scale, TimeSpan moveInterval)
        {
            List<string> imageNames = new List<string>();
            imageNames.Add("player.png");

            AnimatedImage player = new AnimatedImage(imageNames, moveInterval);
            player.Width = width * scale;
            player.Height = height * scale;
            return player;
        }
Ejemplo n.º 14
0
 internal static void ResizeElement(AnimatedImage uiElement, double width, double height, double scale)
 {
     uiElement.Width = width * scale;
     uiElement.Height = height * scale;
 }
Ejemplo n.º 15
0
 // Rather than have separate factory methods for players and invaders, I combined the code into
 // a ShipControlFactory method to reduce duplicate code and make future changes easier.
 public static FrameworkElement ShipControlFactory(Ship ship, double scale)
 {
     AnimatedImage shipImage = new AnimatedImage();
     if (ship is Invader)
     {
         Invader invader = ship as Invader;
         shipImage = new AnimatedImage(GenerateImageList(invader.InvaderType),
             TimeSpan.FromMilliseconds(500));
     }
     else if (ship is Player)
     {
         Player player = ship as Player;
         shipImage = new AnimatedImage(new List<string>() { "player.png", "player.png" },
             TimeSpan.FromSeconds(1));
     }
     shipImage.Width = ship.Size.Width * scale;
     shipImage.Height = ship.Size.Height * scale;
     SetCanvasLocation(shipImage, ship.Location.X * scale, ship.Location.Y * scale);
     return shipImage;
 }