示例#1
0
        public Game()
        {
            InitializeComponent();

            _player = new Player();
            _player.DisplayOn(gameCanvas);

            _alien = new Alien();
            _alien.DisplayOn(gameCanvas);

            _bombs  = new BombCollection();
            _lasers = new LaserCollection();

            _animationTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(40)
            };
            _animationTimer.Tick += animationTimer_Tick;
            _animationTimer.Start();


            _bombTimer = new DispatcherTimer
            {
                Interval = TimeSpan.FromSeconds(2)
            };
            _bombTimer.Tick += bombTimer_Tick;
            _bombTimer.Start();
        }
示例#2
0
        public void ShootLaser(LaserCollection lasers)
        {
            int   laserX = X + Width / 2;
            int   laserY = Y - Height;
            Laser laser  = new Laser(laserX, laserY, lasers);

            laser.DisplayOn(canvas);
        }
示例#3
0
        public Laser(int x, int y, LaserCollection laserCollection)
        {
            _ellipse = new Ellipse {
                Fill = new SolidColorBrush(Colors.Black)
            };
            _stepSize        = 15;
            _laserCollection = laserCollection;

            X      = x;
            Y      = y;
            Width  = 5;
            Height = 10;

            laserCollection.Add(this);
        }