private void SearchForClosest(FurnitureType decision)
        {
            List <FurnitureStatus> furnitureStats = Engine.GetFournitureStats(decision);

            if (furnitureStats.Count > 0)
            {
                destination = furnitureStats[0];
                for (int i = 1; i < furnitureStats.Count; i++)
                {
                    if (Calculator.GetDistance(this.GetPosition(), destination.GetPosition()) > Calculator.GetDistance(this.GetPosition(), furnitureStats[i].GetPosition()) && destination.IsAvailable())
                    {
                        destination = furnitureStats[i];
                    }
                }
            }
        }
Beispiel #2
0
        public static List <FurnitureStatus> GetFournitureStats(FurnitureType furnitureType)
        {
            List <FurnitureStatus> furnitureStats = new List <FurnitureStatus>();

            foreach (Entity entity in entities)
            {
                if (entity is Furniture)
                {
                    Furniture furniture = (Furniture)entity;
                    if (furniture.GetFurnitureType() == furnitureType)
                    {
                        FurnitureStatus furnitureStatus = new FurnitureStatus();
                        furnitureStatus.SetFurniture(furniture);
                        furnitureStats.Add(furnitureStatus);
                    }
                }
            }
            return(furnitureStats);
        }
        public void Move()
        {
            if (!isDecided)
            {
                MakeDecision();
                SearchForClosest(this.decision);
                MoveTowardTarget();
            }


            if (isRefilling)
            {
                Refill();

                if (energy >= 100)
                {
                    energy      = 100;
                    isRefilling = false;
                    isDecided   = false;
                    destination.DecreaseNumberOfUsers();
                    destination = null;
                }
                else if (fun >= 100)
                {
                    fun         = 100;
                    isRefilling = false;
                    isDecided   = false;
                    destination.DecreaseNumberOfUsers();
                    destination = null;
                }
                else if (bladder >= 100)
                {
                    bladder     = 100;
                    isRefilling = false;
                    isDecided   = false;
                    destination.DecreaseNumberOfUsers();
                    destination = null;
                }
                else if (hunger >= 100)
                {
                    hunger      = 100;
                    isRefilling = false;
                    isDecided   = false;
                    destination.DecreaseNumberOfUsers();
                    destination = null;
                }
            }
            else
            {
                if (destination != null)
                {
                    if (Calculator.GetDistance(this.GetPosition(), destination.GetPosition()) < 50)
                    {
                        if (destination.IsAvailable())
                        {
                            isRefilling = true;
                            destination.IncreaseNumberOfUsers();
                        }
                    }
                    else
                    {
                        this.position.X += (int)towardX;
                        this.position.Y += (int)towardY;
                    }
                }
                else
                {
                    isDecided = false;
                }
            }
            ConsumeResources();
        }
 public void StopFromActions()
 {
     isDecided   = false;
     isRefilling = false;
     destination = null;
 }