示例#1
0
        public Structure(StructureType structureType, int _floor)
        {
            IronTowerDBContext db = new IronTowerDBContext();

            //   Game game = db.Games.FirstOrDefault();
            //    this.Game = game;

            switch (structureType)
            {
                case StructureType.Laundry:
                    this.Floor = _floor;
                    this.Income = 1;
                    this.InitialCost = 1;
                    this.IsResidence = false;
                    this.PopulationCost = 1;
                    this.SupportedPopulation = 0;
                    this.Type = StructureType.Laundry;
                    this.UpKeep = 1;
                    break;

                case StructureType.Restaurant:
                    this.Floor = _floor;
                    this.Income = 2;
                    this.InitialCost = 1;
                    this.IsResidence = false;
                    this.PopulationCost = 3;
                    this.SupportedPopulation = 0;
                    this.Type = StructureType.Restaurant;
                    this.UpKeep = 1;
                    break;

                case StructureType.AmusementPark:
                    this.Floor = _floor;
                    this.Income = 3;
                    this.InitialCost = 3;
                    this.IsResidence = false;
                    this.PopulationCost = 1;
                    this.SupportedPopulation = 0;
                    this.Type = StructureType.AmusementPark;
                    this.UpKeep = 1;
                    break;

                case StructureType.Residence:
                    this.Floor = _floor;
                    this.Income = 0;
                    this.InitialCost = 1;
                    this.IsResidence = true;
                    this.PopulationCost = 0;
                    this.SupportedPopulation = 5;
                    this.Type = StructureType.Residence;
                    this.UpKeep = 1;
                    break;

                default:
                    break;
            }
        }
示例#2
0
        public static bool PurchaseBuilding(int currencyRequired, int populationNeeded, Structure.StructureType strucureType)
        {
            IronTowerDBContext db = new IronTowerDBContext();
            Game game = db.Games.FirstOrDefault();
            if (game.TotalBalance < currencyRequired)
            { return false; }
            if (game.TotalPopulation(game) - game.ConsumedPopulation(game) < populationNeeded)
            { return false; }
            game.TotalBalance -= currencyRequired;

            Structure structure = new Structure(strucureType, game.TotalFloors(game) + 1);
            game.Structures.Add(structure);
            game.PeriodicRevenue += structure.Income;
            db.SaveChanges();
            return true;
        }