Beispiel #1
0
        public async Task ShouldAttack_Return_Battle_Result_When_Given_Valid_Coordinates_Successfully()
        {
            var battle = await _battleService.InitiateBattle(10, 2, 3);

            var battleId = battle.Id.ToString();

            var shipCoordinate = new Coordinate(0, 0);

            await _battleService.AddShip(battleId, shipCoordinate,
                                         ShipDirection.Horizontal);

            await _battleService.AddShip(battleId, new Coordinate(1, 0),
                                         ShipDirection.Horizontal);

            var result = await _battleService.Attack(battleId, shipCoordinate);

            Assert.Equal(GridCellStatus.Hit, result.AttackedCellStatus);
            Assert.Equal(BattleStatus.InPlay, result.Status);
            Assert.False(result.AllShipsSunk);
        }
        public void ShouldAttack_Return_Battle_Result_When_Given_Valid_Coordinates_Successfully()
        {
            //Arrange
            var battle = _battleService.InitiateBattle(10, 2, 3);

            var battleId = battle.Id.ToString();

            var shipCoordinate = new Coordinate(0, 0);

            _battleService.AddShip(battleId, shipCoordinate,
                                   ShipDirection.Horizontal, ShipType.BattleShip);
            _battleService.AddShip(battleId, new Coordinate(1, 0),
                                   ShipDirection.Horizontal, ShipType.DestroyerShip);

            //Act
            var result = _battleService.Attack(battleId, shipCoordinate);

            //Assert
            Assert.Equal(Occupation.Hit, result.AttackedCellStatus);
            Assert.Equal(BattleStatus.InPlay, result.Status);
            Assert.False(result.AllShipsSunk);
        }
Beispiel #3
0
    private IEnumerator HeroAttack()
    {
        // definir inimigo
        var index = SelectedEnemyIndex;
        var enemy = _enemies[index];

        // executar regra pré ataque
        ExecuteRule(RuleType.BeforeHeroAttack);

        // definir quem ataca
        var heroes = _heroes.FindAll(h => h.IsPresent);
        var hero   = heroes[_currentHeroIndex];

        // atacar
        var previousHp = enemy.currentHp;

        BattleService.Attack(hero, enemy);

        var currentHp = enemy.currentHp;

        // verificar se causou dano
        var enemyDisplay = EnemyDisplay.Get(_enemies.Count - 1);
        var tagName      = enemyDisplay.ContainerNames[index] + "_" + _enemies.Count;

        var attackValue = previousHp - currentHp;

        if (_strongestAttack < attackValue)
        {
            _strongestAttack = attackValue;
            HeroWhoGaveTheStrongestAttack = hero;
        }

        if (previousHp != currentHp)
        {
            for (var i = 0; i < 5; i++)
            {
                yield return(new WaitForSeconds(0.1f));

                SetColorToGameObject(Color.red, tagName);

                yield return(new WaitForSeconds(0.1f));

                SetColorToGameObject(Color.white, tagName);
            }
        }

        // alterar status da vida
        if (currentHp <= 0)
        {
            enemy.isPresent = false;

            SetColorToGameObject(Color.black, tagName);
        }

        // verificar se existem inimigos vivos
        var thereAreEnemiesAlive = _enemies.Any(e => e.isPresent);

        if (!thereAreEnemiesAlive)
        {
            //TODO: Verificar se toda a equipe ganha xp, mesmo se tiver morrido.
            HeroBattleCalculator.CalculateTheExperienceGained(heroes, _enemies);


            SkillsViewerService.GetInstance().Heroes = _heroes.ConvertAll(h => h.Name).ToArray();
            SceneManager.LoadScene(_currentBattle.whereToGoWhenTheBattleIsOver);
        }

        // executar regra pos ataque
        ExecuteRule(RuleType.AfterHeroAttack);

        var count = heroes.FindAll(h => h.IsPresent).Count;

        // se Existir aliados continuar ataque
        if (_currentHeroIndex + 1 < count)
        {
            _currentHeroIndex++;
            DrawAttackMenu();
            yield break;
        }

        // ir para a próxima fase da batalha
        _currentHeroIndex = 0;
        DrawDefenseMenu();
    }
Beispiel #4
0
        public void AssertThatAttackerCanHurtDefender()
        {
            var isHit = service.Attack(5, 4);

            Assert.True(isHit);
        }