Example #1
0
        private void CreateSimModel()
        {
            if (_userData.simValues == null || _userData.simValues.Count == 0)
            {
                if (_userData.simValues == null)
                {
                    _userData.simValues = new List <SimulationValue>();
                }

                for (int x = 0; x < GRID_SIZE_X * TILE_SIZE; x = x + TILE_SIZE)
                {
                    for (int z = 0; z < GRID_SIZE_Z * TILE_SIZE; z = z + TILE_SIZE)
                    {
                        Tile  tile          = _emptyTile;
                        float angleToRotate = GetRandomAngle();

                        _simValue = new SimulationValue(x, z, angleToRotate.ToString(), tile);
                        _userData.simValues.Add(_simValue);

                        InstatiateSimValue(_simValue);
                    }
                }
                Debug.Log(JsonUtility.ToJson(_userData));
                StartCoroutine("InitSimData");
            }
            else
            {
                foreach (SimulationValue simValue in _userData.simValues)
                {
                    InstatiateSimValue(simValue);
                }
            }
        }
Example #2
0
        public void UpdateSim(int num)
        {
            int spendable = _userData.gold - _userData.goldSpent;

            if (spendable > 10)
            {
                _simValue            = ChooseSimValue();
                _userData.goldSpent -= _simValue.tile.cost; // 'Sell' previous tile
                _tile                = _simValue.tile;
                _simValue.tile       = UpgradeTile(_simValue.tile, spendable);
                _userData.goldSpent += _simValue.tile.cost; // 'Buy' new tile

                if (_tile.code == _simValue.tile.code)
                {
                    if (num >= 4)
                    {
                        return;
                    }

                    UpdateSim(num + 1);
                    return;
                }

                StartCoroutine("PutUserData");
                StartCoroutine("PutSimValue");

                Destroy(_tileObjects[_simValue.xPos / TILE_SIZE, _simValue.yPos / TILE_SIZE]);
                InstatiateSimValue(_simValue);
            }
        }
Example #3
0
        private SimulationValue ChooseSimValue()
        {
            int             randX    = _rand.Next(0, GRID_SIZE_X);
            int             randZ    = _rand.Next(0, GRID_SIZE_Z);
            int             posX     = randX * TILE_SIZE;
            int             posZ     = randZ * TILE_SIZE;
            SimulationValue simValue = _userData.simValues.Find(s => s.xPos == posX && s.yPos == posZ);

            if (simValue == null)
            {
                return(ChooseSimValue());
            }
            return(simValue);
        }
Example #4
0
        void InstatiateSimValue(SimulationValue simValue)
        {
            GameObject obj           = GetTileByCode(simValue.tile.code);
            float      angleToRotate = float.Parse(simValue.rotation);
            Quaternion q             = Quaternion.AngleAxis(angleToRotate, Vector3.up);

            // Transform to account for movement
            int newX = angleToRotate == 270 || angleToRotate == 180 ? simValue.xPos - TILE_SIZE : simValue.xPos;
            int newZ = angleToRotate == 90f || angleToRotate == 180f ? simValue.yPos - TILE_SIZE : simValue.yPos;

            // Create obj
            GameObject tileObj = Instantiate(obj, new Vector3(newX, 0, newZ), q);

            _tileObjects[simValue.xPos / TILE_SIZE, simValue.yPos / TILE_SIZE] = tileObj;
        }