Ejemplo n.º 1
0
Archivo: User.cs Proyecto: Rep2/Life
        /// <summary>
        /// Checks if user has enaugh resources to start research
        /// </summary>
        /// <param name="researchLevel">Research to be checked</param>
        /// <returns>True if user has enaughr resources, false otherwise</returns>
        public bool UserHasResourcesForResearch(ResearchLevel researchLevel)
        {
            var costs = researchLevel.ResearchCosts;

            foreach (ResearchCost 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;
        }
Ejemplo n.º 2
0
Archivo: User.cs Proyecto: Rep2/Life
        public bool UserHasRequirmentsForResearch(ResearchLevel researchLevel)
        {
            if (ResearchedResearchs == null)
            {
                ResearchedResearchs = new List<ResearchedResearch>();
            }

            // Checks if lower level buildings exists
            if (researchLevel.Level != 1)
            {
                for (int i = 1; i < researchLevel.Level; i++)
                {
                    var lowerLvlResesearch = ResearchedResearchs.Where(
                        b => b.ResearchLevel.Research.Id == researchLevel.Research.Id
                        && b.ResearchLevel.Level == i);

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

            // Checks if same level building exists
            var sameLvlResearch = ResearchedResearchs.Where(
                        b => b.ResearchLevel.Research.Id == researchLevel.Research.Id
                        && b.ResearchLevel.Level == researchLevel.Level);

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

            return true;
        }
Ejemplo n.º 3
0
Archivo: Planet.cs Proyecto: Rep2/Life
        public void AddResearch(ResearchLevel researchLevel)
        {

        }
Ejemplo n.º 4
0
Archivo: DBTest.cs Proyecto: Rep2/Life
        public void UserHasEnaughResourcesForResearchFalse()
        {
            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 researchLevel = new ResearchLevel()
            {
                Level = 1,
                ResearchCosts = new List<ResearchCost>(){
                    new ResearchCost(){
                        Resource = metal,
                        Value = 500
                    },
                    new ResearchCost(){
                        Resource = carbon,
                        Value = 200
                    }
                }
            };

            Assert.False(user.UserHasResourcesForResearch(researchLevel));
        }
Ejemplo n.º 5
0
Archivo: Planet.cs Proyecto: Rep2/Life
        public bool StartResearch(ResearchLevel researchLevel)
        {
            if (User == null)
            {
                return false;
            }
            else
            {
                if (!User.UserHasResourcesForResearch(researchLevel))
                {
                    return false;
                }
            }

            if (!User.UserHasRequirmentsForResearch(researchLevel))
            {
                return false;
            }

            CurrentlyResearching = new CurrentlyResearching()
            {
                ResearchLevel = researchLevel,
                ResearchStart = DateTime.Now
            };

            return true;
        }