Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
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;
            }
        }
Exemplo n.º 4
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.");
            }
        }
Exemplo n.º 5
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);
        }