Exemplo n.º 1
0
        /// <summary>
        ///  Enters defend state when the docking city is owned
        /// </summary>
        void Defend()
        {
            if (dockCity.NearbyEnemyBallCount > 0)
            {
                int tries = 0;
                int idx   = Randomizer.GetRandomInt(dockCity.NearbyEnemyBallCount);

                while (tries < dockCity.NearbyEnemyBallCount && dockCity.GetNearbyEnemyBall(idx).IsDied)
                {
                    tries++;
                    idx++;
                    idx %= dockCity.NearbyEnemyBallCount;
                }

                if (tries < dockCity.NearbyEnemyBallCount)
                {
                    target = dockCity.GetNearbyEnemyBall(idx);

                    if (target != null)
                    {
                        ChangeState(RBallState.Defend);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///  Try attack other ememy balls in the docking city
        /// </summary>
        void Attack()
        {
            if (dockCity.NearbyOwnedBallCount > 0)
            {
                // The enemy from the same side as the city's
                int tries = 0;
                int idx   = Randomizer.GetRandomInt(dockCity.NearbyOwnedBallCount);

                while (tries < dockCity.NearbyOwnedBallCount && dockCity.GetNearbyOwnedBall(idx).IsDied)
                {
                    tries++;
                    idx++;
                    idx %= dockCity.NearbyOwnedBallCount;
                }

                if (tries < dockCity.NearbyOwnedBallCount)
                {
                    target = dockCity.GetNearbyOwnedBall(idx);

                    if (target != null)
                    {
                        ChangeState(RBallState.Attack);
                    }
                }
            }
            else if (dockCity.NearbyEnemyBallCount > 0)
            {
                // The enemy from other sides than the city's
                int tries = 0;
                int idx   = Randomizer.GetRandomInt(dockCity.NearbyEnemyBallCount);

                while (tries < dockCity.NearbyEnemyBallCount &&
                       dockCity.GetNearbyEnemyBall(idx).IsDied &&
                       dockCity.GetNearbyEnemyBall(idx).Owner == Owner)
                {
                    idx++;
                    idx %= dockCity.NearbyEnemyBallCount;
                }

                if (tries < dockCity.NearbyEnemyBallCount)
                {
                    target = dockCity.GetNearbyEnemyBall(idx);

                    if (target != null)
                    {
                        ChangeState(RBallState.Attack);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public ResourceBallEventArg(bool bornOrDie, RBall ball)
 {
     BornOrDie = bornOrDie;
     ResourceBall = ball;
 }
Exemplo n.º 4
0
        public void CreateResourceBall(Player owner, City city, RBallType type)
        {
            RBall ball = new RBall(owner, city, type);
            resBalls.Add(ball);

            if (ResourceBallChanged != null) 
            {
                ResourceBallChanged(this, new ResourceBallEventArg(true, ball));
            }
        }
Exemplo n.º 5
0
 public void DestroyResourceBall(RBall ball)
 {
     resBalls.Remove(ball);
     if (ResourceBallChanged != null)
     {
         ResourceBallChanged(this, new ResourceBallEventArg(false, ball));
     }
 }
Exemplo n.º 6
0
        /// <summary>
        ///  Enters defend state when the docking city is owned
        /// </summary>
        void Defend()
        {
            if (dockCity.NearbyEnemyBallCount > 0)
            {
                int tries = 0;
                int idx = Randomizer.GetRandomInt(dockCity.NearbyEnemyBallCount);

                while (tries<dockCity.NearbyEnemyBallCount && dockCity.GetNearbyEnemyBall(idx).IsDied)
                {
                    tries++;
                    idx++;
                    idx %=dockCity.NearbyEnemyBallCount;
                }

                if (tries < dockCity.NearbyEnemyBallCount)
                {
                    target = dockCity.GetNearbyEnemyBall(idx);

                    if (target != null)
                    {
                        ChangeState(RBallState.Defend);
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        ///  Try attack other ememy balls in the docking city
        /// </summary>
        void Attack()
        {
            if (dockCity.NearbyOwnedBallCount > 0)
            {
                // The enemy from the same side as the city's
                int tries = 0;
                int idx = Randomizer.GetRandomInt(dockCity.NearbyOwnedBallCount);

                while (tries < dockCity.NearbyOwnedBallCount && dockCity.GetNearbyOwnedBall(idx).IsDied)
                {
                    tries++;
                    idx++;
                    idx %= dockCity.NearbyOwnedBallCount;
                }

                if (tries < dockCity.NearbyOwnedBallCount)
                {
                    target = dockCity.GetNearbyOwnedBall(idx);

                    if (target != null)
                    {
                        ChangeState(RBallState.Attack);
                    }
                }
            }
            else if (dockCity.NearbyEnemyBallCount > 0)
            {
                // The enemy from other sides than the city's
                int tries = 0;
                int idx = Randomizer.GetRandomInt(dockCity.NearbyEnemyBallCount);

                while (tries < dockCity.NearbyEnemyBallCount
                    && dockCity.GetNearbyEnemyBall(idx).IsDied 
                    && dockCity.GetNearbyEnemyBall(idx).Owner == Owner)
                {
                    idx++;
                    idx %= dockCity.NearbyEnemyBallCount;
                }

                if (tries < dockCity.NearbyEnemyBallCount)
                {
                    target = dockCity.GetNearbyEnemyBall(idx);

                    if (target != null)
                    {
                        ChangeState(RBallState.Attack);
                    }
                }
            }
        }
Exemplo n.º 8
0
        bool CheckBallThrowable(RBall ball)
        {
            if (ball.Owner != Owner)
            {
                return false;
            }
            if (ball.State == RBallState.Gathered)
            {
                return false;
            }
            if (ball.State == RBallState.Gathering)
            {
                return false;
            }
            if (ball.IsDied)
            {
                return false;
            }
            return true;

        }
Exemplo n.º 9
0
 public void NotifyResourceBallMoveOut(RBall ball)
 {
     nearbyBallList.Remove(ball);
     if (ball.Owner == Owner)
     {
         nearbyOwnedBalls.Remove(ball);
     }
     else
     {
         nearbyEnemyBalls.Remove(ball);
     }
 }
Exemplo n.º 10
0
        public void NotifyResourceBallMoveIn(RBall ball)
        {
            nearbyBallList.Add(ball);
            if (ball.Owner == Owner)
            {
                nearbyOwnedBalls.Add(ball);
            }
            else
            {
                nearbyEnemyBalls.Add(ball);
            }

        }