Exemplo n.º 1
0
 private void AddGameToDB(Game game)
 {
     using (MinesweeperDataBaseEntities ctx = new MinesweeperDataBaseEntities()) {
         game.Id = (from g in ctx.Games select g.Id).Max() + 1;
         ctx.Games.Add(game);
     }
 }
Exemplo n.º 2
0
 public bool IsLegalUser(string username, string password)
 {
     using (MinesweeperDataBaseEntities ctx = new MinesweeperDataBaseEntities()) {
         return((from p in ctx.Players
                 where p.UserName == username && p.Password == password
                 select p.UserName).ToList().Count != 0);
     }
 }
Exemplo n.º 3
0
 public bool PlayerExists(string username)
 {
     using (MinesweeperDataBaseEntities ctx = new MinesweeperDataBaseEntities()) {
         return((from p in ctx.Players
                 where p.UserName == username
                 select p.UserName).ToList().Count != 0);
     }
 }
Exemplo n.º 4
0
 public void EnterPlayerToDB(Player player)
 {
     using (MinesweeperDataBaseEntities ctx = new MinesweeperDataBaseEntities()) {
         if (PlayerExists(player.UserName))
         {
             throw new FaultException <UserExistsFault>(
                       new UserExistsFault {
                 Message = player.UserName + " already exists"
             }, new FaultReason(player.UserName + " already exists"));
         }
         else
         {
             ctx.Players.Add(player);
             ctx.SaveChanges();
         }
     }
 }
Exemplo n.º 5
0
        public List <string[]> GetAllGames()
        {
            List <string[]> allGames = new List <string[]>();

            using (MinesweeperDataBaseEntities ctx = new MinesweeperDataBaseEntities()) {
                foreach (Game game in ctx.Games.ToList())
                {
                    string[] gameStats = new string[4];
                    gameStats[0] = game.GameDate.ToString();
                    gameStats[1] = game.Winner;
                    gameStats[2] = game.Loser;
                    gameStats[3] = game.Tie ? "YEAH" : "NOPE";

                    allGames.Add(gameStats);
                }
                return(allGames);
            }
        }
Exemplo n.º 6
0
        public List <string[]> GetAllPlayers()
        {
            List <string[]> allPlayerStats = new List <string[]>();

            using (MinesweeperDataBaseEntities ctx = new MinesweeperDataBaseEntities()) {
                foreach (Player p in ctx.Players.ToList())
                {
                    {
                        string[] playerStats = new string[6];
                        var      gamesWon    = (from g in ctx.Games
                                                where g.Winner == p.UserName
                                                select g).ToList().Count;
                        var gamesLost = (from g in ctx.Games
                                         where g.Loser == p.UserName
                                         select g).ToList().Count;

                        var gamesTied = (from g in ctx.Games where g.Tie &&
                                         (g.Winner == p.UserName) || (g.Loser == p.UserName)
                                         select g).ToList().Count;
                        var totalGames = gamesWon + gamesLost + gamesTied;

                        var winPercent = totalGames == 0 ? 0 : (double)gamesWon / totalGames;

                        playerStats[0] = p.UserName;
                        playerStats[1] = gamesWon.ToString();
                        playerStats[2] = gamesLost.ToString();
                        playerStats[3] = gamesTied.ToString();
                        playerStats[4] = totalGames.ToString();
                        playerStats[5] = winPercent.ToString();

                        allPlayerStats.Add(playerStats);
                    }
                }
            }
            return(allPlayerStats);
        }