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)); }
public void Deactive(Game game, ApplicationUser user) { UserGameProperty userGameProperty = GetUserGameProperty(user, game); userGameProperty.Active = false; db.SaveChanges(); }
//dodanie gracza do gry, jeżeli gra jest pełna to wystartuj public void AddUserToGame(ApplicationUser user, Game game) { game.Players.Add(user); UserGameProperty userGameProperty = userGamePropertyRepository.CreateUserGameProperty(user, game.NumberOfPlayers() - 1); game.UserGameProperties.Add(userGameProperty); db.SaveChanges(); if (game.NumberOfPlayers() == game.MaxPlayers) { List <UserGameProperty> properties = userGamePropertyRepository.GetAllUserGameProperties(game); List <Island> islands = game.InitializeGame(properties); islandRepository.AddIslands(islands); } db.SaveChanges(); }
public List <Island> GetAllIslands(Game game, ApplicationUser user) { UserGameProperty userGameProperty = userGamePropertyRepository.GetUserGameProperty(user, game); return(db.Islands.Where(a => a.Property.Id == userGameProperty.Id).ToList()); }
public void RemoveUserGameProperty(ApplicationUser user, Game game) { UserGameProperty userGameProperty = db.UserGameProperties.Where(a => a.Player.Id == user.Id).Where(b => b.Game.Id == game.Id).FirstOrDefault(); db.UserGameProperties.Remove(userGameProperty); }