示例#1
0
        private void MainForm_KeyPress(object sender, KeyPressEventArgs e)
        {
            switch (e.KeyChar)
            {
            case '1':
                _activeBase.IsActive = false;
                _activeBase          = _bases[0];
                _bases[0].IsActive   = true;
                break;

            case '2':
                _activeBase.IsActive = false;
                _activeBase          = _bases[1];
                _bases[1].IsActive   = true;
                break;

            case '3':
                _activeBase.IsActive = false;
                _activeBase          = _bases[2];
                _bases[2].IsActive   = true;
                break;

            case '7':
                _score -= 5;
                break;

            case '8':
                _score += 5;
                break;

            case '9':
                _activeBase.RemoveHealth(5);
                break;

            case '0':
                _activeBase.AddHealth(5);
                break;

            case '-':
                _activeBase.RemoveAmmo(1);
                break;

            case '=':
                _activeBase.AddAmmo(1);
                break;

            case 'K':
            case 'k':
                _bases[0].RemoveHealth(100);
                _bases[1].RemoveHealth(100);
                _bases[2].RemoveHealth(100);
                break;

            default:
                break;
            }
        }
示例#2
0
        private void gameTimer_Tick(object sender, EventArgs e)
        {
            if (_gameRunning == true)
            {
                foreach (Explosion delExp in _deletedExplosions)
                {
                    _explosions.Remove(delExp);
                }

                foreach (Missile delMis in _deletedMissiles)
                {
                    _missiles.Remove(delMis);
                }

                _deletedExplosions.Clear();
                _deletedMissiles.Clear();

                foreach (Explosion exp in _explosions)
                {
                    if (exp.Update() == true)
                    {
                        _deletedExplosions.Add(exp);
                    }

                    foreach (Missile mis in _missiles)
                    {
                        if (mis.IsBad)
                        {
                            _distanceVector = new Vector(exp.Position.X - mis.Position.X, exp.Position.Y - mis.Position.Y);
                            if (_distanceVector.Length < exp.Radius)
                            {
                                _deletedMissiles.Add(mis);
                                _deletedExplosions.Add(exp);
                                _score += 5;
                                _activeBase.AddAmmo(2);
                            }
                        }
                    }

                    foreach (MissileBase mb in _bases)
                    {
                        _distanceVector = new Vector(exp.Position.X - mb.Position.X, exp.Position.Y - mb.Position.Y);
                        if (_distanceVector.Length < exp.Radius)
                        {
                            mb.RemoveHealth(20);
                            _deletedExplosions.Add(exp);
                        }
                    }
                }

                foreach (Missile mis in _missiles)
                {
                    if (mis.Update() == true)
                    {
                        Explosion explosion = new Explosion(mis.Position);
                        _explosions.Add(explosion);

                        _deletedMissiles.Add(mis);
                    }
                }

                _timeOut++;

                if (_timeOut > 50)
                {
                    int     rand = GetRandomBase();
                    Missile m;
                    m = new Missile(new PointF((gamePanel.Width / 2f) + 10f, 45f), _bases[rand].MissileStartPosition, true);
                    _missiles.Add(m);
                    _timeOut = 0;
                }

                if ((!_bases[0].IsAlive) && (!_bases[1].IsAlive) && (!_bases[2].IsAlive))
                {
                    _gameRunning = false;
                }
            }

            ReDraw();
        }