Пример #1
0
        /// <summary>
        /// Create move behavior.
        /// </summary>
        /// <param name="type"> The type of move behavior.</param>
        /// <returns> A move behavior.</returns>
        public static IMoveBehavior CreateMoveBehavior(MoveBehaviorType type)
        {
            IMoveBehavior moveBehavior = null;

            // Depending on type, change behavior.
            switch (type)
            {
            case MoveBehaviorType.Fly:
                moveBehavior = new FlyBehavior();
                break;

            case MoveBehaviorType.Pace:
                moveBehavior = new PaceBehavior();
                break;

            case MoveBehaviorType.Swim:
                moveBehavior = new SwimBehavior();
                break;

            case MoveBehaviorType.NoMove:
                moveBehavior = new NoMoveBehavior();
                break;
            }
            return(moveBehavior);
        }
Пример #2
0
        /// <summary>
        /// Creates the animal's move behavior.
        /// </summary>
        /// <param name="type">The type of animal.</param>
        /// <returns>Returns the intended movement behavior.</returns>
        public static IMoveBehavior CreateMoveBehavior(MoveBehaviorType type)
        {
            IMoveBehavior animalMove = null;

            switch (type)
            {
            case MoveBehaviorType.Fly:
                animalMove = new FlyBehavior();
                break;

            case MoveBehaviorType.Pace:
                animalMove = new PaceBehavior();
                break;

            case MoveBehaviorType.Swim:
                animalMove = new SwimBehavior();
                break;

            case MoveBehaviorType.Climb:
                animalMove = new ClimbBehavior();
                break;

            case MoveBehaviorType.Hover:
                animalMove = new HoverBehavior();
                break;

            case MoveBehaviorType.NoMove:
                animalMove = new NoMoveBehavior();
                break;
            }

            return(animalMove);
        }
Пример #3
0
 public Microorganism(string name, int xCoordinate, int yCoordinate, int xVelocity, int yVelocity)
 {
     this._name         = name;
     this._type         = null;
     this._isAlive      = true;
     this._xCoordinate  = xCoordinate;
     this._yCoordinate  = yCoordinate;
     this._xVelocity    = xVelocity;
     this._yVelocity    = yVelocity;
     this._moveBehavior = null;
     this._feedBehavior = null;
 }
Пример #4
0
        /// <summary>
        /// Changes the behavior of an animal.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void changeBehaviorButton_Click(object sender, RoutedEventArgs e)
        {
            // Get the animal selected from the list box.
            Animal animal = (Animal)this.animalListBox.SelectedItem;

            // Gets the behavior selected from the combo box.
            MoveBehaviorType behavior = (MoveBehaviorType)this.changeBehaviorComboBox.SelectedItem;

            if (animal != null && behavior != null)
            {
                // Create an IMoveBehavior using the MoveBehaviorFactory.
                IMoveBehavior newBehavior = MoveBehaviorFactory.CreateMoveBehavior(behavior);

                // Set the aniaml's behavior to the new behavior.
                animal.MoveBehavior = newBehavior;
            }
        }
Пример #5
0
 /// <summary>
 /// Changes move behavior of the animal.
 /// </summary>
 /// <param name="sender">The object that initiated the event.</param>
 /// <param name="e">The event arguments of the event.</param>
 private void changeMoveBehaviorButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         object behaviorType = this.changeMoveBehaviorComboBox.SelectedItem;
         Animal animal       = this.animalListBox.SelectedItem as Animal;
         if (animal != null && behaviorType != null)
         {
             IMoveBehavior newmovebehavior = MoveBehaviorFactory.CreateMoveBehavior((MoveBehaviorType)behaviorType);
             animal.MoveBehavior = newmovebehavior;
         }
     }
     catch (NullReferenceException)
     {
         MessageBox.Show("Please select a behavior type and an animal to change its move behavior.");
     }
 }
Пример #6
0
    public void SetUnit(string className)
    {
        var UnitData = GameManager.Get.GetUnitData(className);

        m_ClassName      = UnitData.m_ClassName;
        gameObject.name += "-" + m_ClassName;

        m_SpriteRenderer        = GetComponent <SpriteRenderer>();
        m_SpriteRenderer.sprite = UnitData.m_CharSprite;

        m_AttackBehavior = Instantiate(UnitData.m_AttackBehav);
        //m_AttackBehavior = UnitData.m_AttackBehav;
        //인스턴싱 안하는것도 방법일수 있지만
        //복잡한 게임 특성상 해당 비헤이비어가 따로 변수를 저장해야하는 케이스가 생길 확률이 높음,
        //그럴 경우 인스턴스가 타 유닛과 공유되면 문제 야기함.
        //전부 파라미터로 받아버리는것도 방법이 될수 있음.
        m_MoveBehavior = Instantiate(UnitData.m_MoveBehav);
    }
Пример #7
0
        /// <summary>
        /// Changes the move behavior via the button click.
        /// </summary>
        /// <param name="sender">System data.</param>
        /// <param name="e">Associated event data.</param>
        private void changeMoveBehaviorButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Get the selected animal in the list box.
                Animal           animal           = this.animalListBox.SelectedItem as Animal;
                MoveBehaviorType moveBehaviorType = (MoveBehaviorType)this.changeMoveBehaviorComboBox.SelectedItem;

                if (animal != null)
                {
                    IMoveBehavior animalMove = MoveBehaviorFactory.CreateMoveBehavior(moveBehaviorType);
                    animal.MoveBehavior = animalMove;
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("An animal and a behavior both need to be selected.");
            }
        }
Пример #8
0
 /// <summary>
 /// Инициализирует новый игровой юнит.
 /// </summary>
 /// <param name="player">Игрок, управляющий юнитом.</param>
 /// <param name="_attackBehavior">Поведение атаки юнита.</param>
 /// <param name="_moveBehavior">Поведение передвижения юнита.</param>
 /// <param name="_canStandWithOtherUnitsBehavior">Поведение юнита при нахождении с другими на одной клетке.</param>
 /// <param name="_canMoveBehavior">Поведение юнита при определении, может ли он передвигаться.</param>
 /// <param name="_canAttackBehavior">Поведение юнита при определении, может ли он атаковать.</param>
 /// <param name="maxMoveRange">Дистанция передвижения юнита.</param>
 /// <param name="maxAttackRange">Дистанция атаки юнита.</param>
 /// <param name="hp">Очки здоровья юнита.</param>
 /// <param name="damage">Урон, наносимый юнитом.</param>
 protected PlayableUnit(
     Player player,
     IAttackBehavior _attackBehavior,
     IMoveBehavior _moveBehavior,
     ICanStandWithOtherUnitBehavior _canStandWithOtherUnitsBehavior,
     ICanMoveBehavior _canMoveBehavior,
     ICanAttackBehavior _canAttackBehavior,
     int maxMoveRange,
     int maxAttackRange,
     int hp,
     int damage)
 {
     Player         = player;
     attackBehavior = _attackBehavior;
     moveBehavior   = _moveBehavior;
     canStandWithOtherUnitBehavior = _canStandWithOtherUnitsBehavior;
     canMoveBehavior   = _canMoveBehavior;
     canAttackBehavior = _canAttackBehavior;
     Hp             = hp;
     Damage         = damage;
     MaxMoveRange   = maxMoveRange;
     MaxAttackRange = maxAttackRange;
 }
Пример #9
0
        public static IMoveBehavior CreateMoveBehavior(MoveBehaviorType type)
        {
            IMoveBehavior result = null;

            switch (type)
            {
            case MoveBehaviorType.Fly:
                result = new FlyBehavior();
                break;

            case MoveBehaviorType.Pace:
                result = new PaceBehavior();
                break;

            case MoveBehaviorType.Swim:
                result = new SwimBehavior();
                break;

            case MoveBehaviorType.Climb:
                result = new ClimbBehavior();
                break;

            case MoveBehaviorType.Hover:
                result = new HoverBehavior();
                break;

            case MoveBehaviorType.Hop:
                result = new HopBehavior();
                break;

            case MoveBehaviorType.NoMove:
                result = new NoMoveBehavior();
                break;
            }

            return(result);
        }
 public RandomController(IOptions <SnakeOptions> options, IMoveBehavior <RandomBehavior> behavior)
     : base(options, behavior)
 {
 }
 public BFSController(IOptions <SnakeOptions> options, IMoveBehavior <BFSBehavior> behavior)
     : base(options, behavior)
 {
 }
Пример #12
0
 public Robot(IMoveBehavior moveBehavior)
 {
     _moveBehavior = moveBehavior;
 }
Пример #13
0
        public Enemy(IMoveBehavior mB, EnemyType type)
        {
            moveBehavior = mB;

            switch (type)
            {
            case EnemyType.Random_Robot:
                // This random code sucks, I will try to improve it next version //
                int r = GameLogic.random.Next(0, 3);                                 //
                if (r == 0)
                {
                    CreateCommonRobot();                                             //
                }
                else if (r == 1)
                {
                    CreateEliteRobot();                                              //
                }
                else
                {
                    CreateGiantRobot();                                              //
                }
                //---------------------------------------------------------------//
                break;

            case EnemyType.Common_Robot:
                CreateCommonRobot();
                break;

            case EnemyType.Elite_Robot:
                CreateEliteRobot();
                break;

            case EnemyType.Giant_Robot:
                CreateGiantRobot();
                break;

            case EnemyType.Boss:
                CreateBoss();
                break;
            }

            X         = 1;
            Y         = 1;
            PreviousX = X;
            PreviousY = Y;

            Height = PhysicalForm.Length;
            Width  = GetWidth();

            //Instantiate boundary coordinates
            //------------------------------//
            BoundaryTopX = new int[Width];
            BoundaryTopY = new int[Width];
            //------------------------------//
            BoundaryBotX = new int[Width];
            BoundaryBotY = new int[Width];
            //------------------------------//
            BoundaryLeftX = new int[Width];
            BoundaryLeftY = new int[Width];
            //------------------------------//
            BoundaryRightX = new int[Width];
            BoundaryRightY = new int[Width];
            //------------------------------//
            GetCurrentBoundaryCoordinates();
        }
Пример #14
0
 public BaseController(IOptions <SnakeOptions> options, IMoveBehavior behavior)
 {
     _options  = options;
     _behavior = behavior;
 }
Пример #15
0
 public void SetMoveBehavior(IMoveBehavior moveStrategy)
 {
     _moveStrategy = moveStrategy;
 }