public void RefreshViews() { clearPanel(); // create arrayList from model and convert to array of Buildings List <AnyBuilding> theBuildingList = myModel.AnyBuildings; g = this.pnlDrawOn.CreateGraphics(); Image image = new Bitmap(@".\Images\ground.png"); g.DrawImage(image, 0, 0); if (theBuildingList.Count == 0) { topBuilding = null; } else { foreach (AnyBuilding b in theBuildingList) { b.Display(g); } if (topBuilding != null) { lblBuildingInfo.Text = topBuilding.CostAndProduction(); Rectangle rec = new Rectangle(topBuilding.x_pos, topBuilding.y_pos, 80, 80); g.DrawRectangle(new Pen(Color.Red), rec); } } // draw all Buildings in array }
private void btnModify_Click(object sender, EventArgs e) { int X, Y; AnyBuilding aBuilding; if (topBuilding != null) { try { X = Convert.ToInt32(txtX.Text); Y = Convert.ToInt32(txtY.Text); // if circle selected create circle Building if (rbCastle.Checked) { double defence = tbCastle.Value * 0.1 + 1; aBuilding = new AnyCastle("Castle", X, Y, defence); } // if square selected create square Building else if (rbStorage.Checked) { Level level = (Level)cbStorage.SelectedIndex; aBuilding = new AnyStorage("Storage", X, Y, level); } else // must be an ellipse { int capacity = Convert.ToInt32(txtTraining.Text); aBuilding = new AnyTraining("Training", X, Y, capacity); } myModel.UpdateBuilding(aBuilding, topBuildingIndex); topBuilding = aBuilding; lblBuildingInfo.Text = topBuilding.CostAndProduction(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + "\r\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Please select an building!"); } }