public void add(card newCard) { string valToAdd = newCard.getValue(); cards.Add(newCard); if (valToAdd.All(char.IsDigit)) { value += Int32.Parse(valToAdd); } else if ((valToAdd.Equals("Q")) || (valToAdd.Equals("K")) || (valToAdd.Equals("J"))) { value += 10; } else if (valToAdd.Equals("A")) { if (value + 11 <= 21) { value += 11; newCard.aceHigh = true; } else { value += 1; newCard.aceHigh = false; } } if (value > 21) { recomputeValue(); } }
public void populate() { cards[0] = new card("2", "C"); cards[1] = new card("2", "D"); cards[2] = new card("2", "H"); cards[3] = new card("2", "S"); cards[4] = new card("3", "C"); cards[5] = new card("3", "D"); cards[6] = new card("3", "H"); cards[7] = new card("3", "S"); cards[8] = new card("4", "C"); cards[9] = new card("4", "D"); cards[10] = new card("4", "H"); cards[11] = new card("4", "S"); cards[12] = new card("5", "C"); cards[13] = new card("5", "D"); cards[14] = new card("5", "H"); cards[15] = new card("5", "S"); cards[16] = new card("6", "C"); cards[17] = new card("6", "D"); cards[18] = new card("6", "H"); cards[19] = new card("6", "S"); cards[20] = new card("7", "C"); cards[21] = new card("7", "D"); cards[22] = new card("7", "H"); cards[23] = new card("7", "S"); cards[24] = new card("8", "C"); cards[25] = new card("8", "D"); cards[26] = new card("8", "H"); cards[27] = new card("8", "S"); cards[28] = new card("9", "C"); cards[29] = new card("9", "D"); cards[30] = new card("9", "H"); cards[31] = new card("9", "S"); cards[32] = new card("J", "C"); cards[33] = new card("J", "D"); cards[34] = new card("J", "H"); cards[35] = new card("J", "S"); cards[36] = new card("Q", "C"); cards[37] = new card("Q", "D"); cards[38] = new card("Q", "H"); cards[39] = new card("Q", "S"); cards[40] = new card("K", "C"); cards[41] = new card("K", "D"); cards[42] = new card("K", "H"); cards[43] = new card("K", "S"); cards[44] = new card("10", "C"); cards[45] = new card("10", "D"); cards[46] = new card("10", "H"); cards[47] = new card("10", "S"); cards[48] = new card("A", "C"); cards[49] = new card("A", "D"); cards[50] = new card("A", "H"); cards[51] = new card("A", "S"); currentIndex = 0; }
//the same as the previous one but for the computer and not the player private void lose() { card temp = ai.list[0]; ai.list.RemoveAt(0); ai.list.Add(temp); ai.list.Add(player.list[0]); player.list.RemoveAt(0); update_values(); }
//posiible outcomes #region out_comes //give the players the computers card and adds it to the back with the players first card private void win() { card temp = player.list[0]; player.list.RemoveAt(0); player.list.Add(temp); player.list.Add(ai.list[0]); ai.list.RemoveAt(0); update_values(); }
// each players card gets returned to the back of the list private void draw() { card temp = ai.list[0]; ai.list.RemoveAt(0); ai.list.Add(temp); temp = player.list[0]; player.list.RemoveAt(0); player.list.Add(temp); update_values(); }
public void shuffle() { Random rnd = new Random(); for (int i = 0; i < 52; i++) { int randCard = rnd.Next(52); card temp = cards[i]; cards[i] = cards[randCard]; cards[randCard] = temp; } currentIndex = 0; }
private List <card> create_deck() { List <card> card_list = new List <card>(); //read in the card data string[] details = File.ReadAllText(resources.location + "\\Content\\card_list.txt").Split(' '); //create all of the cards for (int i = 0; i < details.Length / 6; i++) { card new_card = new card(); new_card.name = details[i * 6]; new_card.smite = Convert.ToInt32(details[i * 6 + 1]); new_card.defence = Convert.ToInt32(details[i * 6 + 2]); new_card.followers = Convert.ToInt32(details[i * 6 + 3]); new_card.cruelty = Convert.ToInt32(details[i * 6 + 4]); new_card.forgiveness = Convert.ToInt32(details[i * 6 + 5]); card_list.Add(new_card); } return(card_list); }
//choose what category to use depending on the difficulty public int choose_type(card temp_card) { //on easy a random category is chosen if (resources.difficulty == 0) { temp = rnd.Next(1, 6); return(temp); } //on hard the highest value is chosen if (resources.difficulty == 1) { if ((temp_card.smite > temp_card.defence) && (temp_card.smite > temp_card.followers) && (temp_card.smite > temp_card.cruelty) && (temp_card.smite > temp_card.forgiveness)) { big1 = 1; } else if ((temp_card.defence > temp_card.smite) && (temp_card.defence > temp_card.followers) && (temp_card.defence > temp_card.cruelty) && (temp_card.defence > temp_card.forgiveness)) { big1 = 2; } else if ((temp_card.followers > temp_card.smite) && (temp_card.followers > temp_card.defence) && (temp_card.followers > temp_card.cruelty) && (temp_card.followers > temp_card.forgiveness)) { big1 = 3; } else if ((temp_card.cruelty > temp_card.smite) && (temp_card.cruelty > temp_card.defence) && (temp_card.cruelty > temp_card.followers) && (temp_card.cruelty > temp_card.forgiveness)) { big1 = 4; } else if ((temp_card.forgiveness > temp_card.smite) && (temp_card.forgiveness > temp_card.defence) && (temp_card.forgiveness > temp_card.followers) && (temp_card.forgiveness > temp_card.cruelty)) { big1 = 5; } else { big1 = 1; } return(big1); } return(0); }