Example #1
0
        public BuildingDetails(BuildingLevel buildingLevel, BuildingDetailController controller)
        {
            this.buildingLevel = buildingLevel;
            this.controller = controller;

            controller.view = this;

            InitializeComponent();
        }
Example #2
0
File: User.cs Project: Rep2/Life
        /// <summary>
        /// Adds resource for building
        /// </summary>
        /// <param name="buildingLevel"></param>
        public void AddResourceForBuild(BuildingLevel buildingLevel)
        {
            var costs = buildingLevel.BuildingCosts;

            foreach (BuildingCost cost in costs)
            {
                //Check if user has enaugh resources
                var userResource = UserResources.Where(b => b.Resource.Id == cost.Resource.Id);

                userResource.First().Amount += cost.Value;
            }
        }
Example #3
0
File: User.cs Project: Rep2/Life
        /// <summary>
        /// Checks if user has enaugh resource to build building
        /// </summary>
        /// <param name="buildingLevel">Building to be checked</param>
        /// <returns>True if user has enaughr resources, false otherwise</returns>
        public bool UserHasReseourceForBuild(BuildingLevel buildingLevel){

            var costs = buildingLevel.BuildingCosts;

            foreach (BuildingCost cost in costs)
            {
                //Check if user has enaugh resources
                var userResource = UserResources.Where(b => b.Resource.Id == cost.Resource.Id);
                if (userResource.Count() == 0 || userResource.First().Amount < cost.Value)
                {
                    return false;
                }
            }

            return true;
        }
Example #4
0
File: Planet.cs Project: Rep2/Life
        public bool BuildBuilding(BuildingLevel buildingLevel)
        {
            if (User == null)
            {
                return false;
            }
            else
            {
                if (!User.UserHasReseourceForBuild(buildingLevel))
                {
                    return false;
                }
            }

            if (!StartBuildingBuilding(buildingLevel))
            {
                return false;
            }

            return true;
        }
Example #5
0
File: Planet.cs Project: Rep2/Life
        /// <summary>
        /// Start build of building level if all requirments are met
        /// </summary>
        /// <param name="buildingLevel">Building level to be built</param>
        /// <returns>True if building started, false otherwise</returns>
        public bool StartBuildingBuilding(BuildingLevel buildingLevel)
        {
            RefreshBuildingBuildState();

            if (CurrentlyBuilding != null)
            {
                return false;
            }

            if (!PlanetHasAllRequirmentsForBuilding(buildingLevel))
            {
                return false;
            }

            CurrentlyBuilding = new CurrentlyBuilding()
            {
                BuildingLevel = buildingLevel,
                BuildingStart = DateTime.Now
            };

            return true;
        }
Example #6
0
        public void ViewDidLoad(BuildingLevel buildingLevel)
        {
            var costs = new List<ResourceViewModel>();

            foreach (BuildingCost cost in buildingLevel.BuildingCosts)
            {
                costs.Add(
                    new ResourceViewModel()
                    {
                        Name = cost.Resource.Name,
                        Value = cost.Value
                    }
                    );
            }

            var binding = new BindingSource();
            binding.DataSource = costs;

            var modifiers = new List<BuildingFactorModifierViewModel>();

            foreach (BuildingFactorModifier modifier in buildingLevel.BuildingFactorModifiers)
            {

                modifiers.Add(
                    new BuildingFactorModifierViewModel()
                    {
                        FactorName = modifier.Factor.Name,
                        Value = modifier.Value
                    }
                    );
            }

            var modifierBinding = new BindingSource();
            modifierBinding.DataSource = modifiers;

            view.SetData(binding, modifierBinding);
        }
Example #7
0
File: DBTest.cs Project: Rep2/Life
        public void UserBuildingCreateFalse()
        {
            Program.SetSessionFactory(true);
            Program.CreateData();

            var authRepo = new AuthorisationRepository();

            var user = authRepo.CreateUser(Create());

            Assert.NotNull(user);

            var resorceRepository = new Repository<Resource>();
            var metal = resorceRepository.Get(new Dictionary<string, string>() { { "Name", "Metal" } }).First();
            var carbon = resorceRepository.Get(new Dictionary<string, string>() { { "Name", "Carbon" } }).First();


            var buildingLevel = new BuildingLevel()
            {
                Level = 1,
                BuildingCosts = new List<BuildingCost>(){
                    new BuildingCost(){
                        Resource = metal,
                        Value = 100
                    },
                    new BuildingCost(){
                        Resource = carbon,
                        Value = 400
                    }
                }
            };

            Assert.False(user.UserHasReseourceForBuild(buildingLevel));
        }
Example #8
0
File: Planet.cs Project: Rep2/Life
        /// <summary>
        /// Checks if all previous levels are built and current level not built
        /// </summary>
        /// <param name="buildingLevel">Building that is checked</param>
        /// <returns>True if building can be built</returns>
        public bool PlanetHasAllRequirmentsForBuilding(BuildingLevel buildingLevel){
            
            if (BuiltBuildings == null)
            {
                BuiltBuildings = new List<BuiltBuilding>();
            }

            // Checks if lower level buildings exists
            if (buildingLevel.Level != 1)
            {
                for (int i = 1; i < buildingLevel.Level; i++)
                {
                    var lowerLvlBuilding = BuiltBuildings.Where(
                        b => b.BuildingLevel.Building.Id == buildingLevel.Building.Id
                        && b.BuildingLevel.Level == i);

                    if (lowerLvlBuilding.Count() == 0)
                    {
                        return false;
                    }
                }
            }

            // Checks if same level building exists
            var sameLvlBuilding = BuiltBuildings.Where(
                        b => b.BuildingLevel.Building.Id == buildingLevel.Building.Id
                        && b.BuildingLevel.Level == buildingLevel.Level);

            if (sameLvlBuilding.Count() != 0)
            {
                return false;
            }

            return true;
        }
Example #9
0
File: Planet.cs Project: Rep2/Life
        /// <summary>
        /// Adds built building with level to planet while checking all requirments
        /// </summary>
        /// <param name="buildingLevel">Building level to be added</param>
        /// <returns>True if building added, false otherwise</returns>
        public bool AddBuilding(BuildingLevel buildingLevel)
        {
            if (!PlanetHasAllRequirmentsForBuilding(buildingLevel)){
                return false;            
            }
            
            // Adds the building
            BuiltBuildings.Add(
                new BuiltBuilding()
                {
                    BuildingLevel = buildingLevel,
                    Planet = this
                }
            );

            return true;
        }
Example #10
0
        private void UpdateBuildingState(Object myObject, EventArgs myEventArgs)
        {
            buildingTimeLeft -= 1;

            if (buildingTimeLeft <= 0)
            {
                dataGridView3.Columns[8].Visible = false;
                dataGridView3.Columns[9].Visible = false;
                timer.Tick -= buildingEventHandler;
                dataGridView3.Rows[currentRow].Cells[8].Value = "";

                user.Planets.First().RefreshBuildingBuildState();

                var repo = new Repository<Planet>();
                repo.Update(user.Planets.First());

                currentlyBuilding = null;

                PresentBuildings();
            }
            else
            {
                dataGridView3.Rows[currentRow].Cells[8].Value = buildingTimeLeft.ToString();
            }
        }
Example #11
0
        private void cancleBuild()
        {

            user.Planets.First().StopBuilding();
            user.AddResourceForBuild(currentlyBuilding);

            currentlyBuilding = null;

            dataGridView3.Columns[8].Visible = false;
            dataGridView3.Columns[9].Visible = false;
            timer.Tick -= buildingEventHandler;
            dataGridView3.Rows[currentRow].Cells[8].Value = "";

            PresentBuildings();
        }
Example #12
0
        private void startBuilding(int row)
        {
            if (currentlyBuilding != null)
            {
                MessageBox.Show("Building already being built. Wait for it to finish");
            }
            else
            {
                currentlyBuilding = buildings.ElementAt(row);

                if (!user.UserHasReseourceForBuild(currentlyBuilding))
                {
                    MessageBox.Show("You do not have enaugh resource for the build");
                    currentlyBuilding = null;
                }
                else
                {
                    DialogResult dialog = MessageBox.Show("Do you want to build " + currentlyBuilding.Building.Name + ", level " + currentlyBuilding.Level, "Yes", MessageBoxButtons.YesNo);

                    if (dialog == DialogResult.Yes)
                    {
                        user.Planets.First().StartBuildingBuilding(currentlyBuilding);
                        user.RemoveResourceForBuild(currentlyBuilding);

                        currentRow = row;
                        buildingTimeLeft = currentlyBuilding.BuildDuration;

                        dataGridView3.Columns[8].Visible = true;
                        dataGridView3.Columns[9].Visible = true;
                        dataGridView3.Rows[row].Cells[8].Value = buildingTimeLeft.ToString();

                        timer.Tick += buildingEventHandler;
                    }
                    else
                    {
                        currentlyBuilding = null;
                    }
                }
            }
            
        }