// parameters: card, and an int: 0 = mycard1, 1 = mycard2, 2 = mycard3, 3 = mycard4. // 4 = housecard1, 5 = housecard2, 6 = housecard3, 7 = housecard4 public Card aceTest(Card card, int which) { Console.Out.WriteLine ("Ace test: which: " + which + ". " + card.getRank () + " of " + card.getSuit ()); // first some error handling if(which < 0 || which > 7) { Console.Out.WriteLine("AceTest: Not a real card."); return card; } // now set it to an 11 and update the count card.setNumericalRank (11); updateCount (); // see if an 11 will bust if(which == 0 || which == 1 || which == 2 || which == 3) { if(checkBust()) { card.setNumericalRank (1); } } else if(which == 4 || which == 5 || which == 6 || which == 7) { if(checkHouseBust()) { card.setNumericalRank (1); } } Console.Out.WriteLine("ace test final result: which: " + which + ". " + card.getRank () + " of " + card.getSuit ()); return card; }
// remove a card from the deck (in the case of being dealt) public void removeCard(Card card) { if(card.getSuit() == "spades") { switch(card.getRank()) { case("ace"): this.aceSpades = null; break; case("two"): this.twoSpades = null; break; case("three"): this.threeSpades = null; break; case("four"): this.fourSpades = null; break; case("five"): this.fiveSpades = null; break; case("six"): this.sixSpades = null; break; case("seven"): this.sevenSpades = null; break; case("eight"): this.eightSpades = null; break; case("nine"): this.nineSpades = null; break; case("ten"): this.tenSpades = null; break; case("jack"): this.jackSpades = null; break; case("queen"): this.queenSpades = null; break; case("king"): this.kingSpades = null; break; default: Console.Out.WriteLine ("Remove Card Error: " + card.getRank () + " " + card.getSuit ()); break; } } else if(card.getSuit() == "clubs") { switch(card.getRank()) { case("ace"): this.aceClubs = null; break; case("two"): this.twoClubs = null; break; case("three"): this.threeClubs = null; break; case("four"): this.fourClubs = null; break; case("five"): this.fiveClubs = null; break; case("six"): this.sixClubs = null; break; case("seven"): this.sevenClubs = null; break; case("eight"): this.eightClubs = null; break; case("nine"): this.nineClubs = null; break; case("ten"): this.tenClubs = null; break; case("jack"): this.jackClubs = null; break; case("queen"): this.queenClubs = null; break; case("king"): this.kingClubs = null; break; default: Console.Out.WriteLine ("Remove Card Error: " + card.getRank () + " " + card.getSuit ()); break; } } else if(card.getSuit() == "diamonds") { switch(card.getRank()) { case("ace"): this.aceDiamonds = null; break; case("two"): this.twoDiamonds = null; break; case("three"): this.threeDiamonds = null; break; case("four"): this.fourDiamonds = null; break; case("five"): this.fiveDiamonds = null; break; case("six"): this.sixDiamonds = null; break; case("seven"): this.sevenDiamonds = null; break; case("eight"): this.eightDiamonds = null; break; case("nine"): this.nineDiamonds = null; break; case("ten"): this.tenDiamonds = null; break; case("jack"): this.jackDiamonds = null; break; case("queen"): this.queenDiamonds = null; break; case("king"): this.kingDiamonds = null; break; default: Console.Out.WriteLine ("Remove Card Error: " + card.getRank () + " " + card.getSuit ()); break; } } else if(card.getSuit() == "hearts") { switch(card.getRank()) { case("ace"): this.aceHearts = null; break; case("two"): this.twoHearts = null; break; case("three"): this.threeHearts = null; break; case("four"): this.fourHearts = null; break; case("five"): this.fiveHearts = null; break; case("six"): this.sixHearts = null; break; case("seven"): this.sevenHearts = null; break; case("eight"): this.eightHearts = null; break; case("nine"): this.nineHearts = null; break; case("ten"): this.tenHearts = null; break; case("jack"): this.jackHearts = null; break; case("queen"): this.queenHearts = null; break; case("king"): this.kingHearts = null; break; default: Console.Out.WriteLine ("Rank Remove Card Error: " + card.getRank () + " " + card.getSuit ()); break; } } else { Console.Out.WriteLine ("Suit Remove Card Error: " + card.getRank() + " " + card.getSuit ()); } this.isFull = false; this.remaining--; }
// function to pick a random card and deal it // eventually this should return a card public Card dealCard() { Random random = new Random (); int randCardRank = random.Next(52); // random number between 0 and 51 to use when picking a random card //Console.Out.WriteLine ("random number: " + randCardRank); Card returnCard = new Card("the angel's card", "king of heaven", 777); try { // now pick a card in the deck and make it null // this is gonna be a nightmare switch(randCardRank) { case 0: this.aceSpades = null; returnCard = new Card ("spades", "ace", 0); break; case 1: this.twoSpades = null; returnCard = new Card ("spades", "two", 1); break; case 2: this.threeSpades = null; returnCard = new Card ("spades", "three", 2); break; case 3: this.fourSpades = null; returnCard = new Card ("spades", "four", 3); break; case 4: this.fiveSpades = null; returnCard = new Card ("spades", "five", 4); break; case 5: this.sixSpades = null; returnCard = new Card ("spades", "six", 5); break; case 6: this.sevenSpades = null; returnCard = new Card ("spades", "seven", 6); break; case 7: this.eightSpades = null; returnCard = new Card ("spades", "eight", 7); break; case 8: this.nineSpades = null; returnCard = new Card ("spades", "nine", 8); break; case 9: this.tenSpades = null; returnCard = new Card ("spades", "ten", 9); break; case 10: this.jackSpades = null; returnCard = new Card ("spades", "jack", 10); break; case 11: this.queenSpades = null; returnCard = new Card ("spades", "queen", 11); break; case 12: this.kingSpades = null; returnCard = new Card ("spades", "king", 12); break; case 13: this.aceClubs = null; returnCard = new Card ("clubs", "ace", 13); break; case 14: this.twoClubs = null; returnCard = new Card ("clubs", "two", 14); break; case 15: this.threeClubs = null; returnCard = new Card ("clubs", "three", 15); break; case 16: this.fourClubs = null; returnCard = new Card ("clubs", "four", 16); break; case 17: this.fiveClubs = null; returnCard = new Card ("clubs", "five", 17); break; case 18: this.sixClubs = null; returnCard = new Card ("clubs", "six", 18); break; case 19: this.sevenClubs = null; returnCard = new Card ("clubs", "seven", 19); break; case 20: this.eightClubs = null; returnCard = new Card ("clubs", "eight", 20); break; case 21: this.nineClubs = null; returnCard = new Card ("clubs", "nine", 21); break; case 22: this.tenClubs = null; returnCard = new Card ("clubs", "ten", 22); break; case 23: this.jackClubs = null; returnCard = new Card ("clubs", "jack", 23); break; case 24: this.queenClubs = null; returnCard = new Card ("clubs", "queen", 24); break; case 25: this.kingClubs = null; returnCard = new Card ("clubs", "king", 25); break; case 26: this.aceDiamonds = null; returnCard = new Card ("diamonds", "ace", 26); break; case 27: this.twoDiamonds = null; returnCard = new Card ("diamonds", "two", 27); break; case 28: this.threeDiamonds = null; returnCard = new Card ("diamonds", "three", 28); break; case 29: this.fourDiamonds = null; returnCard = new Card ("diamonds", "four", 29); break; case 30: this.fiveDiamonds = null; returnCard = new Card ("diamonds", "five", 30); break; case 31: this.sixDiamonds = null; returnCard = new Card ("diamonds", "six", 31); break; case 32: this.sevenDiamonds = null; returnCard = new Card ("diamonds", "seven", 32); break; case 33: this.eightDiamonds = null; returnCard = new Card ("diamonds", "eight", 33); break; case 34: this.nineDiamonds = null; returnCard = new Card ("diamonds", "nine", 34); break; case 35: this.tenDiamonds = null; returnCard = new Card ("diamonds", "ten", 35); break; case 36: this.jackDiamonds = null; returnCard = new Card ("diamonds", "jack", 36); break; case 37: this.queenDiamonds = null; returnCard = new Card ("diamonds", "queen", 37); break; case 38: this.kingDiamonds = null; returnCard = new Card ("diamonds", "king", 38); break; case 39: this.aceHearts = null; returnCard = new Card ("hearts", "ace", 39); break; case 40: this.twoHearts = null; returnCard = new Card ("hearts", "two", 40); break; case 41: this.threeHearts = null; returnCard = new Card ("hearts", "three", 41); break; case 42: this.fourHearts = null; returnCard = new Card ("hearts", "four", 42); break; case 43: this.fiveHearts = null; returnCard = new Card ("hearts", "five", 43); break; case 44: this.sixHearts = null; returnCard = new Card ("hearts", "six", 44); break; case 45: this.sevenHearts = null; returnCard = new Card ("hearts", "seven", 45); break; case 46: this.eightHearts = null; returnCard = new Card ("hearts", "eight", 46); break; case 47: this.nineHearts = null; returnCard = new Card ("hearts", "nine", 47); break; case 48: this.tenHearts = null; returnCard = new Card ("hearts", "ten", 48); break; case 49: this.jackHearts = null; returnCard = new Card ("hearts", "jack", 49); break; case 50: this.queenHearts = null; returnCard = new Card ("hearts", "queen", 50); break; case 51: this.kingHearts = null; returnCard = new Card ("hearts", "king", 51); break; default: Console.Out.WriteLine ("Random Card Error."); returnCard = new Card ("the devil's card", "king of hell", 666); break; } Console.Out.WriteLine("after switch: " + returnCard.getRank() + " " + returnCard.getSuit()); } catch(Exception ex) { Console.Out.WriteLine ("Random card error. Card is already null"); Console.Out.WriteLine ("Error: " + ex.ToString ()); dealCard (); } return returnCard; }
public async void firstDeal() { // alright, deal me in. mycard1 = dealDeck.dealCard (); myCard1Label.Text = mycard1.getRank () + " of " + mycard1.getSuit (); myImage1.Image = UIImage.FromBundle (mycard1.getCardString ()); myImage2.Image = UIImage.FromBundle ("back.png"); houseImage1.Image = UIImage.FromBundle ("back.png"); houseImage2.Image = UIImage.FromBundle ("back.png"); await Task.Delay (2500); mycard2 = dealDeck.dealCard (); myCard2Label.Text = mycard2.getRank () + " of " + mycard2.getSuit (); myImage2.Image = UIImage.FromBundle (mycard2.getCardString ()); await Task.Delay (2500); aceTest (mycard1, 0); aceTest (mycard2, 1); // deal the dealer in housecard1 = dealDeck.dealCard (); houseCard1Label.Text = housecard1.getRank () + " of " + housecard1.getSuit (); houseImage1.Image = UIImage.FromBundle (housecard1.getCardString ()); await Task.Delay (2500); housecard2 = dealDeck.dealCard (); houseCard2Label.Text = housecard2.getRank () + " of " + housecard2.getSuit (); houseImage2.Image = UIImage.FromBundle (housecard2.getCardString ()); aceTest (housecard1, 4); aceTest (housecard2, 5); updateCount (); hitButton.Hidden = false; doneButton.Hidden = false; }
public async void hitMe() { if(mycard3 != null && mycard4 != null) { var alert = UIAlertController.Create("Whoa Whoa Whoa.", "You can't hit now.", UIAlertControllerStyle.Alert); // add buttons alert.AddAction(UIAlertAction.Create("Okay", UIAlertActionStyle.Default, null)); // actually show the thing PresentViewController(alert, true, null); } else { if(mycard3 == null) { myCard3Label.Hidden = false; myImage3.Image = UIImage.FromBundle ("back.png"); await Task.Delay (2500); mycard3 = dealDeck.dealCard (); aceTest (mycard1, 0); aceTest (mycard2, 1); aceTest (mycard3, 2); Console.Out.WriteLine ("mycard3: " + mycard3.getRank () + " of " + mycard3.getSuit ()); myCard3Label.Text = mycard3.getRank () + " of " + mycard3.getSuit (); myImage3.Image = UIImage.FromBundle (mycard3.getCardString ()); if(checkBust()) { var alert = UIAlertController.Create("Whoa Whoa Whoa.", "You busted! \n" + "On a " + mycard3.getRank() + " of " + mycard3.getSuit() + "\n Better hope the dealer busts. \n" + "He's dealing now. Hurry!", UIAlertControllerStyle.Alert); // add buttons alert.AddAction(UIAlertAction.Create("Okay :(", UIAlertActionStyle.Default, null)); // actually show the thing PresentViewController(alert, true, null); hitButton.Hidden = true; doneButton.Hidden = true; await Task.Delay (2000); hitDealer (); } } else if(mycard4 == null) { myCard4Label.Hidden = false; myImage4.Image = UIImage.FromBundle ("back.png"); await Task.Delay (2500); mycard4 = dealDeck.dealCard (); aceTest (mycard1, 0); aceTest (mycard2, 1); aceTest (mycard3, 2); aceTest (mycard4, 3); myCard4Label.Text = mycard4.getRank () + " of " + mycard4.getSuit (); myImage4.Image = UIImage.FromBundle (mycard4.getCardString ()); // could refactor into its own function if(checkBust()) { var alert = UIAlertController.Create("Whoa Whoa Whoa.", "You busted! \n" + "On a " + mycard4.getRank() + " of " + mycard4.getSuit() + "\n Better hope the dealer busts.\n" + "He's dealing now. Hurry!", UIAlertControllerStyle.Alert); // add buttons alert.AddAction(UIAlertAction.Create("Okay :(", UIAlertActionStyle.Default, null)); // actually show the thing PresentViewController(alert, true, null); hitButton.Hidden = true; doneButton.Hidden = true; await Task.Delay (2000); hitDealer (); } } } }
public async void hitDealer() { updateCount (); if(housesum < 17) { if(housecard3 == null) { houseCard3Label.Hidden = false; houseImage3.Image = UIImage.FromBundle ("back.png"); await Task.Delay (2500); housecard3 = dealDeck.dealCard (); aceTest (housecard1, 4); aceTest (housecard2, 5); aceTest (housecard3, 6); Console.Out.WriteLine ("housecard3: " + housecard3.getRank () + " of " + housecard3.getSuit ()); houseImage3.Image = UIImage.FromBundle (housecard3.getCardString ()); await Task.Delay (1000); if(checkHouseBust()) { /*var alert = UIAlertController.Create("Whoa Whoa Whoa.", "The house busted! \n On a " + housecard3.getRank() + " of " + housecard3.getSuit(), UIAlertControllerStyle.Alert); // add buttons alert.AddAction(UIAlertAction.Create("Okay :)", UIAlertActionStyle.Default, null)); // actually show the thing PresentViewController(alert, true, null);*/ } } updateCount (); Console.Out.WriteLine ("housesum: " + housesum + ". mysum: " + mysum); if(housecard4 == null && housesum < 17) { houseCard4Label.Hidden = false; houseImage4.Image = UIImage.FromBundle ("back.png"); await Task.Delay (2500); housecard4 = dealDeck.dealCard (); aceTest (housecard1, 4); aceTest (housecard2, 5); aceTest (housecard3, 6); aceTest (housecard4, 7); Console.Out.WriteLine ("housecard4: " + housecard4.getRank () + " of " + housecard4.getSuit ()); houseCard4Label.Text = housecard4.getRank () + " of " + housecard4.getSuit (); houseImage4.Image = UIImage.FromBundle (housecard4.getCardString ()); await Task.Delay (1000); if(checkHouseBust()) { /*var alert = UIAlertController.Create("Whoa Whoa Whoa.", "The house busted! \n On a " + housecard4.getRank() + " of " + housecard4.getSuit(), UIAlertControllerStyle.Alert); // add buttons alert.AddAction(UIAlertAction.Create("Okay :)", UIAlertActionStyle.Default, null)); // actually show the thing PresentViewController(alert, true, null);*/ } } } updateCount (); checkWinner (); }