public void StartFightBattles(List <IFighter <Boxer> > boxers) { BroadcastingBoxing?.Invoke("___Boxing Starting!___\n"); BroadcastingBoxing?.Invoke("Boxers:"); foreach (var boxer in boxers) { BroadcastingBoxing?.Invoke(string.Format("{0, -20} | {1, -10}", $"{boxer.Name} {boxer.Surname}", $"Country: {boxer.CountryFrom}")); } Thread.Sleep(3000); Random rand = new Random(); foreach (var boxer in boxers) { bool win = true; bool played = true; while (played) { Boxer opponent = boxers[rand.Next(0, boxers.Count)] as Boxer; if (boxer.CountryFrom == opponent.CountryFrom) { continue; } else { win = boxer.FightAgainst(opponent); played = false; if (win) { ResultBattle?.Invoke(this, new ResultBattleEventArgs(boxer.Name, boxer.Surname, boxer.CountryFrom, opponent.Name, opponent.Surname, opponent.CountryFrom)); Program.AddPoints(boxer.CountryFrom, 1); } else { ResultBattle?.Invoke(this, new ResultBattleEventArgs(opponent.Name, opponent.Surname, opponent.CountryFrom, boxer.Name, boxer.Surname, boxer.CountryFrom)); Program.AddPoints(opponent.CountryFrom, 1); } } } } BroadcastingBoxing?.Invoke("Done battles for today\n" + "Now can check Boxing stats to view all battles results for all time"); }
public JsonResult PlayerTurn(int x, int y, int Id) { ApplicationUser user = UserManager.FindByEmail(User.Identity.Name); var result = ""; GameContext Gc = new GameContext(); Unit unit = Gc.Units.Where(a => a.UnitId == Id).FirstOrDefault();// Аттакующий юнит if (user.Email == unit.PlayerId) { if ((unit.turn.Day + 1) < DateTime.Now.Ticks) { int xx = int.Parse(unit.coordinate.Substring(0, 4)) - 1000; int yy = int.Parse(unit.coordinate.Substring(5)) - 1000; if ((Math.Abs(x - xx) < 2) && (Math.Abs(y - yy) < 2)) { Unit u = Gc.Units.Where(a => a.coordinate == "10" + x + "x10" + y).OrderBy(b => b.HP).FirstOrDefault();//Защищающийся юнит string message = ""; if (u == null) { unit.coordinate = "10" + x + "x10" + y; unit.turn = DateTime.Now; Gc.Entry(unit).State = System.Data.Entity.EntityState.Modified; Gc.SaveChanges(); message = user.Land + " произвёл захват области " + unit.coordinate + ", Игрок " + user.Name; Journal ju = new Journal(user.Email, message, false); Gc.Journals.Add(ju); Gc.SaveChanges(); return(Json(unit, JsonRequestBehavior.AllowGet)); } if (u.Land == user.Land) { unit.coordinate = "10" + x + "x10" + y; unit.turn = DateTime.Now; Gc.Entry(unit).State = System.Data.Entity.EntityState.Modified; Gc.SaveChanges(); message = user.Land + " произвёл перемещение в область " + unit.coordinate + ", Игрок " + user.Name; } else { if (unit.Ammunition < 1) { //Необходимо прописать ошибку. Нет патронов. return(Json(unit, JsonRequestBehavior.AllowGet)); } Battle batle = new Battle(unit, u); ResultBattle resultBattle = batle.Battle_Resume(Gc); if (unit.Type == "Artillery") // Если ведём артобстрел { u.HP = u.HP - resultBattle.ResumeAttack; unit.Ammunition = unit.Ammunition - 1; message = user.Land + " произвёл артобстрел области " + unit.coordinate + ", отряд " + u.Class + " игрока " + u.PlayerId + " получил повреждения -" + resultBattle.ResumeAttack + " (" + u.HP + ")"; if (u.HP < 0) { //Прописываем уничтожение отряда Gc.Entry(u).State = System.Data.Entity.EntityState.Deleted; Gc.SaveChanges(); message += message + ", отряд в результате артобстрела был полностью уничтожен."; } } else //Идём в ближний бой { u.HP = u.HP - resultBattle.ResumeAttack; message = user.Land + " произвёл атаку обасти " + unit.coordinate + ", отряд " + u.Class + " игрока " + u.PlayerId + " получил повреждения -" + resultBattle.ResumeAttack + " (" + u.HP + ")"; if (u.Ammunition > 0) { unit.HP = unit.HP - resultBattle.ResumeDefence; u.Ammunition = u.Ammunition - 1; message += message + ", атакующая сторона " + unit.Class + " понесла потери " + resultBattle.ResumeDefence; if (unit.HP < 0) { //Уничтожается атакующий отряд Gc.Entry(unit).State = System.Data.Entity.EntityState.Deleted; } } unit.Ammunition = unit.Ammunition - 1; } unit.turn = DateTime.Now; if (u.HP > 0) { Gc.Entry(u).State = System.Data.Entity.EntityState.Modified; } else { //Прописываем уничтожение отряда Gc.Entry(u).State = System.Data.Entity.EntityState.Deleted; unit.coordinate = "10" + x + "x10" + y; message += message + ", защищающийся отряд в результате атаки был полностью уничтожен."; } if (unit.HP > 0) { Gc.Entry(unit).State = System.Data.Entity.EntityState.Modified; } Gc.SaveChanges(); } Journal j = new Journal(user.Email, message, false); Gc.Journals.Add(j); Gc.SaveChanges(); return(Json(unit, JsonRequestBehavior.AllowGet)); } else { result = "Неверно указаны координаты отряда"; } } else { result = "Прошло меньше суток, данный отряд ещё не может производить действий!"; } } else { result = "Данный отряд не принадлежит этому игроку"; } return(Json(result, JsonRequestBehavior.AllowGet)); }