Exemplo n.º 1
0
        /// <summary>
        /// Draws the animal/item.
        /// </summary>
        /// <param name="item">The animal/item to be drawn.</param>
        private void DrawItem(ICageable item)
        {
            // Get the animal's/item type by name using the resource key property.
            string resourceKey = item.ResourceKey;

            // Set a local Viewbox variable to the GetViewBox method. This viewbox will be placed in the cageWindow's grid.
            Viewbox viewbox = this.GetViewBox(800, 400, item.XPosition, item.YPosition, resourceKey, item.DisplaySize);

            viewbox.HorizontalAlignment = HorizontalAlignment.Left;
            viewbox.VerticalAlignment   = VerticalAlignment.Top;

            // If the animal/item is moving to the left
            if (item.XDirection == HorizontalDirection.Left)
            {
                // Set the origin point of the transformation to the middle of the viewbox.
                viewbox.RenderTransformOrigin = new Point(0.5, 0.5);

                // Initialize a ScaleTransform instance.
                ScaleTransform flipTransform = new ScaleTransform();

                // Flip the viewbox horizontally so the animal faces to the left
                flipTransform.ScaleX = -1;

                // Apply the ScaleTransform to the viewbox
                viewbox.RenderTransform = flipTransform;
            }

            // Add the viewbox to the grid
            this.cageGrid.Children.Add(viewbox);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Handles the image update.
 /// </summary>
 /// <param name="item">The item to be updated.</param>
 private void HandleImageUpdate(ICageable item)
 {
     if (this.OnImageUpdate != null)
     {
         this.OnImageUpdate(item);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Removes an occupant from the cage.
        /// </summary>
        /// <param name="cagedItem">The occupant to remove.</param>
        public void Remove(ICageable cagedItem)
        {
            this.cagedItems.Remove(cagedItem);

            this.OnImageUpdate -= this.HandleImageUpdate;

            if (this.OnImageUpdate != null)
            {
                this.OnImageUpdate(cagedItem);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds an occupant to the cage.
        /// </summary>
        /// <param name="cagedItem">The occupant to add.</param>
        public void Add(ICageable cagedItem)
        {
            this.cagedItems.Add(cagedItem);

            cagedItem.OnImageUpdate += this.HandleImageUpdate;

            if (this.OnImageUpdate != null)
            {
                this.OnImageUpdate(cagedItem);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Draws animal on canvas.
        /// </summary>
        /// <param name="animal">The animal to be drawn.</param>
        private void DrawItem(ICageable item, int zIndex)
        {
            // Creates and aligns viewbox.
            Viewbox viewBox = GetViewBox(800, 400, item.XPosition, item.YPosition, item.ResourceKey, item.DisplaySize);

            viewBox.HorizontalAlignment = HorizontalAlignment.Left;
            viewBox.VerticalAlignment   = VerticalAlignment.Top;

            // If the animal is moving to the left
            if (item.XDirection == HorizontalDirection.Left)
            {
                // Set the origin point of the transformation to the middle of the viewbox.
                viewBox.RenderTransformOrigin = new Point(0.5, 0.5);

                // Initialize a ScaleTransform instance.
                ScaleTransform flipTransform = new ScaleTransform();

                // Flip the viewbox horizontally so the animal faces to the left
                flipTransform.ScaleX = -1;

                // Apply the ScaleTransform to the viewbox
                viewBox.RenderTransform = flipTransform;
            }

            // Create new transform group.
            TransformGroup transformGroup = new TransformGroup();

            if (item.HungerState == HungerState.Unconscious)
            {
                SkewTransform unconsciousSkew = new SkewTransform();
                unconsciousSkew.AngleX = item.XDirection == HorizontalDirection.Left ? 30.0 : -30.0;
                transformGroup.Children.Add(unconsciousSkew);

                transformGroup.Children.Add(new ScaleTransform(0.75, 0.5));
            }

            viewBox.RenderTransformOrigin = new Point(0.5, 0.5);

            viewBox.RenderTransform = transformGroup;

            viewBox.Tag = item;

            this.cageGrid.Children.Insert(zIndex, viewBox);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Draws the animal where it's coordinates specifiy.
        /// </summary>
        private void DrawItem(ICageable item)
        {
            // Gets the name and type of the animal.
            //string resourceKey = item.GetType().Name;

            // Ternary operator. If the condition is true, name is baby, otherwise, adult.
            // resourceKey += (animal.Age == 0) ? "Baby" : "Adult";

            // Create a new Canvas. Use the resource key to grab the correct animal inmage.
            // Canvas canvas = Application.Current.Resources[resourceKey] as Canvas;

            // Create a new view box.
            Viewbox viewBox = GetViewBox(800, 400, item.XPosition, item.YPosition, item.ResourceKey, item.DisplaySize);

            // Set the view box allignment.
            viewBox.HorizontalAlignment = HorizontalAlignment.Left;
            viewBox.VerticalAlignment   = VerticalAlignment.Top;

            // If the animal is moving to the left
            if (item.XDirection == HorizontalDirection.Left)
            {
                // Set the origin point of the transformation to the middle of the viewbox.
                viewBox.RenderTransformOrigin = new Point(0.5, 0.5);

                // Initialize a ScaleTransform instance.
                ScaleTransform flipTransform = new ScaleTransform();

                // Flip the viewbox horizontally so the animal faces to the left
                flipTransform.ScaleX = -1;

                // Apply the ScaleTransform to the viewbox
                viewBox.RenderTransform = flipTransform;
            }

            // Attach the view box to the cage grid.
            this.cageGrid.Children.Add(viewBox);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Removes animal from cage.
 /// </summary>
 /// <param name="animal">Animal to be removed.</param>
 public void Remove(ICageable cagedItem)
 {
     this.cagedItems.Remove(cagedItem);
     cagedItem.OnImageUpdate -= this.HandleImageUpdate;
     this.OnImageUpdate?.Invoke(cagedItem);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Adds animal to cage.
 /// </summary>
 /// <param name="animal">Animal to be added.</param>
 public void Add(ICageable cagedItem)
 {
     this.cagedItems.Add(cagedItem);
     cagedItem.OnImageUpdate += this.HandleImageUpdate;
     this.OnImageUpdate?.Invoke(cagedItem);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Handles the image update.
 /// </summary>
 /// <param name="item">The item to be handled.</param>
 private void HandleImageUpdate(ICageable item)
 {
     this.OnImageUpdate?.Invoke(item);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Removes the animal from the cage.
 /// </summary>
 /// <param name="animal"></param>
 public void Remove(ICageable cagedItem)
 {
     // Removes an item from the list of caged items.
     this.cagedItems.Remove(cagedItem);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Adds the animal to the cage.
 /// </summary>
 /// <param name="animal"></param>
 public void Add(ICageable cagedItem)
 {
     // Adds an item to the list of caged items.
     this.cagedItems.Add(cagedItem);
 }
        /// <summary>
        /// Draws the item to the screen.
        /// </summary>
        /// <param name="item">The item to draw.</param>
        /// <param name="zIndex">The index of the item.</param>
        private void DrawItem(ICageable item, int zIndex)
        {
            // Resource key.
            string resourceKey = item.ResourceKey;

            // Gets the view box.
            Viewbox animalViewbox = this.GetViewBox(800, 400, item.XPosition, item.YPosition, resourceKey, item.DisplaySize);

            // Aligns the view box to the top left of the grid.
            animalViewbox.HorizontalAlignment = HorizontalAlignment.Left;
            animalViewbox.VerticalAlignment   = VerticalAlignment.Top;

            TransformGroup unconsciousTransformGroup = new TransformGroup();

            // Label
            if (item is Animal)
            {
                Label animalLabel = new Label();
                animalLabel.Content  = (item as Animal).Name;
                animalLabel.Height   = 30;
                animalLabel.FontSize = 16;
                animalLabel.Width    = animalViewbox.Width;
                animalLabel.HorizontalContentAlignment = HorizontalAlignment.Center;

                animalLabel.Margin = new Thickness(animalViewbox.Margin.Left, animalViewbox.Margin.Top - animalLabel.Height, 0, 0);
                animalLabel.HorizontalAlignment = HorizontalAlignment.Left;
                animalLabel.VerticalAlignment   = VerticalAlignment.Top;
            }

            // If the animal is moving to the left
            if (item.XDirection == HorizontalDirection.Left)
            {
                // Set the origin point of the transformation to the middle of the viewbox
                animalViewbox.RenderTransformOrigin = new Point(0.5, 0.5);

                // Initialize a ScaleTransform instance
                ScaleTransform flipTransform = new ScaleTransform();

                // Flip the viewbox horizontally so the animal faces to the left.
                flipTransform.ScaleX = -1;

                // Adds flip transform to group.
                unconsciousTransformGroup.Children.Add(flipTransform);

                // Apply the ScaleTransform to the viewbox
                animalViewbox.RenderTransform = flipTransform;
            }

            // Create a new SkewTransform and set its Angle to 30 degrees in the direction the cageable is facing.
            SkewTransform unconsciousSkew = new SkewTransform();

            unconsciousSkew.AngleX = item.XDirection == HorizontalDirection.Left ? 30.0 : -30.0;

            // Creates a new ScaleTransform and set it to half the height and three fourths of the width.
            ScaleTransform unconsciousScale = new ScaleTransform();

            unconsciousScale.ScaleY = unconsciousScale.ScaleY * .5;
            unconsciousScale.ScaleX = unconsciousScale.ScaleX * .75;

            // Adds transforms to the group.
            unconsciousTransformGroup.Children.Add(unconsciousSkew);
            unconsciousTransformGroup.Children.Add(unconsciousScale);

            if (item.HungerState == HungerState.Unconscious)
            {
                // Adds the group to the render transform.
                animalViewbox.RenderTransform = unconsciousTransformGroup;
            }

            // Stores the object in the vivewbox for future reference.
            animalViewbox.Tag = item;

            // Add the viewbox to the grid.
            this.cageGrid.Children.Insert(zIndex, animalViewbox);

            // Increment index.
            zIndex++;
        }
Exemplo n.º 13
0
 /// <summary>
 /// Removes an animal from the cage.
 /// </summary>
 /// <param name="cagedItem">The item to be removed from the cage.</param>
 public void Remove(ICageable cagedItem)
 {
     this.cagedItems.Remove(cagedItem);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Adds an animal to the cage.
 /// </summary>
 /// <param name="cagedItem">The item to be added to the cage.</param>
 public void Add(ICageable cagedItem)
 {
     this.cagedItems.Add(cagedItem);
 }