public override void AfterShoot(HitType shoot) { if (shoot.Equals(HitType.Kill)) { Bot.State = new NotHitState(); Bot.LastHits.Add(Bot.LastPoint); Bot.MissedAroundKilled(); Bot.LastHits.Clear(); } else if (shoot.Equals(HitType.Hit)) { Bot.LastHits.Add(Bot.LastPoint); } }
public HitType Shoot(Point p) { if (p.X < 0 || p.X >= BoardSize || p.Y < 0 || p.Y >= BoardSize) { throw new ArgumentOutOfRangeException($"Точка должна быть в пределах доски {BoardSize}x{BoardSize}"); } if (!Board[p.X, p.Y].Equals(CellState.Unknown)) { throw new ArgumentException("Вы уже стреляли в эту точку"); } HitType shoot = Opponent.GetShootIn(p); Board[p.X, p.Y] = shoot.Equals(HitType.Miss) ? CellState.Missed : CellState.Hit; if (shoot == HitType.Kill) { LastHits.Add(p); MissedAroundKilled(); LastHits.Clear(); } else if (shoot == HitType.Hit) { LastHits.Add(p); } LastPoint = p; return(shoot); }
public void HumanShoot(Human human, Player bot) { bool success = false; do { try { do { GUI.PrintYourTurn(); toShoot = GUI.GetCoords(false); shoot = human.Shoot(toShoot); GUI.PrintBoards(human, bot); GUI.PrintShoot(toShoot, shoot, human.Name); GUI.PrintStats(human, bot); } while (!shoot.Equals(HitType.Miss) && bot.Fleet.IsAlive()); success = true; Thread.Sleep(1500); } catch (Exception ex) { GUI.PrintException(ex.Message, 25); } } while (!success); }
public void BotShoot(Bot bot, Human human) { do { shoot = bot.Shoot(); GUI.PrintBoards(human, bot); GUI.PrintShoot(bot.LastPoint, shoot, bot.Name); GUI.PrintStats(human, bot); Thread.Sleep(1500); } while (!shoot.Equals(HitType.Miss) && human.Fleet.IsAlive()); }
public HitType Shoot() { try { Point p = State.ChooseCell(); HitType shoot = bot.Opponent.GetShootIn(p); bot.Board[p.X, p.Y] = shoot.Equals(HitType.Miss) ? CellState.Missed : CellState.Hit; bot.LastPoint = p; State.AfterShoot(shoot); return(shoot); } catch (Exception ex) { throw new Exception(ex.Message, ex); } }