/// <summary> /// This method is called whenever an Animal being viewed moves by itself, /// (or when drag&drop is used to move an Animal or a Plant, when implemented). /// </summary> public void LifeFormMovedEvent() { ContainingCellView.RemoveLifeForm(); Position targetPos = lifeForm.Cell.Position; CellView targetCellView = PigWorldView.GetCellViewFromPosition(targetPos); targetCellView.AddLifeFormView(this); ContainingCellView = targetCellView; }
/// <summary> /// Constructs the LifeFormView. /// </summary> /// <param name="pigWorldView"> the view of the pigWorld. </param> /// <param name="lifeForm"> the LifeForm to view. </param> protected LifeFormView(PigWorldView pigWorldView, LifeForm lifeForm) { this.pigWorldView = pigWorldView; this.lifeForm = lifeForm; Position position = lifeForm.Cell.Position; CellView cellView = pigWorldView.GetCellViewFromPosition(position); this.containingCellView = cellView; this.lifeForm.lifeFormMovedEvent += LifeFormMovedEvent; }
/// <summary> /// Creates all the CellViews in this PigWorldView. /// </summary> private void CreateCellViews() { cellViews = new CellView[pigWorld.NumOfRows, pigWorld.NumOfColumns]; for (int row = 0; row < pigWorld.NumOfRows; row++) { for (int column = 0; column < pigWorld.NumOfColumns; column++) { Cell cell = pigWorld.GetCell(new Position(row, column)); CellView newCellView = new CellView(this, cell); cellViews[row, column] = newCellView; } } }