Пример #1
0
        public void ResetObject(SpaceCraft source)
        {
            switch (source.View)
            {
            case SpaceObject.None:
                break;

            case SpaceObject.LightShip:
                //spaceObject = new LightShip(this, _initialX, _initialY,
                //    _active, _shipSpeed, _counter, _hitpoints, _lifes);
                break;

            case SpaceObject.HeavyShip:
                //creature = new HeavyShip(this, _initialX, _initialY,
                //    _active, _shipSpeed, _counter, _hitpoints, _lifes);
                break;

            case SpaceObject.EnemyShip:

                ResetEnemy((EnemyShip)source);
                break;

            case SpaceObject.ShotLeft:

                ResetShot((Shot)source);
                break;

            case SpaceObject.ShotRight:
                //creature = AddShot(_rightShift);
                break;

            case SpaceObject.ShotEnemy:


                for (int i = 0; i < _gameObjects.Count; i++)
                {
                    if (_gameObjects[i] is EnemyShip one)
                    {
                        if (GetMinY(one).Y == one.Shot)
                        {
                            Coordinate newPosition = NewEnemyShotPosition();
                            source.Position.Clear();
                            source.Position.Add(newPosition);
                            break;
                        }
                    }
                }
                break;

            default:
                break;
            }
        }
Пример #2
0
        public void AddObject(SpaceObject source)
        {
            SpaceCraft creature = null;

            bool reset = false;

            for (int i = /*10*/ 0; i < _gameObjects.Count /*_amountOfObjects*/; i++)
            {
                if (source == _gameObjects[i].View && !_gameObjects[i].Active)
                {
                    ResetObject(_gameObjects[i]);
                    reset = true;
                    break;
                }
            }

            if (!reset)
            {
                switch (source)
                {
                case SpaceObject.None:
                    break;

                case SpaceObject.LightShip:
                    creature = new LightShip(this, _initialX, _initialY,
                                             _active, _shipSpeed, _counter, _hitpoints, _lifes);
                    break;

                case SpaceObject.HeavyShip:
                    creature = new HeavyShip(this, _initialX, _initialY,
                                             _active, _shipSpeed, _counter, _hitpoints, _lifes);
                    break;

                case SpaceObject.EnemyShip:
                    creature = AddEnemy();
                    break;

                case SpaceObject.ShotLeft:
                    creature = AddShot(_leftShift);
                    break;

                case SpaceObject.ShotRight:
                    //creature = AddShot(_rightShift);
                    break;

                case SpaceObject.ShotEnemy:
                    creature = AddEnemyShot(_shotEnemyShift);
                    break;

                default:
                    break;
                }

                _gameObjects.Add(creature);
                ++_amountOfObjects;
            }



            //if (_amountOfObjects >= _gameObjects.Length - 1)
            //{
            //    Array.Resize(ref _gameObjects, _gameObjects.Length * 2);
            //}

            //for (int i = /*10*/0; i <= _gameObjects.Count/*_amountOfObjects*/; i++)
            //{
            //    if (_gameObjects[i] is null)
            //    {
            //        _gameObjects[i] = creature;
            //        ++_amountOfObjects;

            //        break;
            //    }

            //    if (!_gameObjects[i].Active)
            //    {
            //        _gameObjects[i] = creature;
            //        break;
            //    }

            //    if (i == _gameObjects.Count - 1)
            //    {
            //        _gameObjects.Add(creature);
            //        break;
            //    }
            //}
        }