Exemplo n.º 1
0
        public void HitBattleshipResultTest()
        {
            Battleship  battleship = new Battleship();
            ShootResult hitResult  = battleship.Hit();

            Assert.IsTrue(hitResult is HitResult, "The type of Hit is incorrect.");
        }
Exemplo n.º 2
0
        public void HitDestroyerResultTest()
        {
            Destroyer   battleship = new Destroyer();
            ShootResult hitResult  = battleship.Hit();

            Assert.IsTrue(hitResult is HitResult, "The type of Hit is incorrect.");
        }
Exemplo n.º 3
0
        public void HitTest()
        {
            Water       water     = new Water();
            ShootResult typeOfHit = water.Hit();

            Assert.IsTrue(typeOfHit is MissResult, "Hit type is incorrect.");
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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.");
        }
Exemplo n.º 6
0
 public void Handle(ShootResult shootResult)
 {
     if (shootResult is SuccessShootResult successShootResult)
     {
         HandleSuccessResult(successShootResult);
     }
     else
     {
         HandleFaultResult(shootResult as FaultShootResult);
     }
 }
Exemplo n.º 7
0
 private void MarkResultsOnOpponentsBoard(Coordinate coordinate, ShootResult result)
 {
     if (result == ShootResult.Missed)
     {
         HiddenBoard.MarkMissed(coordinate);
     }
     else
     {
         HiddenBoard.MarkHit(coordinate);
     }
 }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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.");
        }
Exemplo n.º 10
0
        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.");
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        /// <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);
        }
Exemplo n.º 13
0
        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.");
        }
Exemplo n.º 14
0
        /// <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);
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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!");
     }
 }
Exemplo n.º 19
0
        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");
        }
Exemplo n.º 20
0
        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");
                    }
                }
            }
        }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
        /// <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);
        }
Exemplo n.º 23
0
 public void InformAboutShoot(int x, int y, ShootResult result)
 {
     if (OnEnemyShoot != null)
         OnEnemyShoot(x, y, result);
 }
Exemplo n.º 24
0
 public void ShowInformationAboutShootResult(ShootResult resuslt)
 {
     this.Reuslt = resuslt;
 }
Exemplo n.º 25
0
        /// <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;
        }
Exemplo n.º 26
0
        /// <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;
        }
Exemplo n.º 27
0
 public void HandleShootResult(ShootResult shootResult)
 {
     ShootResultHandler.Handle(shootResult);
 }
Exemplo n.º 28
0
 public void ShowInformationAboutShootResult(ShootResult resuslt)
 {
     this.labelInformation.Text = resuslt.Information;
 }
Exemplo n.º 29
0
        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();
        }