Black Jack

[Total: 0    Average: 0/5]

This is a game of black jack.

Head Code:

<script>

var GameOver  = 0;
var CardCount = 0;
var Advising  = 0;
var HouseTxt, GuestTxt;

function Shuffle(max) {
	num=Math.random()*max; 
	return Math.round(num)+1;
}

function GetSuit() {
  suit = Shuffle(4);
	switch(suit) {
		case 1 : return "Spades";
		case 2 : return "Clubs";
		case 3 : return "Diamonds";
		default: return "Hearts"; 
	}
}

function CardName(card) {
	switch(card) {
		case 1  : return "Ace";
		case 11 : return "Jack";
		case 12 : return "Queen";
		case 13 : return "King";
		default : return  card;
	}
}

function CardValue(f,card,who) {
  if(card == 1) {
		if(who == "You" && f.you.value >10) {
			f.guest.value = f.guest.value + " Low"; 
			return 1;
		}
	 	  else return 11; 
	}
   if(card > 10) return 10; 
   return card;
}

function DrawCard(f,who) {
  card = Shuffle(12);
  suit = GetSuit();
   
	if(who == "You") {
		f.guest.value=(CardName(card) + " " + suit);
	}
    else {
		f.house.value=(CardName(card) + " " + suit);
	}
 	
	return CardValue(f,card,who);
}

function NewHand(f) {
	if(GameOver !=0) {
		Advise(f,"A Hand is","Already in Play");
		return;
	}
   else {
     f.dealer.value = 0; 
     f.you.value = 0; 
     CardCount=0;
     f.dealer.value = eval(f.dealer.value) + DrawCard(f, "Dealer");
     f.you.value = eval(f.you.value) + DrawCard(f, "You");
     GameOver= -1; 
     CardCount+=1;
	}
}

function Advise(f,top,btm) {
  if (!Advising) {
  Advising=-1;
  HouseTxt=f.house.value;
  GuestTxt=f.guest.value;  
  f.house.value=top;
  f.guest.value=btm;
  window.setTimeout("document.display.house.value=HouseTxt;"+
                    "document.display.guest.value=GuestTxt;"+
                    "Advising=0;", 600);
  }
}

function Dealer(f) {
	if (!GameOver) {
		Advise(f,"Deal the Cards!",""); 
		return;
	}
		else if(f.you.value<10) {
		Advise(f,"Not Below Ten!","Take a Hit!"); 
		return;
	}
		else if (CardCount <2)
  {
		Advise(f,"Minimum 2 Cards!","Hit Again!");  
		return;
	}
		else while(f.dealer.value < 17)
  {
		f.dealer.value = eval(f.dealer.value) + DrawCard(f, "Dealer");
	}
}


function Player(f)
{
	if (!GameOver)
	{
		Advise(f,"Deal the Cards!",""); 
		return;
	}
		else
	{
		CardCount +=1; 
		f.house.value="You Get...";
    f.you.value = eval(f.you.value) + DrawCard(f, "You");
	}
   
	if(f.you.value > 21)
	{
		f.house.value="You Busted!";
	 	GameOver=0; 
		f.score.value=eval(f.score.value)-1;
	}
}

function Declare(f)
{
	if (!GameOver || f.you.value<10 || CardCount <2)
	{
		return;
	}
		else if(f.dealer.value > 21)
	{
		f.house.value="House Busts!"; 
		f.guest.value="You Win! $$$$$$";
	  GameOver=0; 
		f.score.value=eval(f.score.value)+1;
	}
   	else if(f.you.value > f.dealer.value)
	{
		f.house.value="You Win!"; 
		f.guest.value="$$$$$$$$$$$$$$$";
	 	GameOver=0; 
		f.score.value=eval(f.score.value)+1;
	}
   	else if(f.dealer.value == f.you.value)
	{
		f.house.value="Game Tied!"; 
		f.guest.value="Try Again!";
	 	GameOver=0; 
		f.score.value=eval(f.score.value)-1;
	}
   	else
	{
		f.house.value="House Wins!"; 
		f.guest.value="Tough Luck!";
		GameOver=0; 
		f.score.value=eval(f.score.value)-1;
	}
}
</SCRIPT>

Body Code:

<FORM NAME="display">
<TABLE bORDER=0 CELLSPACING=0 CELLPADDING=5>
 <TR>
  <TD ALIGN=CENTER>Score :</TD>
  <TD ALIGN=CENTER>Dealer </TD>
  <TD ALIGN=CENTER><INPUT TYPE=TEXT NAME="dealer" VALUE="" SIZE=2 onfocus="dealer.blur();"></TD>
  <TD ALIGN=CENTER>Card(s):<INPUT TYPE=TEXT NAME="house" VALUE=" ---Blackjack---" SIZE=18 onfocus="house.blur();"></TD>
  <TD></TD>
 </TR>
 <TR>
  <TD ALIGN=CENTER><INPUT TYPE=TEXT NAME="score" VALUE="0" SIZE=3 onfocus="score.blur();"></TD>
  <TD ALIGN=CENTER>Player</TD>   
  <TD ALIGN=CENTER><INPUT TYPE=TEXT NAME="you" VALUE="" SIZE=2 onfocus="you.blur();"></TD>
  <TD ALIGN=CENTER>Card(s):<INPUT TYPE=TEXT NAME="guest" value="Push DEAL to start" SIZE=18 onfocus="guest.blur();"></TD>
 </TR>
 <TR>
  <TD ALIGN=CENTER>
   <INPUT NAME="deal" TYPE=BUTTON VALUE="Deal" onClick="NewHand(this.form)">
  </TD>
  <TD ALIGN=CENTER COLSPAN=3>
   <INPUT TYPE=BUTTON VALUE="Stand" onClick="Dealer(this.form);Declare(this.form)">
   <INPUT TYPE=BUTTON VALUE=" Hit " onClick="Player(this.form)">
  </TD>
 </TR>
</TABLE>
</FORM>

Times Viewed: 5

Leave a Reply

Your email address will not be published. Required fields are marked *