Esempio n. 1
0
        //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();
        }
Esempio n. 2
0
        public void CreateGame(Game game, ApplicationUser user)
        {
            UserGamePropertyRepository userGamePropertyRepository = new UserGamePropertyRepository();

            game.CreateDate = DateTime.Now;
            game.Update     = DateTime.Now;
            game.IsBegan    = false;
            game.Players    = new List <ApplicationUser> {
                user
            };
            game.UserGameProperties = new List <UserGameProperty> {
                userGamePropertyRepository.CreateUserGameProperty(user, 0)
            };
            db.Games.Add(game);
            db.SaveChanges();
        }