public void Render(IWords Iworld, IForms IfieldForm) //мир и формы должны через интерфейсную ссылку передаваться { this.Iworld = Iworld; //или перегружать класс будем(хуже) if (IfieldForm is FieldForm1) { fieldForm = IfieldForm as FieldForm1; } //РАЗВИЛКА!!!!!! if (Iworld is World_1) { world = Iworld as World_1; verwolfHeight = world.verwolfHeight; verwolfWight = world.verwolfWight; subjectPanelGame = world.subjectsPanel; hero = world.hero; fieldForm.renderer = this; //ПОДПИСКИ НА СОБЫТИЯ ФОРМЫ---> ****вервольфа нужно обобщать через интерфейс или абстрактный класс //this.fieldForm.eTruck += new FieldForm.Truck(DrawTrucks); fieldForm.eFieldMouseClick += new FieldMouseClick(DrawCaptureObjects); //ПОДПИСКА ЧЕРЕЗ АНОНИМНЫЙ МЕТОД--->снимаем управление с Hero fieldForm.eFieldMouseUp += delegate(object sender, MouseEventArgs e){ if (hero.CurrentState == stateHero.Control && Math.Abs(hero.Location.X - e.Location.X) < hero.rangeHero && Math.Abs(hero.Location.Y - e.Location.Y) < hero.rangeHero) { if (e.Button == MouseButtons.Right) { hero.CurrentState = stateHero.Stay; } } }; //ПОДПИСКА ЧЕРЕЗ ЛЯМБДА fieldForm.eFieldMouseMove += (sender, e) => { Point verwolfBeginLocation = world.verfolfBeginLocation; int rateX = verwolfBeginLocation.X + world.verwolfWight; int rateY = verwolfBeginLocation.Y + world.verwolfHeight; if (e.Location.X > verwolfBeginLocation.X && e.Location.X < rateX && e.Location.Y > verwolfBeginLocation.Y && e.Location.Y < rateY && world.verwolf.CurrentState == WolfState.Stay) { DrawTrucks(true); } else { DrawTrucks(false); } }; } InitializeImages(); hero = world.hero; }
public Hive(IWords world) //вторым параметром могли передать делегат sendMessage { World = world as World_1;; Honey = InitialHoney; InitializeLocation(); Random random = new Random(); for (int i = 0; i < InitialBees; i++) { AddBee(random); } }
public Werwolf(World_1 world) : base() { this.hero = world.hero; Location = world.verfolfBeginLocation; CurrentState = WolfState.Stay; this.world = world; //подписываемся на укус пчел foreach (Bee bee in world.bees) { bee.BeeBeeSting += Werwolf_BeeSting; } }
public void GetCurrentWorld(IWords iword) { //РАЗДЕЛ НАСТРОЕК ГЕРОЯ ДЛЯ КАЖДОГО МИРА if (iword is World_1) { this.iword = iword; World_1 world = iword as World_1; Location = world.heroBeginLocation; verwolf = world.verwolf; CurrentState = stateHero.Stay; rangeHero = 50; } }
public Bee(int id, Point location, World_1 world, Hive hive) { this.world = world; this.hive = hive; ID = id; this.location = location; Age = 0; InsideHive = true; destinationFlower = null; NectarCollected = 0; CurrentState = BeeState.Idle; StingGoal = false; }
////ИСХОДНАЯ ТОЧКА, ОТКУДА ЗАПУСКАЕТСЯ МИР И ВИЗУАЛИЗАТОР private void ResetSimulator() { framesRun = 0; renderer = new Renderer(); GameOver pipec = new GameOver(YouLost); hero = new Hero(); //герой общий для всех миров hero.eExchangeWorld += new ExchangeWorld(CurrentExit); timer1.Enabled = true; timer2.Enabled = true; Iworld1 = new World_1(fillPanel, pipec, subjectsPanel, hero); World_1 w1 = Iworld1 as World_1; exchangePortal.Add(Iworld1.Exit, w1.hive); //т.к. у нас пчелы в улье создаются, а сначала мы мир открываем, то вот такие пляски currentWorld = Iworld1; hero.GetCurrentWorld(Iworld1); //герой узнает о мире Iworld1.renderer = renderer; IForm1 = new FieldForm1(); StartWorld(Iworld1); }