Example #1
0
    public void EnemyInRange(GameObject unitGo = null)
    {
        if (unitGo == null)
        {
            return;
        }

        var unit = unitGo.GetComponent <Unit>();

        if (unit.Stats.IsDead)
        {
            return;
        }
        _targetEnemyIndex = unit._unit.Index;
        _targetEnemyTeam  = unit.Intell.IAm;

        //Debug.Log(gameObject.name + ": enemy (" + TargetEnemy.gameObject.name + ") is in range.");

        _moveController.StopMoving(false);
        _unit.Attack();

        FightUtils.FaceEnemy(unitGo.transform.position, transform, onlyY: false);

        Intell.AtackSensor.gameObject.SetActive(false);
    }
Example #2
0
 public void ShowTargetBox(Label box, IUnit enemy)
 {
     box.Show();
     box.Text = "\nAttack: " + enemy.Attack()
                + "\nDefense: " + enemy.Defend()
                + "\nHitpoints: " + enemy.CurrentHitPoints;
 }
Example #3
0
        void Start()
        {
            CLandUnitCreator landUnitCreator = new CLandUnitCreator();
            IUnit            soldier         = landUnitCreator.CreateUnit(EUnitType.Soldier);

            soldier.Name = "瑞恩";
            soldier.Move(100, 100);
            soldier.Attack(150, 150);
        }
Example #4
0
        public void TestAttackAndGetDamage()
        {
            /*Unit 1 attack Unit 2, Unit 2 health should be equal to his max health - the Unit 1 damage. */
            unit1.Attack(unit2);
            Assert.AreEqual(UnitConstants.SpearmenHealth - UnitConstants.SwordsmenDamage, unit2.Hp);

            /*Unit 3 take damage equal to his mx health, Unit 3 should be dead. */
            unit3.Damage(UnitConstants.ArcherHealth);
            Assert.IsFalse(unit3.IsAlive());
        }
        static void Main(string[] args)
        {
            //Unit ua = new Unit {Name = "Mark", WeaponName = "gun", BehaviorName = "soldier"};
            //ua.Move(1, 1);
            //ua.Attack(2,2);
            //Console.WriteLine("Mark changes weapon.");
            //ua.WeaponName = "Cannon";
            //ua.Attack(2,2);

            LandUnitCreator landUnitCreator = new LandUnitCreator();
            IUnit           soldier1        = landUnitCreator.CreateUnit(UnitType.Soldier);

            soldier1.Name = "Mark";
            soldier1.Move(1, 1);
            soldier1.Attack(2, 2);
        }
Example #6
0
        public int SingleAttack(List <IUnit> A, List <IUnit> B)
        {
            IUnit AUnit = Picker.AttackerAvailable(A);
            IUnit BUnit = Picker.UnitAlive(B);

            if (AUnit == null && BUnit != null)
            {
                return(1);                                // A not available or dead
            }
            if (BUnit == null && AUnit != null)
            {
                return(2);                                // B dead
            }
            if (BUnit == null && AUnit == null)
            {
                return(3);                                // A notavailable B dead
            }
            AUnit.Attack(BUnit);
            Debug.Log(AUnit + " attacked " + BUnit);

            tileController.addCoroutine(AUnit.AttackCoroutine(BUnit.UnitController.unit, BUnit.Alive));

            return(0); //attack completed
        }
Example #7
0
        public void Attack(IUnit attacker, IUnit target)
        {
            int damage = attacker.Attack() - target.Defend();

            if (damage > 0)
            {
                target.CurrentHitPoints -= damage;
                if (this.IsPlayerTurn)
                {
                    GameEngine.BattleScreen.ShowDamageBox(-damage, Color.Red, this.CurrentTarget.PicBox);
                }
                else
                {
                    GameEngine.BattleScreen.ShowDamageBox(-damage, Color.Red, GameEngine.BattleScreen.characterPicture);
                }
            }

            if (target.CurrentHitPoints <= 0)
            {
                if (this.IsPlayerTurn)
                {
                    this.EnemyList[this.CurrentTargetId].PicBox.Hide();
                    this.EnemyList[this.CurrentTargetId].IsAlive = false;
                    GameEngine.PlayerCharacter.Experience += this.EnemyList[this.CurrentTargetId].Experience;

                    if (GameEngine.PlayerCharacter.Experience >= GameEngine.BattleScreen.experienceBar.Maximum)
                    {
                        GameEngine.PlayerCharacter.Level++;
                        GameEngine.PlayerCharacter.Strength++;
                        GameEngine.PlayerCharacter.Intelligence++;
                        GameEngine.PlayerCharacter.Dexterity++;
                        GameEngine.PlayerCharacter.Vitality++;
                        GameEngine.BattleScreen.experienceBar.Maximum = GameEngine.PlayerCharacter.CalculateExperience(GameEngine.PlayerCharacter.Level);
                        GameEngine.PlayerCharacter.CalculateHitPoints();
                        GameEngine.PlayerCharacter.Experience = 0;
                        GameEngine.BattleScreen.experienceBar.Value = 0;
                    }
                    else
                    {
                        GameEngine.BattleScreen.experienceBar.Value = GameEngine.PlayerCharacter.Experience;
                    }

                    bool aliveEnemies = false;

                    foreach(IEnemy enemy in this.EnemyList) {
                        if (enemy.IsAlive)
                        {
                            aliveEnemies = true;
                            break;
                        }
                    }

                    if (aliveEnemies == false)
                    {
                        MessageBox.Show("YOU ARE VICTORIOUS!");
                        GameEngine.BattleScreen.Close();
                        GameEngine.Map.Show();
                        Sound.Sound.PlayMapSound();
                    }
                }
                else
                {
                    throw new EndBattleException();
                }
            }
        }
Example #8
0
 public void ShowTargetBox(Label box, IUnit enemy)
 {
     box.Show();
     box.Text = "\nAttack: " + enemy.Attack()
                 + "\nDefense: " + enemy.Defend()
                 + "\nHitpoints: " + enemy.CurrentHitPoints;
 }
Example #9
0
        public void Attack(IUnit attacker, IUnit target)
        {
            int damage = attacker.Attack() - target.Defend();

            if (damage > 0)
            {
                target.CurrentHitPoints -= damage;
                if (this.IsPlayerTurn)
                {
                    GameEngine.BattleScreen.ShowDamageBox(-damage, Color.Red, this.CurrentTarget.PicBox);
                }
                else
                {
                    GameEngine.BattleScreen.ShowDamageBox(-damage, Color.Red, GameEngine.BattleScreen.characterPicture);
                }
            }

            if (target.CurrentHitPoints <= 0)
            {
                if (this.IsPlayerTurn)
                {
                    this.EnemyList[this.CurrentTargetId].PicBox.Hide();
                    this.EnemyList[this.CurrentTargetId].IsAlive = false;
                    GameEngine.PlayerCharacter.Experience       += this.EnemyList[this.CurrentTargetId].Experience;

                    if (GameEngine.PlayerCharacter.Experience >= GameEngine.BattleScreen.experienceBar.Maximum)
                    {
                        GameEngine.PlayerCharacter.Level++;
                        GameEngine.PlayerCharacter.Strength++;
                        GameEngine.PlayerCharacter.Intelligence++;
                        GameEngine.PlayerCharacter.Dexterity++;
                        GameEngine.PlayerCharacter.Vitality++;
                        GameEngine.BattleScreen.experienceBar.Maximum = GameEngine.PlayerCharacter.CalculateExperience(GameEngine.PlayerCharacter.Level);
                        GameEngine.PlayerCharacter.CalculateHitPoints();
                        GameEngine.PlayerCharacter.Experience       = 0;
                        GameEngine.BattleScreen.experienceBar.Value = 0;
                    }
                    else
                    {
                        GameEngine.BattleScreen.experienceBar.Value = GameEngine.PlayerCharacter.Experience;
                    }

                    bool aliveEnemies = false;

                    foreach (IEnemy enemy in this.EnemyList)
                    {
                        if (enemy.IsAlive)
                        {
                            aliveEnemies = true;
                            break;
                        }
                    }

                    if (aliveEnemies == false)
                    {
                        MessageBox.Show("YOU ARE VICTORIOUS!");
                        GameEngine.BattleScreen.Close();
                        GameEngine.Map.Show();
                        Sound.Sound.PlayMapSound();
                    }
                }
                else
                {
                    throw new EndBattleException();
                }
            }
        }