コード例 #1
0
ファイル: Save.cs プロジェクト: milensk1/FarcrothuTheGame
        public void SavePlayer(IRepository <IPlayer> players)
        {
            var context = new SpaceShipFarcrothuContext();

            foreach (var player in players.GetAll())
            {
                var playerModel = new PlayerModel()
                {
                    Armor          = player.Armor,
                    BulletDamage   = player.BulletDamage,
                    BulletDelay    = player.BulletDelay,
                    BulletSpeed    = player.BulletSpeed,
                    IsAlive        = player.IsAlive,
                    Level          = player.Level,
                    MaxHealth      = player.MaxHealth,
                    PlayerIdentity = player.Id,
                    PositionX      = player.Position.X,
                    PositionY      = player.Position.Y,
                    Score          = player.Score,
                    Speed          = player.Speed,
                    Health         = player.Health
                };
                context.Players.Add(playerModel);
            }
            context.SaveChanges();
        }
コード例 #2
0
        public string LogIn(string username, string password)
        {
            var context = new SpaceShipFarcrothuContext();

            bool hasUserInDb = context.Users.Any(u => u.Username == username && u.Password == password);

            if (hasUserInDb)
            {
                return(username);
            }

            return(null);
        }
コード例 #3
0
        public State LoadGame(IRepository <IPlayer> players, IRepository <IEnemy> enemies,
                              IRepository <IAsteroid> asteroids, InputHandler handler, UsersRepository users, int gameId)
        {
            if (gameId == 0)
            {
                return(State.LoadGameMenu);
            }
            var context = new SpaceShipFarcrothuContext();
            // var game = context.Users.Where(u => users.GetAll().Contains(u.Username)).Select(u => u.Games);

            var game = context.Games.FirstOrDefault(g => g.Id == gameId);

            foreach (var player in game.Players)
            {
                IPlayer playerEntity = new Player(new Vector2(player.PositionX,
                                                              player.PositionY), handler, player.PlayerIdentity)
                {
                    Armor        = player.Armor,
                    BulletDamage = player.BulletDamage,
                    BulletDelay  = player.BulletDelay,
                    BulletSpeed  = player.BulletSpeed,
                    MaxHealth    = player.MaxHealth,
                    IsAlive      = player.IsAlive,
                    Score        = player.Score,
                    Speed        = player.Speed,
                    Level        = player.Level
                };

                playerEntity.Health = player.Health - 100;

                players.AddEntity(playerEntity);
            }
            foreach (var enemy in game.Enemies)
            {
                IEnemy enemyEntity = new GameObjects.Enemy(new Vector2(enemy.PositionX, enemy.PositionY));
                enemies.AddEntity(enemyEntity);
            }
            foreach (var asteroid in game.Asteroids)
            {
                IAsteroid asteroidEntity = new GameObjects.Asteroid(new Vector2(asteroid.PositionX,
                                                                                asteroid.PositionY));
                asteroids.AddEntity(asteroidEntity);
            }
            return(State.OnePlayer);
        }
コード例 #4
0
        public string RegisterUser(ICollection <string> forms)
        {
            var    context           = new SpaceShipFarcrothuContext();
            string username          = string.Empty;
            string password          = string.Empty;
            string confirmedPassword = string.Empty;

            foreach (var form in forms)
            {
                string[] userInfo = form.Split(new char[] { ' ' }, 2);

                if (userInfo[0] == "Username:"******"Password:"******"ConfirmPassword:")
                {
                    confirmedPassword = userInfo[1];
                }
            }

            bool isUsernameFree = !context.Users.Any(u => u.Username == username);

            if (password == confirmedPassword && isUsernameFree)
            {
                var user = new UserModel
                {
                    Username = username,
                    Password = password
                };

                context.Users.Add(user);
                context.SaveChanges();
                return(username);
            }
            return(null);
        }
コード例 #5
0
 public SaveAndLoadDbManager()
 {
     this.context = new SpaceShipFarcrothuContext();
 }
コード例 #6
0
 public UsersRepository()
 {
     this.users   = new HashSet <User>();
     this.context = new SpaceShipFarcrothuContext();
 }