List <IUnit> GetAvailibleForAttackUnits(int start, int range, IArmy enemyArmy) { List <IUnit> availibleForAttack = new List <IUnit>(Range); //обойдем текущий ряд и выше int currentRange = range; for (int i = start; i >= 0 && currentRange > 0; i--) { for (int j = 0; j < currentRange; j++) { int pos = i + j * enemyArmy.Width; if (pos >= enemyArmy.Count) { break; } availibleForAttack.Add(enemyArmy.GetUnit(pos)); } currentRange--; } //обойдем нижние ряды currentRange = range - 1; for (int i = start + 1; i < enemyArmy.Width && currentRange > 0; i++) { for (int j = 0; j < currentRange; j++) { int pos = i + j * enemyArmy.Width; if (pos >= enemyArmy.Count) { break; } availibleForAttack.Add(enemyArmy.GetUnit(pos)); } currentRange--; } return(availibleForAttack); }
public ActionResult DoSpecialAction(int position, IArmy myArmy, IArmy enemyArmy, Random random = null) { if (random == null) { random = new Random(); } double probability = random.NextDouble(); //для выстрела сгенерированная вероятность должна принадлежать промежутку [0, ArcheryProbability) if (probability >= ArcheryProbability) { return(ActionResult.Empty); } int range = Range - (int)position / myArmy.Width; int start = position % myArmy.Width; if (range <= 0) { return(ActionResult.Empty); } List <IUnit> availibleForAttack = GetAvailibleForAttackUnits(start, range, enemyArmy); if (availibleForAttack.Count == 0) { return(ActionResult.Empty); } int unitForAttack = random.Next(0, availibleForAttack.Count); IUnit resultUnit = availibleForAttack[unitForAttack].TakeDamage(ArcheryPower); if (resultUnit != availibleForAttack[unitForAttack]) { enemyArmy.ReplaceUnit(resultUnit, availibleForAttack[unitForAttack]); } return(new ActionResult(this, availibleForAttack[unitForAttack], ActionResultType.Shot)); }
public void GameStep(object sender, EventArgs e) { if (_redArmy.IsAlive() && _blueArmy.IsAlive()) { _redArmy.UpdateAliveUnits(); _blueArmy.UpdateAliveUnits(); _redArmy.ActWithout(GameBoard, _player); if (Actions.Count > 0) { _player.Act(GameBoard, Actions.Dequeue()); } _blueArmy.Act(GameBoard); } if (!_blueArmy.IsAlive()) { Winner = _redArmy; } if (!_redArmy.IsAlive()) { Winner = _blueArmy; } }
private IEnumerable <ActionResult> CollectUnits(IArmy firstArmy, IArmy secondArmy) { List <ActionResult> collectedUnits = firstArmy.CollectKilledUnits(); collectedUnits.AddRange(secondArmy.CollectKilledUnits()); if (collectedUnits.Count == 0) { _gameEngine.EmptyTurns++; } else { _gameEngine.EmptyTurns = 0; } if (_gameEngine.EmptyTurns == MaxEmptyTurns) { _gameEngine.IsDeadHeat = true; } return(collectedUnits); }
public List <IUnit> getSpecialAbilityTargets(IArmy friendlyArmy, IArmy enemiesArmy, ISpecialAbility unit) { List <IUnit> friendlyUnits = friendlyArmy.Units; int position = friendlyUnits.IndexOf(unit); int colNum = position / N, rowNum = position % N; int i = 0; List <IUnit> availableRange = new List <IUnit>(); foreach (var armyUnit in friendlyUnits) { int unitColNum = i / N, unitRowNum = i % N; if (!armyUnit.isDead() && i != position && Math.Abs(unitColNum - colNum) + Math.Abs(unitRowNum - rowNum) <= unit.SpecialAbilityRange) { availableRange.Add(armyUnit); } i++; } i = 0; foreach (var armyUnit in enemiesArmy.Units) { int unitColNum = i / N, unitRowNum = i % N; if (!armyUnit.isDead() && i != position && Math.Abs(unitColNum - colNum) + Math.Abs(unitRowNum - rowNum) + colNum + 1 <= unit.SpecialAbilityRange) { availableRange.Add(armyUnit); } i++; } return(availableRange); }
private void Fight(IArmy firstArmy, IArmy secondArmy) { if (EndGame()) { return; } List <IUnit> firstLineFirstArmy = GetFirstLine(firstArmy); List <IUnit> firstLineSecondArmy = GetFirstLine(secondArmy); var minPossiblePairs = Math.Min(GameStrategy.SizeOfRow, Math.Min(firstArmy.Count(), secondArmy.Count())); //Сражаются бойцы, у которых есть противник for (int i = 0; i < minPossiblePairs; i++) { IUnit Attecker = firstLineFirstArmy[i]; IUnit Defender = firstLineSecondArmy[i]; StepInfo += $"\n\nАрмия {firstArmy.ArmyName} - {Attecker.GetInfo()}\n\n\t\t\t|--|--СРАЖАЕТСЯ С--|--|\n\nАрмией {secondArmy.ArmyName} - {Defender.GetInfo()}\n"; IUnit attackedUnit = Attecker.Fight(Defender); if (attackedUnit == null) { StepInfo += $"\n\t\t\t -------ИТОГ-------\n\nАрмия {secondArmy.ArmyName} АТТАКОВАНА! Пострадал {Defender.GetInfo()}!\n"; } else { StepInfo += $"\n\t\t\t -------ИТОГ-------\n\nВ армии {secondArmy.ArmyName} СМЕРТЬ! Погиб {Defender.Name}!\n"; if (Subscribed == true) { StepInfo += $"\n\t\t\t{secondArmy.NotifyAboutDeath()}\n"; } secondArmy.Remove(attackedUnit); } } if (EndGame()) { return; } }
public IEnumerable <ActionResult> Fight(IArmy firstArmy, IArmy secondArmy, Random random = null) { if (random == null) { random = new Random(); } firstArmy.Width = 3; secondArmy.Width = 3; List <ActionResult> results = new List <ActionResult>(); int count = Math.Min(firstArmy.Count, secondArmy.Count); count = Math.Min(count, 3); for (int i = 0; i < count; i++) { IUnit first = firstArmy.GetUnit(i); IUnit second = secondArmy.GetUnit(i); int turnRound = random.Next(0, 2); //чей ход должен быть следующим: 0 - 1-го игрока, 1 - 2-го игрока if (turnRound == 0) { results.AddRange(Attack(i, first, second, firstArmy, secondArmy)); } else if (turnRound == 1) { results.AddRange(Attack(i, second, first, secondArmy, firstArmy)); } } results.AddRange(DoSpecialActions(count, firstArmy, secondArmy, random)); return(results); }
public void SetUp() { wareHouse = new WareHouse(); army = new Army(); missionController = new MissionController(army, wareHouse); }
public SoldierRegenerateCommand(IArmy army) { this.army = army; }
public GameController(ISoldierFactory soldierFactory, IMissionFactory missionFactory, IArmy army, IWriter writer) { this.missionFactory = missionFactory; this.soldierFactory = soldierFactory; this.Army = army; this.WareHouse = new WareHouse(this); this.MissionControllerField = new MissionController(army, this.WareHouse); this.writer = writer; }
public Engine(IReader reader, IWriter writer, IMissionController missionController, IGameController gameController, IArmy army, IWareHouse wareHouse , ISoldierFactory soldierFactory, IMissionFactory missionFactory, IAmmunitionFactory ammunitionFactory) { this.reader = reader; this.writer = writer; this.missionController = missionController; this.gameController = gameController; this.army = army; this.wareHouse = wareHouse; this.soldierFactory = soldierFactory; this.missionFactory = missionFactory; this.ammunitionFactory = ammunitionFactory; }
public GameController(MissionController missionController, IWriter writer, IMissionFactory missionFactory, ISoldierFactory soldiersFactory, IArmy army, IWareHouse wareHouse) { this.missionController = missionController; this.writer = writer; this.missionFactory = missionFactory; this.soldiersFactory = soldiersFactory; this.army = army; this.wareHouse = wareHouse; }
//public GameController() //{ // this.Army = new Iarmy; // this.WearHouse = new List<Ammunition>(); // this.MissionControllerField = new MissionController(Army,WearHouse ); //} public GameController(MissionController missionControllerField, IWareHouse wearHouse, IArmy army) { this.MissionControllerField = missionControllerField; this.WearHouse = wearHouse; this.Army = army; }
public void InitialSetup() { this.army = new Army(); this.wareHouse = new WareHouse(); this.stu = new MissionController(this.army, this.wareHouse); }
public ActionResult DoSpecialAction(int position, IArmy myArmy, IArmy enemyArmy, Random random = null) { return(ArcherUnit.DoSpecialAction(position, myArmy, enemyArmy, random)); }
public void EquipArmy(IArmy army) { }
public Battle(IArmy firstArmy, IArmy secondArmy, IStrategy strategy) { FirstArmy = firstArmy; SecondArmy = secondArmy; GameStrategy = strategy; }
public void TestInit() { this.army = new Army(); this.wareHouse = new WareHouse(); this.sut = new MissionController(army, wareHouse); }
public void EquipArmy(IArmy army) { //TODO }
private void setArmy(IArmy army) => this.army = army;
public GameController(IServiceProvider serviceProvider, IMissionController missionController, ICommandParser commandFactory, IArmy army) { this.army = army; this.missionController = missionController; this.serviceProvider = serviceProvider; this.commandFactory = commandFactory; this.stringBuilder = new StringBuilder(); }
//юниты атакут друг друга по-очереди: сначала первый второго, затем второй - первого private IEnumerable <ActionResult> Attack(IUnit first, IUnit second, IArmy firstArmy, IArmy secondArmy) { List <ActionResult> results = new List <ActionResult>(); IUnit resultUnit = second.TakeDamage(first.Power); if (resultUnit != second) { secondArmy.ReplaceUnit(resultUnit, 0); } if (first.Power > 0) { results.Add(new ActionResult(first, second, ActionResultType.Attack)); } second = secondArmy.GetUnit(0); if (second.Health > 0) { resultUnit = first.TakeDamage(second.Power); if (resultUnit != first) { firstArmy.ReplaceUnit(resultUnit, 0); } if (second.Power > 0) { results.Add(new ActionResult(second, first, ActionResultType.Attack)); } } return(results); }
private void DoSpecialAction(IArmy first, IArmy second) { if (EndGame()) { return; } for (int i = 0; i < GameStrategy.SizeOfRow; i++) { var specialUnits = GetSpecialUnitsInRow(first, i); if (specialUnits.Count == 0) { continue; } Random random = new Random(); int indexSpecial = random.Next(0, specialUnits.Count - 1); var targetUnits = GetTargets(first, second, specialUnits[indexSpecial]); if (targetUnits.Count == 0) { continue; } int indexTargets = random.Next(0, targetUnits.Count - 1); IUnit beforeSpecialAction = targetUnits[indexTargets].Copy(); IUnit afterSpecialAction = specialUnits[indexSpecial].DoSpecialAction(targetUnits[indexTargets]); StepInfo += "\n\n\t\t\t-----ОСОБОЕ ДЕЙСТВИЕ-----"; if (specialUnits[indexSpecial] is Archer) { StepInfo += $"\n\nв Армии {first.ArmyName} - {((IUnit)specialUnits[indexSpecial]).GetInfo()}\n\n\t\t\t|--|--СТРЕЛЯЕТ ИЗ ЛУКА В--|--|\n\nв Армию {second.ArmyName} - {beforeSpecialAction.GetInfo()}"; if (afterSpecialAction == specialUnits[indexSpecial]) { StepInfo += $"\n\n\t\t\t -------ИТОГ-------\n\nв Армии {second.ArmyName} ПОГИБАЕТ {targetUnits[indexTargets].Name}\n"; if (Subscribed == true) { StepInfo += $"\n\n\t\t\t{second.NotifyAboutDeath()}\n\n"; } second.Remove(targetUnits[indexTargets]); } else { StepInfo += $"\n\n\t\t\t -------ИТОГ-------\n\nв Армии {second.ArmyName} РАНЕН {targetUnits[indexTargets].GetInfo()}\n"; } } else if (specialUnits[indexSpecial] is Healer) { if (afterSpecialAction != null) { StepInfo += $"\n\nв Армии{first.ArmyName} - {((IUnit)specialUnits[indexSpecial]).GetInfo()}\n\n\t\t\t|---|---ЛЕЧИТ---|---|\n\n в Армии {first.ArmyName} - {beforeSpecialAction.GetInfo()}"; StepInfo += $"\n\n\t\t\t -------ИТОГ-------\n\nв Армии {first.ArmyName} - {targetUnits[indexTargets].GetInfo()} ВЫЛЕЧЕН\n"; } else { StepInfo += $"\n\nЦелитель уснул после ночного дежурства! Никто НЕ ВЫЛЕЧЕН в Армии {first.ArmyName}\n"; } } else if (specialUnits[indexSpecial] is Wizard) { if (afterSpecialAction != null) { StepInfo += $"\n\nв Армии {first.ArmyName} - {((IUnit)specialUnits[indexSpecial]).GetInfo()}\n\n\t\t\t|---|---КЛОНИРУЕТ---|---|\n\n в Армии {first.ArmyName} - {beforeSpecialAction.GetInfo()}"; StepInfo += $"\n\n\t\t\t -------ИТОГ-------\n\nв Армии {first.ArmyName} - {targetUnits[indexTargets].GetInfo()} УСПЕШНО КЛОНИРОВАН.\n"; first.Push(afterSpecialAction); } else { StepInfo += $"\n\nМаг столкнулся с кражей зелий. НИКТО НЕ КЛОНИРОВАН в Армии {first.ArmyName}\n"; } } else if (specialUnits[indexSpecial] is Infantry) { if (afterSpecialAction != null) { targetUnits[indexTargets] = afterSpecialAction; StepInfo += $"\n\nв Армии {first.ArmyName} - {((IUnit)specialUnits[indexSpecial]).GetInfo()}\n\n\t\t\t|---|---ОДЕВАЕТ---|---|\n\n в Армии {first.ArmyName} - {beforeSpecialAction.GetInfo()}"; StepInfo += $"\n\n\t\t\t -------ИТОГ-------\n\nв Армии {first.ArmyName} - {targetUnits[indexTargets].GetInfo()} ОДЕТ В СПЕЦИАЛЬНУЮ АМУНИЦИЮ!\n"; } else { StepInfo += $"\n\nХодоки украли амуницию! НИКТО НЕ ОДЕТ в Армии {first.ArmyName}\n"; } } } }
public void EquipArmy(IArmy army) { foreach (var soldier in army.Soldiers) { } }
public void Menu() { Console.WriteLine("\nМеню:"); Console.WriteLine("1. Создать армию"); Console.WriteLine("2. Показать состав армии"); Console.WriteLine("3. Сделать ход"); Console.WriteLine("4. Отменить ход"); Console.WriteLine("5. Вернуть ход обратно"); Console.WriteLine("6. Играть до конца"); Console.WriteLine("7. Уведомлять о гибели бойцов"); Console.WriteLine("8. Отменить уведомления о гибели бойцов"); Console.WriteLine(); var answ = Console.ReadLine(); Console.WriteLine(); switch (answ) { case "1": var armyFactory = new ArmyFactory(); Console.WriteLine("Введите сумму, на которую необходимо создать первую армию:"); int price; while (!int.TryParse(Console.ReadLine(), out price)) { Console.WriteLine("Необходимо ввести целочисленоое значение"); } firstArmy = armyFactory.CreateArmy(price, "ЛАННИСТЕРЫ"); Console.WriteLine("\nВведите сумму, на которую необходимо создать вторую армию:"); while (!int.TryParse(Console.ReadLine(), out price)) { Console.WriteLine("Необходимо ввести целочисленоое значение"); } secondArmy = armyFactory.CreateArmy(price, "СТАРКИ"); if (strategy == 1) { strt = new OneToOneStrategy(); } else if (strategy == 2) { strt = new ThreeToThreeStrategy(); } else { strt = new NToNStrategy(firstArmy, secondArmy); } battle = new Battle(firstArmy, secondArmy, strt); commandManager = new CommandManager(battle); Logger($"\n\n\t\t\t------Армии СОЗДАНЫ------\n\n{battle.ArmyInfo()}"); Console.ReadLine(); Menu(); break; case "2": Console.WriteLine(); Console.WriteLine(battle.ArmyInfo()); Console.ReadLine(); Menu(); break; case "3": commandManager.Step(); Logger(battle.StepInfo); if (!battle.GameOver) { Console.ReadLine(); } Menu(); break; case "4": commandManager.Undo(out possible); if (possible) { Logger("Отмена предыдущего хода"); } else { Console.WriteLine("\nОтмена хода не может быть выполнена\n"); } Console.ReadLine(); Menu(); break; case "5": commandManager.Redo(out possible); if (possible) { Logger("Ход снова выполнен"); } else { Console.WriteLine("\nВозврат хода не может быть выполнен\n"); } Console.ReadLine(); Menu(); break; case "6": commandManager.PlayTillEnd(); Logger(battle.TillEndInfo); Console.ReadLine(); Menu(); break; case "7": battle.Subscribe(); Console.WriteLine("Подписка на уведомления успешно оформлена"); Console.ReadLine(); Menu(); break; case "8": battle.UnSubscribe(); Console.WriteLine("Подписка на уведомления успешно отменена"); Console.ReadLine(); Menu(); break; default: Console.WriteLine("Неверный ввод! Данного пункта не существует! Попробуйте еще раз!"); Console.ReadLine(); Menu(); break; } }
public void MissionControllerInit() { army = new Army(); wareHouse = new WareHouse(); mc = new MissionController(army, wareHouse); }
public void SetUp() { this.army = new Army(); this.wareHouse = new WareHouse(); this.missionController = new MissionController(this.army, this.wareHouse); }
private void CreateArmies(int cost) { this.army1 = this.CreateArmy(cost); this.army2 = this.CreateArmy(cost); }
public MissionController(IArmy army, IWareHouse wareHouse) { this.army = army; this.wareHouse = wareHouse; this.missionQueue = new Queue <IMission>(); }
public void EquipArmy(IArmy army) { throw new System.NotImplementedException(); }