Пример #1
0
        public static List <YatzyGame> GetConsecutiveWinsRanking() // hämtar avslutade spel
        {
            List <YatzyGame> gameList = new List <YatzyGame>();

            string stmt = "SELECT game_id, ended_at FROM game WHERE ended_at IS NOT NULL";

            using (var conn = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["dbConn"].ConnectionString))
            {
                conn.Open();
                using (var cmd = new NpgsqlCommand(stmt, conn))
                {
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            YatzyGame game = new YatzyGame
                            {
                                Players = GetGamePlayerStatsList(reader.GetInt32(0)),
                                GameId  = reader.GetInt32(0),
                                EndTime = reader.GetDateTime(1)
                            };
                            gameList.Add(game);
                        }
                    }
                }
            }

            return(gameList);
        }
Пример #2
0
        public static void SetEndGame(YatzyGame game) // avslutar matchen
        {
            string stmt    = "UPDATE game SET ended_at = @endTime WHERE game_id = @gameId";
            string stmtTwo = "UPDATE game_player SET score = @playerScore WHERE game_id = @gameId AND player_id = @playerId";

            using (var conn = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["dbConn"].ConnectionString))
            {
                conn.Open();
                using (var cmd = new NpgsqlCommand(stmt, conn))
                {
                    cmd.Parameters.AddWithValue("endTime", DateTime.Now);
                    cmd.Parameters.AddWithValue("gameId", game.GameId);
                    cmd.ExecuteNonQuery();
                }
                for (int i = 0; i < game.Players.Count; i++)
                {
                    using (var cmd = new NpgsqlCommand(stmtTwo, conn))
                    {
                        cmd.Parameters.AddWithValue("playerScore", game.Players[i].ScoreSheet.TotScore);
                        cmd.Parameters.AddWithValue("gameId", game.GameId);
                        cmd.Parameters.AddWithValue("playerId", game.Players[i].Id);
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }
Пример #3
0
 public GameLogic(int gameId, int gametype)
 {
     game           = new YatzyGame();
     game.Players   = DbOperations.GetGame(gameId);
     game.StartTime = DateTime.Now;
     game.GameId    = gameId;
     game.GameType  = gametype;
     activePlayer   = game.Players[0];
     rnd            = new Random();
     if (game.GameType == 2)
     {
         StartSteeredYatzy();
     }
 }