21: Hit Me (Stage 2)

21: Hit Me (Stage 2)

if(items_left_in_suit==0){
 twenty1('Hit Me'); // try again - this should not end in a loop unless the player deals all cards, which should be prevented by current_score > 21
}
else{
 if(suit_chosen=="Clubs"){
  card_drawn = Clubs[Math.floor(Math.random()*items_left_in_suit)];
  if(card_drawn=="DealAgain"){
   twenty1('Hit Me');
   return;
  }
  // remove card from deck
  card_number = Clubs.indexOf(card_drawn);
  Clubs.splice(card_number,1);
 }
 else if(suit_chosen=="Hearts"){
  card_drawn = Hearts[Math.floor(Math.random()*items_left_in_suit)];
  if(card_drawn=="DealAgain"){
   twenty1('Hit Me');
   return;
  }
  // remove card from deck
  card_number = Hearts.indexOf(card_drawn);
   Hearts.splice(card_number,1);
 }
 else if(suit_chosen=="Spades"){
  card_drawn = Spades[Math.floor(Math.random()*items_left_in_suit)];
  if(card_drawn=="DealAgain"){
   twenty1('Hit Me');
   return;
  }
  // remove card from deck
  card_number = Spades.indexOf(card_drawn);
  Spades.splice(card_number,1);
 }
 else if(suit_chosen=="Diamonds"){
  card_drawn = Diamonds[Math.floor(Math.random()*items_left_in_suit)];
  if(card_drawn=="DealAgain"){
   twenty1('Hit Me');
   return;
  }
  // remove card from deck
  card_number = Diamonds.indexOf(card_drawn);
  Diamonds.splice(card_number,1);
 }
 else{
  document.getElementById('gameStatus').innerHTML = 'Invalid Suit Chosen - We Will Re-deal!';
  twenty1('Hit Me');
 }
}
Comments are closed.