Example #1
0
        /// <summary>
        /// Event-handler for when the cell changes in some way,
        /// other than having a nonlivingThing put-down or picked-up.
        /// </summary>
        public void CellChangedEvent()
        {
            // If there is a LifeFormView, refresh its image.
            if (this.lifeFormView != null)
            {
                this.Image = lifeFormView.PaintImage();
            }

            Invalidate();  // Cause the OnPaint method to repaint this CellView.
        }
Example #2
0
        /// <summary>
        /// Adds a LifeFormView to this CellView.
        /// This happens when a LifeForm is added to a Cell, either by the user,
        /// or when an animal moves from one cell to another.
        /// </summary>
        /// <param name="view"> the LifeFormView to add. </param>
        public void AddLifeFormView(LifeFormView lifeFormView)
        {
            // Check that the cell has no life-form already.  (It may have nonLivingThings, e.g. pig food.)
            Debug.Assert(this.lifeFormView == null);
            this.lifeFormView = lifeFormView;

            // Update this cell's image.
            this.Image = lifeFormView.PaintImage();

            // If the life-form changes or is destroyed, tell this CellView about it.
            this.lifeFormView.LifeForm.thingChangedEvent   += ThingChangedEvent;
            this.lifeFormView.LifeForm.thingDestroyedEvent += ThingDestroyedEvent;
            this.ContextMenuStrip = this.lifeFormView.contextMenuStrip;  // Assign the context-menu to this CellView.
        }