コード例 #1
0
    public bool HasValidUnoccupiedPositions(FoodMap foodMap)
    {
        List <int> fixedRows = new List <int> {
            minRow, maxRow
        };
        List <int> fixedColumns = new List <int> {
            minColumn, maxColumn
        };

        foreach (var row in fixedRows)
        {
            for (int column = minColumn; column <= maxColumn; ++column)
            {
                Vector2Int position = new Vector2Int(column, row);
                if (foodMap.IsValidAndUnoccupied(position))
                {
                    return(true);
                }
            }
        }

        foreach (var column in fixedColumns)
        {
            for (int row = minRow + 1; row < maxRow; ++row)
            {
                Vector2Int position = new Vector2Int(column, row);
                if (foodMap.IsValidAndUnoccupied(position))
                {
                    return(true);
                }
            }
        }

        return(false);
    }
コード例 #2
0
    private void Start()
    {
        Manager = GameObject.Find("Level Manager")?.GetComponent <LevelManager>();
        MenuButton.onClick.AddListener(() => Manager?.OnMenu());
        ScoreDisplay = GameObject.Find("Score Display").GetComponent <TMP_Text>();

        PlayerDestination  = PlayerTransform.position;
        flowerHealthSlider = GameObject.Find("Flower Health Slider").GetComponent <Slider>();

        foodMap = new FoodMap(levelGrid, waveCount, firstValidWave);
        // This needs to be called after the foodMap is created.
        SpawnObstacles();

        flower = new Flower(flowerInitialSeconds, flowerMaxSeconds, flowerWiltThresholdInSeconds);

        snake = new Snake();

        flowerHealthSlider.maxValue     = flower.MaxSecondsRemaining;
        flowerHealthSlider.minValue     = 0f;
        flowerHealthSlider.wholeNumbers = true;

        playerScore = 0;

        StartCoroutine(FoodWaveController());
        StartCoroutine(SpawnFood());
        StartCoroutine(FlowerCountdownTimer());
        var fixedColor = background.color;

        fixedColor.a     = 1;
        background.color = fixedColor;
        background.CrossFadeAlpha(0f, 0f, true);
        GameOverContainer.SetActive(false);

        enemySpawner =
            new EnemySpawner(
                horizontalEnemyLifetime,
                verticalEnemyLifetime);

        StartCoroutine(SpawnEnemies());

        e_AudioSource = GetComponent <AudioSource>();

        for (int i = 0; i < EnemyPoolLimit; i++)
        {
            // This line throws an exception
            var temp = Instantiate(EnemyPrefab, Vector3.zero, Quaternion.identity, EnemyContainer.transform);

            temp.SetActive(false);
            EnemyList.Add(temp);
        }
    }
コード例 #3
0
ファイル: FoodMapController.cs プロジェクト: MyLegendLife/O2O
        public List <FoodMap> GetFoodMapList(string token, long shopId)
        {
            var list = new List <FoodMap>();

            var resCate = _serviceFood.GetShopCategories(token, shopId);

            if (resCate.error == null)
            {
                var cates = JsonConvert.DeserializeObject <List <OCategory> >(resCate.result.ToString());

                foreach (var cate in cates)
                {
                    var resItem = _serviceFood.GetItemsByCategoryId(token, cate.id);

                    if (resItem.error != null)
                    {
                        continue;
                    }

                    var dics = JsonConvert.DeserializeObject <Dictionary <long, OItem> >(resItem.result.ToString());

                    foreach (var dic in dics)
                    {
                        var item = dic.Value;

                        foreach (var spec in item.specs)
                        {
                            var foodMap = new FoodMap();

                            foodMap.Token    = token;
                            foodMap.CateId   = cate.id;
                            foodMap.CateName = cate.name;
                            foodMap.ItemId   = item.id;
                            foodMap.ItemName = item.name;
                            foodMap.SpecId   = spec.specId;
                            foodMap.SpecName = spec.name;
                            foodMap.Price    = spec.price;
                            foodMap.Stock    = spec.stock;

                            var extendCode = spec.extendCode;
                            var codes      = extendCode.Split(new[] { 'X' }, StringSplitOptions.RemoveEmptyEntries);

                            var prodNo   = "";
                            var prodName = "";
                            var prodUnit = "";
                            var price    = "";
                            foreach (var code in codes)
                            {
                                var prod = _prodList.Find(a => a.ProdNo == code);
                                if (prod != null)
                                {
                                    prodNo   += $"{prod.ProdNo}\r\n";
                                    prodName += $"{prod.ProdName}\r\n";
                                    prodUnit += $"{prod.ProdUnit}\r\n";
                                    price    += $"{prod.Price}\r\n";
                                }
                            }

                            foodMap.ProdNo    = prodNo.Trim("\r\n".ToCharArray());
                            foodMap.ProdName  = prodName.Trim("\r\n".ToCharArray());
                            foodMap.ProdUnit  = prodUnit.Trim("\r\n".ToCharArray());
                            foodMap.SalePrice = price.Trim("\r\n".ToCharArray());

                            list.Add(foodMap);
                        }
                    }
                }
            }

            return(list);
        }
コード例 #4
0
 void Start()
 {
     myState = BehaviorState.idle;
     stateMachine = gameObject.GetComponent<AnimalStateMachine>();
     animator = gameObject.transform.FindChild("AnimatedChild").gameObject.GetComponent<Animator>();
     body = gameObject.GetComponent<AnimalBody>();
     foodMap = GameObject.FindGameObjectWithTag("Map").GetComponent<FoodMap>();
     animalMap = GameObject.FindGameObjectWithTag("Map").GetComponent<AnimalMap>();
     PrairieBrainStart(); //Only meaningful in the child class PrairieDogBrain
 }