private void UnRegisterEvent() { foreach (Animal mAni in aniArr) { if (mAni is MachineCat) { MachineCat mCat = (MachineCat)mAni; mCat.RemoveAllEvent(); } } }
public static MachineCat Create(string name, int shouts, string thing) { MachineCat cat = null; if (shouts <= 0) { return(cat); } else { cat = new MachineCat(name, shouts, thing); return(cat); } }
private void RegisterEvent() { foreach (Animal mAni in aniArr) { if (mAni is MachineCat) { MachineCat mCat = (MachineCat)mAni; mCat.RemoveAllEvent(); foreach (Animal ani in aniArr) { if ((ani is Cat) && !(ani is MachineCat)) { Cat cat = ani as Cat; mCat.change += new MachineCat.ChangeThingDelegate(cat.Clap); } } } } }
private void btn_SignUp_Click(object sender, EventArgs e) { int amount = aniArr.Count; if (amount >= 10) { MessageBox.Show("報名額滿!"); return; } switch (cbox_AnimalType.SelectedIndex) { case 0: Cat cat = Cat.Create(txt_CatName.Text, int.Parse(txt_ShoutNum.Text)); if (cat == null) { MessageBox.Show("報名失敗!"); return; } cat.Order = aniArr.Count; aniArr.Add(cat); txt_AmountOfCats.Text = Cat.Amount.ToString(); break; case 1: Dog dog = Dog.Create(txt_CatName.Text, int.Parse(txt_ShoutNum.Text)); if (dog == null) { MessageBox.Show("報名失敗!"); return; } dog.Order = aniArr.Count; aniArr.Add(dog); txt_AmountOfDogs.Text = Dog.Amount.ToString(); break; case 2: Cattle cattle = Cattle.Create(txt_CatName.Text, int.Parse(txt_ShoutNum.Text)); if (cattle == null) { MessageBox.Show("報名失敗!"); return; } cattle.Order = aniArr.Count; aniArr.Add(cattle); txt_AmountOfCattles.Text = Cattle.Amount.ToString(); break; case 3: Sheep sheep = Sheep.Create(txt_CatName.Text, int.Parse(txt_ShoutNum.Text)); if (sheep == null) { MessageBox.Show("報名失敗!"); return; } sheep.Order = aniArr.Count; aniArr.Add(sheep); txt_AmountOfSheeps.Text = Sheep.Amount.ToString(); break; case 4: MachineCat mcat = MachineCat.Create(txt_CatName.Text, int.Parse(txt_ShoutNum.Text), txt_Thing.Text); if (mcat == null) { MessageBox.Show("報名失敗!"); return; } mcat.Order = aniArr.Count; aniArr.Add(mcat); txt_AmountOfCats.Text = Cat.Amount.ToString(); break; case 5: MagicCattle mcattle = MagicCattle.Create(txt_CatName.Text, int.Parse(txt_ShoutNum.Text), txt_Thing.Text); if (mcattle == null) { MessageBox.Show("報名失敗!"); return; } mcattle.Order = aniArr.Count; aniArr.Add(mcattle); txt_AmountOfCattles.Text = Cattle.Amount.ToString(); break; default: break; } txt_AmountOfAnimals.Text = aniArr.Count.ToString(); }