Пример #1
0
 public int DistanceTo(Abstraceunit another, bool isMovement)
 {
     if (isMovement)
     {
         return(Math.Abs(GetPosition.X - another.GetPosition.X) + Math.Abs(GetPosition.Y - another.GetPosition.Y));
     }
     return(Math.Max(Math.Abs(GetPosition.X - another.GetPosition.X), Math.Abs(GetPosition.Y - another.GetPosition.Y)));
 }
Пример #2
0
 public void Attack(Abstraceunit who)
 {
     this.OnAttacking(who);
     LOGS.Add(String.Format("{0} attacks {1}", this.NameFull, who.NameFull));
     who.OnAttacked(this);
     who.DamageFor(this.CurrentDamage);
     if (!who.isDead)
     {
         who.AfterAttacked(this);
     }
 }
Пример #3
0
        public void SORTUNITS(bool FromMinToMax)
        {
            List <Abstraceunit> want = _units;

            for (int i = 0; i < want.Count; i++)
            {
                int          needInd = i, lowestMVP = want[i].CurrentMVP;
                Abstraceunit chosen = want[i];

                for (int j = i + 1; j < want.Count; j++)
                {
                    if ((lowestMVP > want[j].CurrentMVP && FromMinToMax) ||
                        (lowestMVP < want[j].CurrentMVP && !FromMinToMax))
                    {
                        needInd = j; chosen = want[j]; lowestMVP = want[j].CurrentMVP;
                    }
                }

                Abstraceunit temp = want[i];
                want[i]       = want[needInd];
                want[needInd] = temp;
            }
            _units = want;
        }
Пример #4
0
        public void CalculateMovementForEachCharacter()
        {
            List <Point> currentUnitPoses = new List <Point>();

            for (int i = 0; i < _units.Count; i++)
            {
                currentUnitPoses.Add(_units[i].GetPosition);
            }


            SORTUNITS(true);
            for (int i = 0; i < _units.Count; i++)
            {
                Abstraceunit unit      = _units[i];
                List <Point> unitCanGo = Calculator.deleteListFromList(Calculator.GetOblast(currentUnitPoses[i], unit.GetSpd, false, true), currentUnitPoses.ToArray());
                unitCanGo.Add(_units[i].GetPosition);
                if (unitCanGo.Count == 0)
                {
                    continue;
                }
                List <Prio> unitThinks = unit.CalculateSituation(this);
                Point       decided    = Calculator.CalculateMovement(unitCanGo, unitThinks);
                currentUnitPoses[i] = decided;
                _units[i].MoveTo(decided);
            }


            for (int i = 0; i < _units.Count; i++)
            {
                try
                {
                    // attack
                    for (int att = 0; att < _units[i].CurrentATP; att++)
                    {
                        if (i == _units.Count - 1)
                        {
                            Console.WriteLine(_units[i].NameFull);
                        }
                        Abstraceunit decideAttack = _units[i].CalculateAttack(getEnemyesInObl(_units[i].GetPosition, _units[i].CurrentAttackRange, true, _units[i].getTeamNumber));
                        if (decideAttack != null)
                        {
                            _units[i].Attack(decideAttack);
                            if (decideAttack.isDead)
                            {
                                _units.Remove(decideAttack);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    LOGS.Add("Unit can't do anything - he is dead. (" + e.Message + ")");
                }
            }
            // end turn
            for (int i = 0; i < _units.Count; i++)
            {
                _units[i].OnTurnEnd();
            }

            Console.Clear();
            List <MapPicture> mp = new List <MapPicture>();

            for (int i = 0; i < _units.Count; i++)
            {
                mp.Add(new MapPicture(_units[i].GetType().Name.ToString()[1], (_units[i].getTeamNumber == 0) ? ConsoleColor.Red : ConsoleColor.Green, _units[i].GetPosition));
            }

            Calculator.TraceBattlefieldToConsole(mp);
        }
Пример #5
0
 public void addUnit(Abstraceunit newUnit)
 {
     _units.Add(newUnit); LOGS.Add(String.Format("{0} joined the battle\t(for team {1})", newUnit.NameFull, newUnit.getTeamNumber));
 }