public void HitBattleshipResultTest() { Battleship battleship = new Battleship(); ShootResult hitResult = battleship.Hit(); Assert.IsTrue(hitResult is HitResult, "The type of Hit is incorrect."); }
public void HitDestroyerResultTest() { Destroyer battleship = new Destroyer(); ShootResult hitResult = battleship.Hit(); Assert.IsTrue(hitResult is HitResult, "The type of Hit is incorrect."); }
public void HitTest() { Water water = new Water(); ShootResult typeOfHit = water.Hit(); Assert.IsTrue(typeOfHit is MissResult, "Hit type is incorrect."); }
private StringBuilder GeneratePoint(Point point, IList <GeneratedShip> generatedShips, IList <Point> shoots) { StringBuilder generatedPoint = new StringBuilder(); ShootResult shootResult = shootChecker.CheckShot(point, generatedShips, shoots); switch (shootResult) { case ShootResult.Hit: generatedPoint.Append(" x |"); break; case ShootResult.HitAndSink: case ShootResult.SinkAllShips: generatedPoint.Append(" X |"); break; case ShootResult.Miss: generatedPoint.Append(" o |"); break; default: generatedPoint.Append(" |"); break; } return(generatedPoint); }
public void HitTwoTimesTheSameFieldTest() { Field field = new Field(new Water()); ShootResult hitType = field.Hit(); hitType = field.Hit(); Assert.IsTrue(hitType is FieldIsHitAlreadyResult, "Type of hit is incorrect."); }
public void Handle(ShootResult shootResult) { if (shootResult is SuccessShootResult successShootResult) { HandleSuccessResult(successShootResult); } else { HandleFaultResult(shootResult as FaultShootResult); } }
private void MarkResultsOnOpponentsBoard(Coordinate coordinate, ShootResult result) { if (result == ShootResult.Missed) { HiddenBoard.MarkMissed(coordinate); } else { HiddenBoard.MarkHit(coordinate); } }
public void CheckShot_WhenMiss_ReturnsMissResult() { Point point = new Point(2, 2); ShootResult result = target.CheckShot(point, generatedShips, new List <Point>() { new Point(2, 2) }); Assert.Equal(ShootResult.Miss, result); }
public void Hit5TimesAndSinksTest() { Battleship battleship = new Battleship(); ShootResult typeOfHit = null; for (int i = 0; i < Battleship.LIFE_OF_BATTLESHIP; i++) { typeOfHit = battleship.Hit(); } Assert.IsTrue(typeOfHit is HitAndSinksResult, "The type of Hit is incorrect."); }
public void Hit5TimesAndSinksTest() { Destroyer battleship = new Destroyer(); ShootResult typeOfHit = null; for (int i = 0; i < Destroyer.LIFE_OF_DESTROYER; i++) { typeOfHit = battleship.Hit(); } Assert.IsTrue(typeOfHit is HitAndSinksResult, "The type of Hit is incorrect."); }
public void CheckShot_WhenHit_ReturnsHitResult() { Point point = new Point(1, 1); ShootResult result = target.CheckShot(point, generatedShips, new List <Point>() { new Point(1, 1) }); Assert.Equal(ShootResult.Hit, result); }
/// <summary> /// Стреляет без промахов и критических ударов по танку противника (игнорируя броню) /// </summary> /// <param name="EnemyTank">Танк противника</param> /// <returns>Результат стрельбы</returns> public ShootResult Shoot(ITank EnemyTank) { ShootResult result = ShootResult.NoRounds; if (RoundsNum > 1) { result = ShootResult.Usual; EnemyTank.Health -= Damage; RoundsNum--; } return(result); }
public void HitTooMuchTimesTest() { Destroyer battleship = new Destroyer(); ShootResult typeOfHit = null; for (int i = 0; i < Destroyer.LIFE_OF_DESTROYER; i++) { battleship.Hit(); } typeOfHit = battleship.Hit(); Assert.IsTrue(typeOfHit is ElementDiedResult, "The type of Hit is incorrect."); }
/// <summary> /// Attack with the pistol /// </summary> /// <param name="targetCords">The position the projectile should go to</param> /// <returns></returns> public override ShootResult Attack(Vector2 targetCords) { ShootResult shootResult = base.Attack(targetCords); if (shootResult == ShootResult.Successfull) { ammo--; cooldown = attackSpeed; //Console.WriteLine($"Shoot pistol: {ammo}"); GameWorld.AddGameObject(new Projectile(this, projectileSpeed, targetCords), GameWorld.ActiveRoom); return(shootResult); } return(shootResult); }
public ShootResult Shoot(int row, int column) { var map = mapRepository.Entity; if (map == null) { throw new MapNotInitializedException(); } ValidateInput(row, column, map); var currentScore = GetScore(); var field = map.Fields[row][column]; if (field.IsShoot) { return(new ShootResult() { LastShootStatus = ShootStatus.AlreadyShoot, Score = currentScore }); } var result = new ShootResult() { Score = currentScore }; field.IsShoot = true; if (field.Ship != null) { field.Ship.Coordinates .FirstOrDefault(coordinate => coordinate.Row == row && coordinate.Column == column) .IsHit = true; currentScore.Hits++; if (field.Ship.IsDestroyed) { result.LastShootStatus = ShootStatus.Destroyed; currentScore.Sinks++; } else { result.LastShootStatus = ShootStatus.Hit; } } else { currentScore.Misses++; result.LastShootStatus = ShootStatus.Missed; } mapRepository.Save(map); scoreRepository.Save(currentScore); return(result); }
public void CheckShot_WhenSinkAllShips_ReturnsSinkAllShipsResult() { Point point = new Point(1, 1); ShootResult result = target.CheckShot(point, generatedShips, new List <Point>() { new Point(0, 0), new Point(0, 1), new Point(1, 0), new Point(1, 1) }); Assert.Equal(ShootResult.SinkAllShips, result); }
public void HitBattleMapTest() { FakeMap map = this.CreateFakeMap(); map.RenderMap(); for (int i = 0; i < map.Fields.GetLength(0); i++) { for (int j = 0; j < map.Fields.GetLength(1); j++) { ShootResult result = map.Hit(i, j); if (result is HitResult == false) { Assert.Fail("Hit on the map is not working correctly"); } } } }
private static void WriteBattleStatusMessage(ShootResult result) { if (result.LastShootStatus == ShootStatus.Destroyed) { Console.WriteLine("Wohoo! You have destroyed a ship!"); } else if (result.LastShootStatus == ShootStatus.AlreadyShoot) { Console.WriteLine("You already shoot this coordinate! Choose something different!"); } else if (result.LastShootStatus == ShootStatus.Hit) { Console.WriteLine("Wohoo! You have hit the target!"); } else if (result.LastShootStatus == ShootStatus.Missed) { Console.WriteLine("Damn! You missed! Try again!"); } }
public void ShootToDeadObjectTest() { FakeMap map = new FakeMap(3, 1, new List <LiveElement>() { new FakeShip() }); map.RenderMap(); Player player = new Player(map); for (int i = 0; i < map.Fields.GetLength(0); i++) { for (int j = 0; j < map.Fields.GetLength(1); j++) { player.Shoot(i, j); } } ShootResult hitType = player.Shoot(0, 0); Assert.IsTrue(hitType is FieldIsHitAlreadyResult, "The Hit type is incorrectly"); }
public void ShootPlayerTest() { FakeMap map = new FakeMap(3, new List <LiveElement>() { new FakeShip(), new FakeShip(), new FakeShip() }); map.RenderMap(); Player player = new Player(map); for (int i = 0; i < map.Fields.GetLength(0); i++) { for (int j = 0; j < map.Fields.GetLength(1); j++) { ShootResult result = player.Shoot(i, j); if (result is HitResult == false) { Assert.Fail("Shoot is not working correctly"); } } } }
public override StringBuilder Process(string enteredData) { StringBuilder output = new StringBuilder(); try { Point shootCoordinates = ParseEnteredDataToPoint(enteredData); Game.Board.Shoots.Add(shootCoordinates); ShootResult shootResult = shootChecker.CheckShot(shootCoordinates, Game.Board.GeneratedShips, Game.Board.Shoots); switch (shootResult) { case ShootResult.Hit: output.AppendLine("You hit"); return(output); case ShootResult.Miss: output.AppendLine("You miss"); return(output); case ShootResult.HitAndSink: output.AppendLine("You hit and sink"); return(output); case ShootResult.SinkAllShips: output.AppendLine("You sink all ships"); Game.TransitionTo(serviceProvider.GetService <EndGameState>()); return(output); } } catch (Exception e) { logger.LogError(e, e.Message); } output.AppendLine("Wrong coordinates. Try again."); return(output); }
/// <summary> /// Стреляет по другому танку (если броня больше урона, то жизни не меняются) /// </summary> /// <param name="EnemyTank">Объект, описывающий танк, в который стреляют</param> /// <returns>Возвращает результат выстрела</returns> public ShootResult Shoot(ITank EnemyTank) { ShootResult result = ShootResult.NoRounds; // Проверяем, есть ли патроны. if (RoundsNum > 0) { result = ShootResult.Usual; double SR = Random.NextDouble(); int DamageInThisShoot = Damage; // Проверяем промах (20%). if (SR <= 0.2) { result = ShootResult.Miss; } // Проверяем критический удар (10%). if (SR >= 0.9) { result = ShootResult.Critical; DamageInThisShoot += (int)Math.Round(0.2 * Damage); } // Если не промах, уменьшаем число жизней. if (result != ShootResult.Miss) { int DamageWithoutArmor = DamageInThisShoot - EnemyTank.Armor; // Если броня больше урона, то урон не наносится, но и здоровье не добавляется. if (DamageWithoutArmor < 0) { DamageWithoutArmor = 0; } EnemyTank.Health -= DamageWithoutArmor; } RoundsNum--; } return(result); }
public void InformAboutShoot(int x, int y, ShootResult result) { if (OnEnemyShoot != null) OnEnemyShoot(x, y, result); }
public void ShowInformationAboutShootResult(ShootResult resuslt) { this.Reuslt = resuslt; }
/// <summary> /// 玉発射 /// </summary> /// <param name="power">0~255</param> /// <returns></returns> public ShootResult Shoot(int power) { var yaku = Yaku.Hazure; // powerと機械の状態から、yakuとrouteを決定する var route = routeDeterminer.GetRoute(roundMachine, power); if( route==Route.Chacker7 || route==Route.Chacker ) { yaku = mainLogic.Chusen(kakuhenMachine.Mode, setting); //デバッグ用 大当たり固定 //yaku = Yaku.Atari; } var payout = payoutTable.Where(pt=>pt.route== route) .FirstOrDefault() .payout; var result = new ShootResult() { yaku = yaku, route = route, payout = payout, }; return result; }
/// <summary> /// 進捗させる /// </summary> public ShootResult Progress() { var yaku = Yaku.Hazure; var route = Route.Nothing; var payout = 0; var result = new ShootResult() { yaku = yaku, route = route, payout = payout, }; // 状態遷移する roundMachine.Progress(kakuhenMachine); return result; }
public void HandleShootResult(ShootResult shootResult) { ShootResultHandler.Handle(shootResult); }
public void ShowInformationAboutShootResult(ShootResult resuslt) { this.labelInformation.Text = resuslt.Information; }
private void InformAboutShoot(Player player, int x, int y, ShootResult result) { T("Informing {0} about enemy shoot {1} {2} {3}", player.Name, x, y, result); ThreadStart action = () => { Thread.Sleep(250); player.CallBack.InformAboutShoot(x, y, result); }; new Thread(action).Start(); }