Beispiel #1
0
    void AddBuilding(CityBuilding building)
    {
        GameObject rock = GameObject.Find ("Rock");
        Vector3 center = new Vector3(startPoint.x + blockSize.x * building.X + blockSize.x , startPoint.y + blockSize.y * building.Y + blockSize.y * 1);
        GameObject rock2 = Instantiate (rock, center, Quaternion.identity) as GameObject;
        PolyMesh a = rock2.GetComponent<PolyMesh> ();

        a.makeUnique ();

        a.keyPoints.Clear ();
        a.isCurve.Clear ();

        List<Vector3> pts = new List<Vector3>();

        pts.Add(new Vector3(-buildingSize.x/2, -buildingSize.y/2));

        if(building.HasPoint(new Point(0,1))){
            pts.Add(new Vector3(-buildingSize.x/2, -buildingSize.y/2 - blockSize.y));
            pts.Add(new Vector3(buildingSize.x/2, -buildingSize.y/2 - blockSize.y));
        }

        pts.Add(new Vector3(buildingSize.x/2, -buildingSize.y/2));

        if(building.HasPoint(new Point(1,0))){
            pts.Add(new Vector3(buildingSize.x/2 + blockSize.x, -buildingSize.y/2));
            pts.Add(new Vector3(buildingSize.x/2 + blockSize.x, buildingSize.y/2));
        }

        pts.Add(new Vector3(buildingSize.x/2, buildingSize.y/2));

        if(building.HasPoint(new Point(0,-1))){
            pts.Add(new Vector3(buildingSize.x/2, buildingSize.y/2 + blockSize.y));
            pts.Add(new Vector3(-buildingSize.x/2, buildingSize.y/2 + blockSize.y));
        }

        pts.Add(new Vector3(-buildingSize.x/2, buildingSize.y/2));

        if(building.HasPoint(new Point(-1, 0))){
            pts.Add(new Vector3(-buildingSize.x/2 - blockSize.x, buildingSize.y/2));
            pts.Add(new Vector3(-buildingSize.x/2 - blockSize.x, -buildingSize.y/2));
        }

        pts.Reverse ();

        a.keyPoints.AddRange (pts);

        /*
        a.keyPoints.Add(new Vector3(-rect.width/2, -rect.height/2));
        a.keyPoints.Add(new Vector3(rect.width/2, -rect.height/2));
        a.keyPoints.Add(new Vector3(rect.width/2, rect.height/2));
        a.keyPoints.Add(new Vector3(-rect.width/2, rect.height/2));
        */

        for(int i =0; i< a.keyPoints.Count; i++)
            a.isCurve.Add(false);

        a.BuildMesh ();
    }
Beispiel #2
0
 // 跑到建筑物周围
 public void RunToTroop(CityBuilding building)
 {
     _troopBuilding    = building;
     agent.destination = building.transform.position;
     ChangeToRunningBackState();
 }
Beispiel #3
0
        public async Task <IdentityResult> CreateCity(string cityName)
        {
            using (_applicationDbContext)
            {
                City newCity = new City
                {
                    Name       = cityName,
                    Population = 1000,
                    Pearl      = 10000,
                    Coral      = 10000,
                    Rank       = 0
                };
                _applicationDbContext.Cities.Add(newCity);

                CityBuilding cityBuildingData1 = new CityBuilding
                {
                    CityId        = newCity.Id,
                    BuildingId    = (int)BuildingTypeEnum.Aramlasiranyito,
                    Number        = 0,
                    RoundToFinish = 0,
                };
                _applicationDbContext.CityBuildings.Add(cityBuildingData1);

                CityBuilding cityBuildingData2 = new CityBuilding
                {
                    CityId        = newCity.Id,
                    BuildingId    = (int)BuildingTypeEnum.Zatonyvar,
                    Number        = 0,
                    RoundToFinish = 0,
                };
                _applicationDbContext.CityBuildings.Add(cityBuildingData2);

                for (var i = 1; i <= 6; i++)
                {
                    CityUpgrade cityUpgradeData = new CityUpgrade
                    {
                        CityId        = newCity.Id,
                        UpgradeId     = i,
                        Number        = 0,
                        RoundToFinish = 0,
                    };
                    _applicationDbContext.CityUpgrades.Add(cityUpgradeData);
                }

                var newArmyid = (_applicationDbContext.Armies
                                 .Select(a => a.ArmyId).DefaultIfEmpty(0).Max()) + 1;

                var cityArmy = new Army
                {
                    CityId      = newCity.Id,
                    ArmyId      = newArmyid,
                    EnemyCityId = null,
                };
                _applicationDbContext.Armies.Add(cityArmy);
                await _applicationDbContext.SaveChangesAsync();

                for (var i = 1; i <= 3; i++)
                {
                    var Units = new ArmyUnit
                    {
                        UnitId = i,
                        Number = 0,
                        ArmyId = newArmyid,
                    };
                    _applicationDbContext.ArmyUnits.Add(Units);
                }

                var success = await _applicationDbContext.SaveChangesAsync() > 0;

                if (!success)
                {
                    return(IdentityResult.Failed());
                }

                return(IdentityResult.Success);
            }
        }
Beispiel #4
0
    public CityGenerator(int sizeX, int sizeY)
    {
        this.sizeX = sizeX;
        this.sizeY = sizeY;

        Grid = new CityBuilding[sizeX,sizeY];

        for (int x = 0; x < sizeX; x++) {
            for(int y = 0; y < sizeX; y++){
                Grid[x,y] = new CityBuilding(x,y);
            }
        }
    }
Beispiel #5
0
 // 跑到建筑物周围
 public void RunToBuilding(CityBuilding building)
 {
     _workingBuilding  = building;
     agent.destination = building.transform.position;
     ChangeToRunningState();
 }