Exemplo n.º 1
0
    void Start()
    {
        _locationGenerator = GameObject.Find("GenerationManager").GetComponent <LocationGenerator>();
        _seeker            = GetComponent <Seeker>();

        _timeManager = GameObject.Find(NameOfTimeManager).GetComponent <TimeManager>();

        _timeToBreeding = 15f;

        _waters    = GameObject.FindGameObjectsWithTag("Water");
        _foods     = GameObject.FindGameObjectsWithTag("Food");
        _greenMobs = GameObject.FindGameObjectsWithTag("GreenMob");

        for (int i = 0; i < _greenMobs.Length; i++)
        {
            if (_greenMobs[i].name == gameObject.name)
            {
                _greenMobs[i] = null;
                _greenMobs    = _greenMobs.Where(x => x != null).ToArray();
            }
        }

        _waterNeeds = GetComponent <WaterNeeds>();
        _foodNeeds  = GetComponent <FoodNeeds>();

        _timeToStuck = 0f;
        _changePlace = new Vector3(0f, 0f, 0f);

        _way = WayPoint.Choose;
    }
    void Start()
    {
        _player      = GameObject.Find(PlayerName);
        _playerPanel = GameObject.Find(PlayerPanelName);

        _winPanel = GameObject.Find("WinPanel");
        _winPanel.SetActive(false);

        _deathPanel = GameObject.Find("DeathPanel");
        _deathPanel.SetActive(false);

        _collectRadioPart = _player.GetComponent <CollectRadioPart>();
        _foodNeeds        = _player.GetComponent <FoodNeeds>();
        _waterNeeds       = _player.GetComponent <WaterNeeds>();

        RadioPartsMax.text = "/ " + _collectRadioPart.ReturnMax();
    }
Exemplo n.º 3
0
        public void FoodNeedRatesBaseOnLifeStageTest(LifeStage lifeStage, int rate)
        {
            // Arrange
            var dragon = new Tamagotchi("Dragon");

            dragon.LifeStage = lifeStage;
            var hungrinessBefore = dragon.Hungriness;

            var need = new FoodNeeds();

            // Act
            need.Satisfy(dragon);
            var hungrinessAfter = dragon.Hungriness;

            // Assert
            Math.Abs(hungrinessAfter - hungrinessBefore).ShouldBe(rate);
        }
Exemplo n.º 4
0
        public void ExampleOfUse()
        {
            // Dragon is born and it is a baby
            var dragon = new Tamagotchi("Needy dragon");

            var needForFood    = new FoodNeeds();
            var needForPetting = new PettingNeeds();

            dragon.AddNeed(needForFood);
            dragon.AddNeed(needForPetting);

            // TimePassed could be called each hour (or something like that) to age the pet
            dragon.TimePassed();
            dragon.TimePassed();
            dragon.TimePassed();

            // At this point it is 3 years old, very unhappy and hungry
            dragon.Age.ShouldBe(3);
            dragon.Happiness.ShouldBe(-45);
            dragon.Hungriness.ShouldBe(24);

            // Let's feed it first
            dragon.Feed();
            dragon.Feed();
            dragon.Hungriness.ShouldBe(8); // It is less hungy now

            // Let's give it some attention
            dragon.Pet();
            dragon.Pet();
            dragon.Happiness.ShouldBe(-15); // It is less unhappy now

            // At this point we could add a new need. For example the need for a diet (Implemented bellow)
            dragon.AddNeed(new DietNeeds());

            dragon.Weight.ShouldBe(7);

            // 50 years passed
            for (int i = 0; i < 50; i++)
            {
                dragon.TimePassed();
            }

            dragon.Age.ShouldBe(53);
            dragon.Weight.ShouldBe(107);
        }
    void Way()
    {
        if (_way == WayPoint.Going)
        {
            if (_timeToBreeding <= 0f)
            {
                for (int i = 0; i < _redMobs.Length; i++)
                {
                    if (Math.Abs(_redMobs[i].transform.position.x - gameObject.transform.position.x) < 4f && Math.Abs(_redMobs[i].transform.position.y - gameObject.transform.position.y) < 4f)
                    {
                        if (_foodNeeds.ReturnFood() > 85)
                        {
                            if (_waterNeeds.ReturnWater() > 85)
                            {
                                _way = WayPoint.Breeding;
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < _greenMobs.Length; i++)
            {
                if (Math.Abs(_greenMobs[i].transform.position.x - gameObject.transform.position.x) < 4f && Math.Abs(_greenMobs[i].transform.position.y - gameObject.transform.position.y) < 4f)
                {
                    _way = WayPoint.Devouring;
                }
            }


            if (gameObject.transform.position.x > _target.x - 0.5f &&
                gameObject.transform.position.x <= _target.x + 0.5f &&
                gameObject.transform.position.y > _target.y - 0.5f &&
                gameObject.transform.position.y <= _target.y + 2.7f)
            {
                //print("Done!");
                _way = WayPoint.Choose;
            }
        }

        if (_way == WayPoint.Breeding)
        {
            _timeToBreeding = 15f;
            Instantiate(RedMobPrefab,
                        new Vector3(gameObject.transform.position.x + 0.3f, gameObject.transform.position.y + 0.3f,
                                    gameObject.transform.position.z), Quaternion.identity);
            _way = WayPoint.Going;
        }

        if (_way == WayPoint.Devouring)
        {
            if (_timeManager.NowSeason == TimeManager.Season.Summer & _waterNeeds.ReturnWater() < 75f & _foodNeeds.ReturnFood() < 75f)
            {
                for (int i = 0; i < _greenMobs.Length; i++)
                {
                    if (Math.Abs(_greenMobs[i].transform.position.x - gameObject.transform.position.x) < 4f &&
                        Math.Abs(_greenMobs[i].transform.position.y - gameObject.transform.position.y) < 4f)
                    {
                        //print("OM NOM NOM!!!");
                        Destroy(_greenMobs[i]);
                    }
                }

                _waterNeeds.AddWater(100f);
                _foodNeeds.AddFood(100f);
            }

            if (_waterNeeds.ReturnWater() < 60f || _foodNeeds.ReturnFood() < 60f)
            {
                for (int i = 0; i < _greenMobs.Length; i++)
                {
                    if (Math.Abs(_greenMobs[i].transform.position.x - gameObject.transform.position.x) < 4f &&
                        Math.Abs(_greenMobs[i].transform.position.y - gameObject.transform.position.y) < 4f)
                    {
                        //print("OM NOM NOM!!!");
                        Destroy(_greenMobs[i]);
                    }
                }

                _waterNeeds.AddWater(100f);
                _foodNeeds.AddFood(100f);
            }
            _way = WayPoint.Going;
        }

        if (_way == WayPoint.Food)
        {
            if (_timeManager.NowSeason == TimeManager.Season.Summer)
            {
                int number = 0;
                if (_greenMobs.Length > 0)
                {
                    float distance = (Math.Abs(_greenMobs[number].transform.position.x -
                                               gameObject.transform.position.x -
                                               _locationGenerator.LongOfGrassBlock / 2) +
                                      Math.Abs(_greenMobs[number].transform.position.y -
                                               gameObject.transform.position.y +
                                               _locationGenerator.LongOfGrassBlock / 2));


                    for (int i = 0; i < _greenMobs.Length; i++)
                    {
                        if ((Math.Abs(_greenMobs[i].transform.position.x - gameObject.transform.position.x -
                                      _locationGenerator.LongOfGrassBlock / 2) +
                             Math.Abs(_greenMobs[i].transform.position.y - gameObject.transform.position.y +
                                      _locationGenerator.HeightOfGrassBlock / 2)) < distance)
                        {
                            number = i;

                            distance = (Math.Abs(_greenMobs[number].transform.position.x -
                                                 gameObject.transform.position.x -
                                                 _locationGenerator.LongOfGrassBlock / 2) +
                                        Math.Abs(_greenMobs[number].transform.position.y -
                                                 gameObject.transform.position.y +
                                                 _locationGenerator.LongOfGrassBlock / 2));
                        }
                    }

                    _target = _greenMobs[number].transform.position;
                    _seeker.StartPath(transform.position, _target + new Vector3(0f, 1.7f, 0), OnPathComplete);
                    _way = WayPoint.Going;
                }
                else
                {
                    var distance = (Math.Abs(_foods[number].transform.position.x - gameObject.transform.position.x -
                                             _locationGenerator.LongOfGrassBlock / 2) +
                                    Math.Abs(_foods[number].transform.position.y - gameObject.transform.position.y +
                                             _locationGenerator.LongOfGrassBlock / 2));

                    for (int i = 0; i < _foods.Length; i++)
                    {
                        var need = _foods[i].GetComponent <FoodHave>();
                        if (need.ReturnFood() > _foodNeeds.ReturnFoodNeeds())
                        {
                            if ((Math.Abs(_foods[i].transform.position.x - gameObject.transform.position.x -
                                          _locationGenerator.LongOfGrassBlock / 2) +
                                 Math.Abs(_foods[i].transform.position.y - gameObject.transform.position.y +
                                          _locationGenerator.HeightOfGrassBlock / 2)) < distance)
                            {
                                number = i;

                                distance = (Math.Abs(_foods[number].transform.position.x - gameObject.transform.position.x -
                                                     _locationGenerator.LongOfGrassBlock / 2) +
                                            Math.Abs(_foods[number].transform.position.y - gameObject.transform.position.y +
                                                     _locationGenerator.LongOfGrassBlock / 2));
                            }
                        }
                    }

                    _target = _foods[number].transform.position;
                    _seeker.StartPath(transform.position, _target + new Vector3(0f, 1.7f, 0), OnPathComplete);
                    _way = WayPoint.Going;
                }
            }
            else
            {
                int number = 0;

                var distance = (Math.Abs(_foods[number].transform.position.x - gameObject.transform.position.x -
                                         _locationGenerator.LongOfGrassBlock / 2) +
                                Math.Abs(_foods[number].transform.position.y - gameObject.transform.position.y +
                                         _locationGenerator.LongOfGrassBlock / 2));

                for (int i = 0; i < _foods.Length; i++)
                {
                    var need = _foods[i].GetComponent <FoodHave>();
                    if (need.ReturnFood() > _foodNeeds.ReturnFoodNeeds())
                    {
                        if ((Math.Abs(_foods[i].transform.position.x - gameObject.transform.position.x -
                                      _locationGenerator.LongOfGrassBlock / 2) +
                             Math.Abs(_foods[i].transform.position.y - gameObject.transform.position.y +
                                      _locationGenerator.HeightOfGrassBlock / 2)) < distance)
                        {
                            number = i;

                            distance = (Math.Abs(_foods[number].transform.position.x - gameObject.transform.position.x -
                                                 _locationGenerator.LongOfGrassBlock / 2) +
                                        Math.Abs(_foods[number].transform.position.y - gameObject.transform.position.y +
                                                 _locationGenerator.LongOfGrassBlock / 2));
                        }
                    }
                }

                _target = _foods[number].transform.position;
                _seeker.StartPath(transform.position, _target + new Vector3(0f, 1.7f, 0), OnPathComplete);
                _way = WayPoint.Going;
            }
        }

        if (_way == WayPoint.Water)
        {
            //print("water");
            WaterHave need;
            int       number = 0;

            //WaterNeeds waterNeeds = GetComponent<WaterNeeds>();

            float distance;

            distance = (Math.Abs(_waters[number].transform.position.x - gameObject.transform.position.x -
                                 _locationGenerator.LongOfGrassBlock / 2) +
                        Math.Abs(_waters[number].transform.position.y - gameObject.transform.position.y +
                                 _locationGenerator.LongOfGrassBlock / 2));

            for (int i = 0; i < _waters.Length; i++)
            {
                need = _waters[i].GetComponent <WaterHave>();
                if (need.ReturnWater() > _waterNeeds.ReturnWaterNeed())
                {
                    if ((Math.Abs(_foods[i].transform.position.x - gameObject.transform.position.x -
                                  _locationGenerator.LongOfGrassBlock / 2) +
                         Math.Abs(_foods[i].transform.position.y - gameObject.transform.position.y +
                                  _locationGenerator.HeightOfGrassBlock / 2)) < distance)
                    {
                        number   = i;
                        distance = (Math.Abs(_waters[number].transform.position.x - gameObject.transform.position.x -
                                             _locationGenerator.LongOfGrassBlock / 2) +
                                    Math.Abs(_waters[number].transform.position.y - gameObject.transform.position.y +
                                             _locationGenerator.LongOfGrassBlock / 2));
                    }
                }
            }

            _target = _waters[number].transform.position;
            _seeker.StartPath(transform.position, _target + new Vector3(0f, 2.5f, 0), OnPathComplete);

            _way = WayPoint.Going;
        }

        if (_way == WayPoint.Walking)
        {
            var seeker = GetComponent <Seeker>();

            _goingTarget = new Vector3(
                _locationGenerator.Size *
                _locationGenerator.Rand.Next(0, (int)_locationGenerator.LongOfGrassBlock * 9 / 10),
                -_locationGenerator.Size *
                _locationGenerator.Rand.Next(0, (int)_locationGenerator.HeightOfGrassBlock / 2), 0f);
            _target = _goingTarget;
            // _target = GameObject.Find("Player").transform.position;

            seeker.StartPath(transform.position, _target, OnPathComplete);
            _way = WayPoint.Going;
        }

        if (_way == WayPoint.Choose)
        {
            if (_timeManager.NameOfTime == TimeManager.TimeName.Morning)
            {
                _seeker.CancelCurrentPathRequest();
            }
            else
            {
                WaterNeeds water = GetComponent <WaterNeeds>();
                FoodNeeds  food  = GetComponent <FoodNeeds>();

                if (water.ReturnWater() < food.ReturnFood())
                {
                    if (water.ReturnWater() < 85)
                    {
                        _way = WayPoint.Water;
                    }
                    else
                    {
                        _way = WayPoint.Walking;
                        ;
                    }
                }
                else
                {
                    if (food.ReturnFood() < 85)
                    {
                        _way = WayPoint.Food;
                    }
                    else
                    {
                        _way = WayPoint.Walking;
                    }
                }
            }
        }
    }