示例#1
0
        public bool StartBuilding(TileType tileToBuild, int tileId)
        {
            foreach (List<PlayerTile> tiles in map)
            {
                foreach (PlayerTile playerTile in tiles)
                {
                    if (playerTile.Id == tileId && playerTile.TileType.kind == tileToBuild.kind)
                    {
                        Debug.WriteLine("Already build here.");
                        return false;
                    }
                }
            }

            if ( tileToBuild.FoodCost <= resources.food &&
                 tileToBuild.StoneCost <= resources.stone &&
                 tileToBuild.WoodCost <= resources.wood &&
                 tileToBuild.GoldCost <= resources.gold &&
                 tileToBuild.WorkerCost <= resources.workers)
            {

                resources.food -= tileToBuild.FoodCost;
                resources.stone -= tileToBuild.StoneCost;
                resources.wood -= tileToBuild.WoodCost;
                resources.gold -= tileToBuild.GoldCost;
                resources.workers -= tileToBuild.WorkerCost;

                buildings.Add(new PlayerTile(tileToBuild, tileId));

                return true;

            }

            return false;
        }
示例#2
0
        public JsonResult Build(TileType.Kind kind, int TileId)
        {
            TileType tileToBuild = RunningGame.TileTypes.Where(e => e.kind.Equals(kind)).First();

            bool buildStarted = PlayerVik.StartBuilding(tileToBuild, TileId);

            var buildresponse = new ClientResponseModels.BuildModel();
            buildresponse.Ok = buildStarted;
            if (buildStarted)
            {
                buildresponse.ImageFile = tileToBuild.ImageFile;
                buildresponse.BuildTimeTicks = tileToBuild.BuildingTime;
                buildresponse.TileId = TileId;
                buildresponse.Kind = kind;
            }

            return Json(buildresponse, JsonRequestBehavior.AllowGet);
        }