bool StartBattle(Monster beast, bool initiative) { bool fleed = false; InBattle = true; var battleground = new BattleWindow(Sam, beast, initiative); battleground.Owner = this; Visibility = Visibility.Hidden; battleground.ShowDialog(); fleed = battleground.Fleed; if (!IsLoaded) { return(false); } Visibility = Visibility.Visible; if (beast.HP == 0) { //Выбираем награду if (beast is Goblin) { WeaponChooseWindow weapon = new WeaponChooseWindow(Sam, LeftHand, RightHand); weapon.Owner = this; weapon.ShowDialog(); } //Убираем мимика else if (beast is Mimic) { Dungeon.Chests.Remove(Sam.Position); Dungeon.Map[Sam.Position.Y, Sam.Position.X].ID = 'e'; } //Телепорт ко входу else if (beast is Shadow) { if (Dungeon.Map[Dungeon.Start.Y + 1, Dungeon.Start.X].ID == '0' || Dungeon.Map[Dungeon.Start.Y + 1, Dungeon.Start.X].ID == 'b') { Sam.Position = new Coords(Dungeon.Start.Y, Dungeon.Start.X + 1); } else { Sam.Position = new Coords(Dungeon.Start.Y + 1, Dungeon.Start.X); } } //Находим лут else if (beast.Loot.Count > 0) { WeaponChangeWindow wcw = new WeaponChangeWindow(beast.Loot[DataBase.RNG.Next(beast.Loot.Count)], Sam, LeftHand, RightHand); wcw.ShowDialog(); } if (beast.Food && DataBase.RNG.Next(3) == 0) { var food = new FoodWindow(); food.Owner = this; food.ShowDialog(); FoodChange(1); } Killed.Add(beast); } Keyboard.Focus(this); InBattle = false; ChangeHealth(0); EnergyChange(0); FoodChange(0); return(fleed); }
void Interaction(int backY, int backX) { bool fleed = false; switch (Dungeon.Map[Sam.Position.Y, Sam.Position.X].ID) { case 's': { //Проверка завершения игры if (Sam.RightHand == 'g' || Sam.LeftHand == 'g') { WinWindow endWin = new WinWindow(); endWin.Owner = this; endWin.ShowDialog(); } break; } case 't': { //Нашли сокровище. Во второй раз его не взять WeaponChangeWindow wcw = new WeaponChangeWindow('g', Sam, LeftHand, RightHand); wcw.ShowDialog(); if (Sam.LeftHand == 'g' || Sam.RightHand == 'g') { Dungeon.MonsterTier = 3; } if (wcw.ChestExplored) { Dungeon.Map[Sam.Position.Y, Sam.Position.X].ID = 'e'; } break; } case 'w': { //Нас могут утащить под воду if (DataBase.RNG.Next(10) == 0) { StartBattle(new Tentacle(Dungeon, Sam, Table), false); } break; } case 'c': { //Роемся в сундуке. Ну, или деремся с мимиком char chest = Dungeon.Chests[Sam.Position]; if (chest != 'm') { Dungeon.MonsterTier = 2; WeaponChangeWindow wcw = new WeaponChangeWindow(chest, Sam, LeftHand, RightHand); wcw.ShowDialog(); if (wcw.ChestExplored) { Dungeon.Map[Sam.Position.Y, Sam.Position.X].ID = 'e'; } } else { StartBattle(new Mimic(Dungeon, Sam, Table), false); } break; } case 'e': { //Деремся с монстром, если он тут есть foreach (var beast in Dungeon.Monsters) { if (beast.Position.Equals(Sam.Position)) { fleed = StartBattle(beast, true); if (fleed) { Sam.Position.Y += backY; Sam.Position.X += backX; //Гоблин убегает if (beast is Goblin) { beast.Wander(Sam, Dungeon); } } } } break; } } Redraw(); //Если кого-то убили - убираем с доски. Монстры двигаются только если мы не убегали. Иначе побег не имеет смысла, потому что сразу догонят if (!fleed) { RemoveMonsters(); WanderingMonsters(); } }