Example #1
0
        public MainWindow()
        {
            InitializeComponent();
            timer.Interval = 15;
            timer.Tick    += Timer_Tick;
            try
            {
                Names.AddRange(File.ReadLines("resources/nomes.txt"));
            }
            catch (Exception ex)
            {
                //System.Windows.MessageBox.Show(ex.Message);
            }



            bugsMaxQty = 10;
            object syncLock = new object();

            lock (syncLock)
            {
                for (int i = 0; i <= bugsMaxQty * 10; i++)
                {
                    Foods.Add(new Food());
                }

                for (int i = 0; i <= bugsMaxQty; i++)
                {
                    Bugs.Add(new Autobug());
                }
                for (int i = 0; i <= bugsMaxQty; i++)
                {
                    Labels.Add(new BugLabel());
                }
                foreach (BugLabel label in Labels)
                {
                    label.IsOn        = chkLabels.IsChecked.Value;
                    label.RelativeAge = chkRelativeAge.IsChecked.Value;
                    Stage.Children.Add(label);
                }

                foreach (Food food in Foods)
                {
                    Stage.Children.Add(food);
                    food.hatch();
                }
                foreach (Autobug bug in Bugs)
                {
                    int nameIndex = Measure2.Random(Names.Count);
                    UsedNames.Add(nameIndex);
                    string newName = Names[nameIndex];
                    bug.Name = newName;
                    Stage.Children.Add(bug);
                    bug.hatch();
                }
            }


            timer.Start();
        }
Example #2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            foreach (Autobug bug in Bugs)
            {
                bug.act(Foods);

                foreach (Food food in Foods)
                {
                    if (Measure2.Distance(bug.ActualPosition, food.Position) < 0.001)
                    {
                        food.shrink(bug.BiteSize);
                    }
                    else
                    {
                        food.grow();
                    }
                }

                Labels[Bugs.IndexOf(bug)].ShowLabel           = bug._showLabel;
                Labels[Bugs.IndexOf(bug)].ShowLabelPersistent = bug._showLabelPersistent;
                Labels[Bugs.IndexOf(bug)].BugName             = (bug._amDying) ? "MORTO" : bug.Name;
                Labels[Bugs.IndexOf(bug)].BugType             = bug.Type;
                Labels[Bugs.IndexOf(bug)].AgeNow          = bug.Age;
                Labels[Bugs.IndexOf(bug)].AgeMax          = bug.LifeSpan;
                Labels[Bugs.IndexOf(bug)].RelativeAge     = chkRelativeAge.IsChecked.Value;
                Labels[Bugs.IndexOf(bug)].IsOn            = chkLabels.IsChecked.Value;
                Labels[Bugs.IndexOf(bug)].RenderTransform = new TranslateTransform(bug.pos.X + 50 + bug.Size / 2, bug.pos.Y + 25 + bug.Size / 2);
                Labels[Bugs.IndexOf(bug)].populate();
            }
        }
Example #3
0
        public void think()
        {
            double distanceFromFood, distanceFromTarget;

            target             = AquireTarget();
            FoodPosition       = Convert2.toVector(target);
            distanceFromFood   = Measure2.Distance(WhereAmI, FoodPosition);
            TargetPosition     = FoodPosition;
            distanceFromTarget = distanceFromFood;
            LastReassurance++;
            switch (WhatAmIDoing)
            {
            case "WALK":
                if (distanceFromTarget <= 0.001)
                {
                    _whatToDo = "STOP";
                }
                else if (distanceFromTarget > WalkingSpeed)
                {
                    _whatToDo = "WALK";
                }
                break;

            case "STOP":
                if (distanceFromTarget > WalkingSpeed)
                {
                    _whatToDo = "EVOLVE";
                }
                else
                {
                    _timeStopped++;
                }
                break;

            case "EVOLVE":
                if (_timeToEvolve < _timeStopped * 10)
                {
                    MySize       += 1 / _timeStopped / 10;
                    BiteSize     += 1 / _timeStopped / 10000;
                    WalkingSpeed += 1 / _timeStopped / 100000;
                    _timeToEvolve++;
                    _whatToDo = "EVOLVE";
                }
                else
                {
                    _timeToEvolve = 0;
                    _timeStopped  = 0;
                    _whatToDo     = "WALK";
                }
                break;

            default:
                _whatToDo = "WALK";
                break;
            }
        }
Example #4
0
        public void hatch()
        {
            _sizeMultiplyier = _speedMultiplyier = _biteSizeMultiplyier = _lifespanMultiplyier = 1;
            _size            = 2;
            ActualPosition   = new Vector(Measure2.Random(-300, 300), Measure2.Random(-300, 300));
            _speed           = 0.1;
            _biteSize        = 0.05;

            hatch(_size, ActualPosition, _speed, _biteSize, 2000);
        }
Example #5
0
        public Vector move(Vector actualPosition, Vector Target, double speed)
        {
            if (Keyboard.IsKeyDown(Key.Enter))
            {
                speed++;
            }

            double angle    = Measure2.AngleBetween(actualPosition, Target);
            double distance = Measure2.Distance(actualPosition, Target);
            double X        = (speed < distance) ? Math.Cos(angle) * speed : Math.Cos(angle) * distance;
            double Y        = (speed < distance) ? Math.Sin(angle) * speed : Math.Sin(angle) * distance;

            return(new Vector(X, Y));
        }
Example #6
0
        public void hatch(bool SuperFood = true)
        {
            _growRate  = Measure2.RandomDouble();
            _minSize   = 2;
            _maxSize   = Measure2.Random(5, 10);
            ActualSize = InicialSize;
            if (SuperFood)
            {
                IsSuperFood = (Measure2.Random(1000) == 1) ? true : false;
            }

            Position = new Vector(Measure2.Random(-300, 300), Measure2.Random(-300, 300));

            Color = Brushes.Red;
        }
Example #7
0
        private void GenType()
        {
            double multiplyer = 2;

            switch (Measure2.Random(5))
            {
            case 0:
                Type = "GLUTÃO";
                _biteSizeMultiplyier = multiplyer;
                break;

            case 1:
                Type = "APRESSADINHO";
                _speedMultiplyier = multiplyer;
                break;

            case 2:
                Type = "ZÉ";
                _biteSizeMultiplyier = 1;
                break;

            case 3:
                Type = "MATUSALÉM";
                _lifespanMultiplyier = multiplyer;
                break;

            case 4:
                Type     = "EINSTEIN";
                LifeSpan = 1;
                goto case 5;

            case 5:
                Type = "ZÉ";
                break;

            default:
                break;
            }
        }
Example #8
0
        private Food DecideFood()
        {
            List <double> foodPos = new List <double>();
            List <double> foodSize = new List <double>();
            List <Food>   SuperFoods = new List <Food>();
            List <Food>   FoodsToCheck = new List <Food>();
            Food          targetFood, nearestFood;

            foreach (Food food in Foods)
            {
                if (food.IsSuperFood)
                {
                    SuperFoods.Add(food);
                }
            }

            if (SuperFoods.Count > 0)
            {
                FoodsToCheck       = SuperFoods;
                _targetIsSuperFood = true;
            }
            else
            {
                FoodsToCheck       = Foods;
                _targetIsSuperFood = false;
            }

            foreach (Food food in FoodsToCheck)
            {
                foodPos.Add(Measure2.Distance(WhereAmI, Convert2.toVector(food)));
            }
            int nearestFoodID = foodPos.IndexOf(foodPos.Min());

            nearestFood = FoodsToCheck[nearestFoodID];
            targetFood  = nearestFood;

            return(targetFood);
        }