コード例 #1
0
        public ActionResult Map(int id)
        {
            ApplicationUser user = userRepository.GetUser(User.Identity.GetUserId());
            Game            game = gameRepository.GetGame(id);

            if ((!game.IsBegan || game == null))
            {
                return(RedirectToAction("GameList", "Home"));
            }
            UserGameProperty userGameProperty = userGamePropertyRepository.GetUserGameProperty(user, game);

            if (!userGameProperty.Active || userGameProperty == null)
            {
                return(RedirectToAction("GameList", "Home"));
            }
            CyclicProduct.CalculateGame(id);
            MapViewModel viewModel = new MapViewModel
            {
                Game       = game,
                Property   = userGameProperty,
                Islands    = islandRepository.GetIslandsToMap(game),
                AllPlayers = userGamePropertyRepository.GetAllUserGameProperties(game)
            };

            return(View(viewModel));
        }
コード例 #2
0
        public ActionResult Island(int id)
        {
            ApplicationUser user   = userRepository.GetUser(User.Identity.GetUserId());
            Island          island = islandRepository.GetIsland(id);

            if (!island.Game.PlayerIsActive(user))
            {
                return(RedirectToAction("GameList", "Home"));
            }
            CyclicProduct.CalculateGame(island.Game.Id);
            IslandViewModel viewModel = new IslandViewModel();

            viewModel.EmptyIsland = island.Property == null;
            if (!viewModel.EmptyIsland)
            {
                viewModel.YourIsland = island.Property.Player.Id == user.Id;
                viewModel.Property   = island.Property;
            }
            viewModel.Island = island;
            if (viewModel.YourIsland)
            {
                viewModel.Resources = island.Resources;
            }
            viewModel.Coins     = userGamePropertyRepository.GetUserGameProperty(user, island.Game).Coins;
            viewModel.Buildings = island.Buildings;
            BuildingList buildings = new BuildingList(island);

            if (viewModel.YourIsland)
            {
                viewModel.CalculateMaxBuildings(island, buildings.buildings);
                viewModel.ResourceImages = Resources.ResourceImage();
                viewModel.ResourcesList  = viewModel.Resources.BuildList();
            }
            return(View(viewModel));
        }
コード例 #3
0
 public ActionResult Build([Bind(Include = "Id,Number,Name")] BuildDestroyViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         ApplicationUser user   = userRepository.GetUser(User.Identity.GetUserId());
         Island          island = islandRepository.GetIsland(viewModel.Id);
         if (island != null && island.Property.Player.Id == user.Id)
         {
             CyclicProduct.CalculateGame(island.Game.Id);  // ponowne odświerzanie danych by sprawdzić czy dalej stać użytkownika
             island.Build(viewModel.Name, viewModel.Number);
             gameRepository.Save();
         }
     }
     return(RedirectToAction("Island", new { id = viewModel.Id }));
 }
コード例 #4
0
 public ActionResult Destroy([Bind(Include = "Id,Number,Name")] BuildDestroyViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         ApplicationUser user   = userRepository.GetUser(User.Identity.GetUserId());
         Island          island = islandRepository.GetIsland(viewModel.Id);
         if (island != null && island.Property.Player.Id == user.Id)
         {
             CyclicProduct.CalculateGame(island.Game.Id);
             island.Destroy(viewModel.Name, viewModel.Number);
             gameRepository.Save();
         }
     }
     return(RedirectToAction("Island", new { id = viewModel.Id }));
 }