Exemple #1
0
        public void AxeLosesDurabilityAfterAttack()
        {
            var durability = axe.DurabilityPoints;

            axe.Attack(dummy);
            Assert.That(axe.DurabilityPoints, Is.LessThan(durability), "Axe Durability doesn't change after attack.");
        }
Exemple #2
0
    public void BrokenWeaponCannotAttack()
    {
        //Act
        weapon.Attack(dummy);

        //Assert
        Assert.That(() => weapon.Attack(dummy), Throws.InvalidOperationException.With.Message.EqualTo("Axe is broken."));
    }
Exemple #3
0
        public void DummyLosesHealthWhenAttacked()
        {
            var initialDummyHealth = this.dummy.Health;

            axe.Attack(dummy);

            var currentDummyHealth = this.dummy.Health;

            Assert.That(currentDummyHealth, Is.LessThan(initialDummyHealth));
        }
Exemple #4
0
 public void Weapon_OnUse()
 {
     if (this.IsInMeleeRange(currentTarget))
     {
         aWeapon.Attack();
         return;
     }
     var w = aWeapon as IRangedWeapon;
      
     if (w != null && w.IsInRange(currentTarget)
     {
         aWeapon.Attack();
         return;
     }
     context.HUD.Warn("Out of range");
 }
        public void AttackWithBrokenAxe()
        {
            this.axe.Attack(this.dummy);
            this.axe.Attack(this.dummy);

            Assert.That(() => axe.Attack(this.dummy), Throws.Exception.With.Message.EqualTo("Axe is broken."));
        }
Exemple #6
0
    private void Update()
    {
        //AI logic
        Transform target = destinationSetter.target;

        if (target != null)
        {
            if (Utils.Ai.isInRange(gameObject, target.gameObject, creatureAIProperties.attackRange) &&
                Utils.Ai.isTargetVisible(gameObject, target.gameObject))
            {
                //Attack
                if (weapon != null)
                {
                    weapon.Attack(target.position);
                }
            }
        }
        else
        {
            if (creatureAIProperties.moveAroundRandomly)
            {
                if (Vector2.Distance(transform.position, moveAroundTargetPoint) > 0.5 &&
                    moveAroundTargetPoint != Vector2.zero)
                {
                    rb.AddForce((moveAroundTargetPoint - (Vector2)transform.position).normalized
                                * movementSpeed * 50);
                }
                else
                {
                    setMoveAroundTargetPoint();
                }
            }
        }
    }
Exemple #7
0
    void Update()
    {
        float distanceToPlayer = (transform.position - GameManager.Instance.Player.transform.position).magnitude;

        if (distanceToPlayer >= MinFollowDistance)
        {
            policeScript.MovingState = MovingState.Walking;
            rb2d.velocity            = (GameManager.Instance.Player.transform.position - transform.position).normalized * policeScript.GetSpeed();
        }
        else
        {
            policeScript.MovingState = MovingState.Standing;
            rb2d.velocity            = Vector2.zero;
        }

        if (distanceToPlayer >= MaxDistance)
        {
            policeScript.ChangeState(PoliceState.Passive);
        }

        if (attackTimer >= 0.5f && distanceToPlayer <= MinShootDistance)
        {
            attackTimer = 0f;
            weapon.Attack();
        }
        attackTimer += Time.deltaTime;

        HandleLookAt();
    }
    private void HandleInput()
    {
        if (weapon != null)
        {
            bool attack;
            if (weapon.automatic)
            {
                attack = Input.GetKey("Attack");
            }
            else
            {
                attack = Input.GetKeyDown("Attack");
            }
            bool throwWeapon = Input.GetKeyDown("Throw");

            if (attack)
            {
                weapon.Attack();
            }
            if (throwWeapon)
            {
                Throw(-transform.up * 1000);
            }
        }
    }
Exemple #9
0
    public void AxeLosesDurabilityAfterAttack()
    {
        //Act
        axe.Attack(this.dummy);

        //Assert
        Assert.AreEqual(9, this.axe.DurabilityPoints, "Axe Durability doesn't change after attack");
    }
Exemple #10
0
 void Update()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         weapon.Attack(lookDirection);
         ammoText.text = "Ammo: " + weapon.GetAmmo().ToString();
     }
 }
Exemple #11
0
 void FixedUpdate()
 {
     if (gameControleler.isPlayerAlive)
     {
         currentWeapon.Attack();
         ChangeWeapon();
     }
 }
    public void AttackShouldThrowExceptionWhenAttackingWithZeroOrNegativeDurabilityPoints
        (int attack, int durability)
    {
        weapon = new Axe(attack, durability);

        Mock <ITarget> target = new Mock <ITarget>();

        Assert.Throws <InvalidOperationException>(() => weapon.Attack(target.Object));
    }
Exemple #13
0
 void Update()
 {
     if (Input.GetButtonDown("Fire1") && !Inventory.isInventoryOpened)
     {
         if (_currentWeapon != null)
         {
             _currentWeapon.Attack();
         }
     }
 }
    public void DurabilityPiontsShouldDecreasewhenAttacking(int attack, int durability)
    {
        weapon = new Axe(attack, durability);

        Mock <ITarget> target = new Mock <ITarget>();

        weapon.Attack(target.Object);

        Assert.AreEqual(9, weapon.DurabilityPoints);
    }
Exemple #15
0
 public void Attack()
 {
     if (Weapon != null)
     {
         Weapon.Attack(FirePoint, projectilePreFab);
     }
     else
     {
         // TODO: Normal attacks
     }
 }
Exemple #16
0
 public void PerformAttack()
 {
     if (equippedIWeapon != null)
     {
         equippedIWeapon.Attack();
     }
     else
     {
         Debug.Log("equippedIWeapon == NULL");
     }
 }
Exemple #17
0
 public void Attack()
 {
     if (iWeapon == null)
     {
         Console.WriteLine("default attack..");
     }
     else
     {
         iWeapon.Attack();
     }
 }
        public void Attack()
        {
            // if our weapon slot really is a weapon, use it to attack
            // we're using casting here which is a bit messy, but makes for an easy example
            // we have to cast because we know WeaponSlot is IEquippable, but we don't know if it's an IWeapon yet
            IWeapon weaponToUse = _stats.WeaponSlot as IWeapon;

            if (weaponToUse != null)
            {
                weaponToUse.Attack();
            }
        }
        public void AxeLosesDurabilyAfterAttack()
        {
            //Arrange
            this.axe   = new Axe(AxeAttackPoints, DurabilityPoints);
            this.dummy = new Dummy(DummyHealth, DummyExperience);

            //Act
            axe.Attack(dummy);

            //Assert
            Assert.AreEqual(9, axe.DurabilityPoints, "Axe Durability doesn't change after attack");
        }
Exemple #20
0
        protected IEnumerator ImplAttack(IWeapon weapon)
        {
            actor.OnActionBegin(Actions.Attack);
            SmartCoroutine weaponAttack = SmartCoroutine.Create(weapon.Attack());

            yield return(weaponAttack);

            actor.OnActionEnd(Actions.Attack);
            if (weaponAttack.Status == SmartCoroutine.Result.WasExited)
            {
                yield return(SmartCoroutine.Exit);
            }
        }
Exemple #21
0
    public void CannotAttackWithBrokenWeapon()
    {
        this.axeDamage     = 5;
        this.axeDurability = 0;

        this.dummyHp  = 10;
        this.dummyExp = 20;

        this.axe   = new Axe(axeDamage, axeDurability);
        this.dummy = new Dummy(dummyHp, dummyExp);

        Assert.That(() => axe.Attack(dummy), Throws.InvalidOperationException.With.Message.EqualTo("Axe is broken."));
    }
Exemple #22
0
    public void Attack()
    {
        if (EquippedWeapon == null)
        {
            throw new System.NotImplementedException();
        }

        EquippedWeapon.Attack();
        //var mGo = GameObject.Find("Monstruo");
        //if (mGo != null)
        //{
        //    var m = mGo.GetComponent<Monster>();
        //    m.Matar();
        //}
    }
        static void Main(string[] args)
        {
            var enemy = new Enemy();

            PoisonedSword poisonedSword = new PoisonedSword();

            poisonedSword.Attack(enemy); // will execute PoisonedSword.Attack

            Sword sword = poisonedSword;

            sword.Attack(enemy); // will still execute PoisonedSword.Attack

            IWeapon weapon = poisonedSword;

            weapon.Attack(enemy); // will still execute PoisonedSword.Attack
        }
Exemple #24
0
    public void AxeLosesDurability()
    {
        this.axeDamage     = 5;
        this.axeDurability = 10;

        this.dummyHp  = 10;
        this.dummyExp = 20;

        this.axe   = new Axe(axeDamage, axeDurability);
        this.dummy = new Dummy(dummyHp, dummyExp);

        axe.Attack(dummy);

        int expectedDurability = 9;

        Assert.That(axe.DurabilityPoints, Is.EqualTo(expectedDurability));
    }
Exemple #25
0
    // Update is called once per frame
    void Update()
    {
        Vector2 movementDirection = GetMovementDirection();

        _body.MovePosition(transform.position + movementDirection.ToVector3() * Speed);
        var characterOrientation = GetCharacterOrientation();

        UpdateAnimation(characterOrientation);

        //Stop animation if player is not moving
        _animator.speed = movementDirection == Vector2.zero ? 0 : 0.1f;

        int leftClickMouseButton = 0;

        if (Input.GetMouseButtonDown(leftClickMouseButton))
        {
            _weapon.Attack(characterOrientation);
        }
    }
Exemple #26
0
 void Update()
 {
     playerMovement();
     setHeroSpriteDirection();
     if (Input.GetKeyDown(KeyCode.Space))
     {
         // Vector2 target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         // rb.velocity = Vector2.zero;
         // Vector2 dashDirection = (target - (Vector2)transform.position).normalized;
         Vector2 dashDirection = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).normalized;
         rb.AddForce(dashDirection * dashSpeed * 100);
         isDashing = true;
     }
     if (weapon != null)
     {
         if (Input.GetKey(KeyCode.Mouse0))
         {
             weapon.Attack(Camera.main.ScreenToWorldPoint(Input.mousePosition));
         }
     }
 }
Exemple #27
0
 private void Update()
 {
     if (OnClick)
     {
         if (ShootTimer <= 0)
         {
             if (_playerWeapon != null)
             {
                 _playerWeapon.Attack();
                 _playerWeapons.SetBulletText();
                 ShootTimer = _playerWeapon.GetAttackSpeed();
             }
             else
             {
                 _playerWeapons.SetBulletText(null);
             }
         }
         if (ShootTimer > 0)
         {
             ShootTimer -= Time.deltaTime;
         }
     }
 }
Exemple #28
0
 public void Hit()
 {
     _weapon.Attack();
 }
Exemple #29
0
 public int Attack(IWarrior target, IWeapon weapon)
 {
     return weapon.Attack(target);
 }
Exemple #30
0
 public void Attack(int x, int y)
 {
     myWeapon.Attack(this, x, y);
 }
    public void InputLoop()
    {
        while (true)
        {
            currentRoom.PrintRoom();
            string input = Console.ReadLine();
            if (input == "quit")
            {
                break;
            }

            if (input.StartsWith("pick up "))
            {
                string item = input.Split("up ")[1];
                if (currentRoom.Items.Exists(x => x.Name == item))
                {
                    Item PUitem = currentRoom.Items.Find(x => x.Name.Contains(item));
                    backpack.Items.Add(PUitem);
                    currentRoom.Items.Remove(PUitem);
                    scoreboard.Score += PUitem.PointValue;
                }
                else
                {
                    Console.WriteLine("The item you tried to pick up does not exist. Try again.");
                }
            }

            if (input.StartsWith("attack"))
            {
                var regex = new Regex(@"attack ([\w\s]+) with ([\w\s]+)", RegexOptions.IgnoreCase);
                var match = regex.Match(input);
                if (match.Success)
                {
                    string attackableName = match.Groups[1].Value;
                    string weaponName     = match.Groups[2].Value;

                    // find matching weapon
                    // null if weapon is not an IWeapon
                    // null if attackable is not an IAttackable
                    IWeapon     weapon     = FindWeapon(weaponName);
                    IAttackable attackable = FindAttackable(attackableName);

                    if (weapon != null && attackable != null)
                    {
                        if (attackable is Harpsichord)
                        {
                            // gold is added to Item list in Room
                            currentRoom.Items.Add(new Item {
                                Name = "gold", Description = "Shiny gold coins.", PointValue = 100
                            });
                            // harpsichord is removed from Item list in Room
                            currentRoom.Items.Remove(attackable as Harpsichord);
                        }
                        //IsDestroyed for object becomes true
                        weapon.Attack(attackable);
                    }
                }
            }

            else if (input.StartsWith("drop "))
            {
                string item = input.Split("drop ")[1];
                if (backpack.Items.Exists(x => x.Name == item))
                {
                    Item Ditem = backpack.Items.Find(x => x.Name.Contains(item));
                    backpack.Items.Remove(Ditem);
                    currentRoom.Items.Add(Ditem);
                    scoreboard.Score -= Ditem.PointValue;
                }
                else
                {
                    Console.WriteLine("The item you tried to drop does not exist. Try again.");
                }
                continue;
            }

            else if (input.StartsWith("describe "))
            {
                string item = input.Split("describe ")[1];
                if (currentRoom.Items.Exists(x => x.Name == item))
                {
                    Console.WriteLine(currentRoom.Items.Find(x => x.Name == item));
                }
                else if (backpack.Items.Exists(x => x.Name == item))
                {
                    Console.WriteLine(backpack.Items.Find(x => x.Name == item));
                }
                else
                {
                    Console.WriteLine("The item is not available.");
                }
                continue;
            }

            // TryGetValue gets the value associated with the specified key.
            if (currentRoom.Transitions.TryGetValue(input, out Room nextRoom))
            {
                if (currentRoom.Enemies.Exists(enemy => (enemy.IsDestroyed == false)))
                {
                    scoreboard.Score = 0;
                    break;
                }
                else
                {
                    currentRoom = nextRoom;
                    counter++;

                    // if counter has an even number (counter is even every other time a player switches rooms)
                    // & if enemy is still alive
                    if (counter % 2 == 0 && enemyRoom.Enemies.Exists(enemy => enemy.IsDestroyed == false))
                    {
                        Enemy enemy = enemyRoom.Enemies.Find(enemy => enemy.IsDestroyed == false);
                        enemyRoom.Enemies.Remove(enemy);

                        Room newEnemyRoom = enemy.SwitchRoom(enemyRoom);

                        enemyRoom = newEnemyRoom;
                        enemyRoom.Enemies.Add(enemy);
                    }
                }
            }

            if (currentRoom.FinalRoom)
            {
                currentRoom.PrintRoom();
                break;
            }
        }
    }