Exemple #1
0
        //not tested/used yet
        //probably needs to check hand_id as well
        public List <Card> GetAllCardsForPlayer(string username, int handID)
        {
            List <Card> output = new List <Card>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand("SELECT card_number, card_suit FROM hand_cards WHERE player = @player AND hand_id = @handID;", conn);
                    cmd.Parameters.AddWithValue("@player", username);
                    cmd.Parameters.AddWithValue("@handID", handID);
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Card c = new Card();

                        c.Number = Convert.ToInt32(reader["card_number"]);
                        c.Suit   = Convert.ToString(reader["card_suit"]);

                        output.Add(c);
                    }
                }
            }
            catch (SqlException)
            {
                throw;
            }

            return(DeckOfCards.GetSuitAndLetterValues(output));
        }
Exemple #2
0
        public List <Card> DrawCards(int handID, int numberToDraw, string player)
        {
            List <Card> output = new List <Card>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand($"SELECT TOP {numberToDraw} * FROM hand_card_deck WHERE hand_id = @handID AND dealt = 0 ORDER BY deck_position ASC;", conn);
                    cmd.Parameters.AddWithValue("@handID", handID);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Card c = new Card();

                        c.Number = Convert.ToInt32(reader["card_number"]);
                        c.Suit   = Convert.ToString(reader["card_suit"]);
                        output.Add(c);
                    }
                    reader.Close();

                    foreach (Card card in output)
                    {
                        cmd = new SqlCommand("INSERT INTO hand_cards VALUES (@handID, @player, @number, @suit, 1, 0);", conn);
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@handID", handID);
                        cmd.Parameters.AddWithValue("@player", player);
                        cmd.Parameters.AddWithValue("@number", card.Number);
                        cmd.Parameters.AddWithValue("@suit", card.Suit);
                        cmd.ExecuteNonQuery();

                        cmd.CommandText = "UPDATE hand_card_deck SET dealt = 1 WHERE hand_id = @handID AND card_number = @number AND card_suit = @suit";
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("@handID", handID);
                        cmd.Parameters.AddWithValue("@player", player);
                        cmd.Parameters.AddWithValue("@number", card.Number);
                        cmd.Parameters.AddWithValue("@suit", card.Suit);
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (SqlException)
            {
                throw;
            }

            output = DeckOfCards.GetSuitAndLetterValues(output);
            return(output);
        }