Example #1
0
 private void SaveGame(BattleshipsServiceLibrary.Game game)
 {
     using (BattleshipsDbEntities bdc = new BattleshipsDbEntities())
     {
         BattleshipsDatabase.Game g = new BattleshipsDatabase.Game();
         g.End    = DateTime.Now;
         g.Winner = game.Winner.PlayerId;
         g.Loser  = game.Opponent(g.Winner).PlayerId;
         g.Start  = game.Start;
         foreach (Move m in game.Moves)
         {
             bdc.Turns.Add(new Turn()
             {
                 Game   = g.GameId,
                 Player = m.Player,
                 Time   = m.Time,
                 Hit    = m.Result == BlockState.HIT,
                 X      = m.AtX,
                 Y      = m.AtY
             });
         }
         bdc.Games.Add(g);
         bdc.SaveChanges();
     }
 }
Example #2
0
 public PlayerContract Register(string name, string password)
 {
     using (BattleshipsDbEntities bdc = new BattleshipsDbEntities())
     {
         if (bdc.Players.AsEnumerable().Where(p => p.Name == name).Count() == 0)
         {
             Player player = new Player {
                 Name = name, Password = password
             };
             bdc.Players.Add(player);
             bdc.SaveChanges();
             return(new PlayerContract(player.PlayerId, player.Name));
         }
     }
     return(null);
 }