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(); }
public void SaveGame(IRepository <IPlayer> players, IRepository <IEnemy> enemies, IRepository <IAsteroid> asteroids, UsersRepository users) { var game = new GameModel(); foreach (var user in users.GetAll()) { game.Users.Add(this.context.Users.FirstOrDefault(u => u.Username == user)); } 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 }; game.Players.Add(playerModel); } foreach (var enemy in enemies.GetAll()) { var enemyModel = new EnemyModel() { PositionX = enemy.Position.X, PositionY = enemy.Position.Y }; game.Enemies.Add(enemyModel); } foreach (var asteroid in asteroids.GetAll()) { var asteroidModel = new AsteroidModel() { PositionX = asteroid.Position.X, PositionY = asteroid.Position.Y }; game.Asteroids.Add(asteroidModel); } context.Games.Add(game); context.SaveChanges(); }
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); }