Play,Blackjack,against,computer
Quick Search for:  in language:    
Play,Blackjack,against,computer
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 144,429 lines
 Jobs: 168 postings

 
Sponsored by:

 

You are in:

 
Login


 

 


Latest Code Ticker for ASP/ VbScript.
Click here to see a screenshot of this code!Ping in ASP
By Michele_Garneri on 10/28

(Screen Shot)

Embed Real Player Object
By Ziae Mousavi m. on 10/27


Set Country --> Combobox
By Hohl David on 10/27


Client Side Sorting of records
By Ravi Rajan on 10/26


Recordset paging with images
By Ravi Rajan on 10/26


Click here to see a screenshot of this code!Online photo catalogue VBScript 2.1
By Ivan Loire on 10/26

(Screen Shot)

GPS 1.4 WYSIWYG
By Guo Xu on 10/25


Click here to see a screenshot of this code!A Network Monitor tool from ActivXperts Software Inc.
By Freddy Hofstadt on 10/25

(Screen Shot)

Socket samples based on Winsock, TCP/IP and client/server communication
By Ronny Bright on 10/25


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

ASP Blackjack

Print
Email
 
VB icon
Submitted on: 12/22/2000 7:05:50 PM
By: Owen Cutajar  
Level: Intermediate
User Rating: By 4 Users
Compatibility:ASP (Active Server Pages), VbScript (browser/client side)

Users have accessed this code 7635 times.
 
(About the author)
 
     Play Blackjack against the computer
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: ASP Blackjack
    ' Description:Play Blackjack against the
    '     computer
    ' By: Owen Cutajar
    '
    ' Assumes:Code should be fully functiona
    '     l. One assumption is that card generatio
    '     n is totally random. There is no check t
    '     hat a card has already been extracted fr
    '     om the deck in the same game.
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/xq/ASP/txtCode
    '     Id.6425/lngWId.4/qx/vb/scripts/ShowCode.
    '     htm    'for details.    '**************************************
    
    <%
    '---------------------------------------
    '     -----------------------
    ' ASPBlackJack v1.0
    ' (x) Ugh!! 2000 - 15/10/2000
    '
    ' Converted to ASP from JScript obtained
    '     at
    ' http://www.javascriptsearch.com/script
    '     s/Games/blackjack.html
    ' Original author: Unknown
    '
    ' Written for http://www.only-network.co
    '     m/games Any comments, 
    ' flames, requests, postcards etc to owe
    '     n@cutajar.net
    '---------------------------------------
    '     -----------------------
    Option Explicit
    '---------------------------------------
    '     ---------
    ' History Routines
    '---------------------------------------
    '     ---------
    Sub ClearHistory
    	Dim q
    	For q = 1 To 10
    		Session("DHistory" & q) = ""
    		Session("UHistory" & q) = ""		
    	Next
    End Sub
    Sub WriteHistory(Entity,Message)
    	Dim q
    	q = 1
    	While Session( Left(Entity,1) & "History" & q) <> ""
    		q = q + 1
    	Wend
    	Session( Left(Entity,1) & "History" & q) = Message
    End Sub
    function ReadHistory(Entity)
    	Dim returnValue,q,currentmessage
    	returnvalue = ""
    	For q = 1 To 10
    		currentmessage = Session( Left(Entity,1) & "History" & q) 
    		if currentmessage <> "" Then
    			returnvalue = returnvalue & "- " & currentmessage & "<BR>"	
    		End if		
    	Next	
    	ReadHistory = returnValue
    End function
    '---------------------------------------
    '     ---------
    ' Select a random card
    '---------------------------------------
    '     ---------
    function pickCard()
    	Dim iRandom
    	Randomize()
    	iRandom = Int(13 * Rnd + 1)
    	pickCard = iRandom
    End function
    '---------------------------------------
    '     ---------
    ' Select a random suit
    '---------------------------------------
    '     ---------
    function pickSuit()
    	Dim iRandom
    	Randomize()
    	iRandom = Int(4 * Rnd + 1)
    	if iRandom = 1 Then
    	 pickSuit = "Spades"
    	ElseIf iRandom = 2 Then
    	 pickSuit = "Clubs"
    	ElseIf iRandom = 3 Then
    	 pickSuit = "Diamonds"
    	Else
    	 pickSuit = "Hearts"
    	End if
    End function
    '---------------------------------------
    '     ---------
    ' Translate card number to words
    '---------------------------------------
    '     ---------
    function cardName(card)
    	if card = 1 Then
    		cardName = "Ace"
    	ElseIf card = 11 Then
    		cardName = "Jack"
    	ElseIf card = 12 Then
    		cardName = "Queen"
    	ElseIf card = 13 Then
    		cardName = "King"
    	Else
    		cardName = card
    	End if
    End function
    '---------------------------------------
    '     ---------
    ' Work out value of card
    '---------------------------------------
    '     ---------
    function cardValue(card)
    	if card = 1 Then
    		cardValue = 11
    	ElseIf card > 10 Then
    		cardValue = 10
    	Else
    		cardValue = card
    	End if
    End function
    '---------------------------------------
    '     ---------
    ' Work out value of card
    '---------------------------------------
    '     ---------
    function selectCard(strWho)
    	Dim iCardNum,theCard
    	iCardNum = pickCard
    	theCard = CardName(iCardNum) & " of " & pickSuit
    	Response.Write strWho & " picked a " & theCard & "<BR>"
    	selectCard = CardValue(iCardNum)
    	WriteHistory strWho , theCard
    End function
    '---------------------------------------
    '     ---------
    ' Show current status on screen
    '---------------------------------------
    '     ---------
    Sub ReportStatus
    	Response.Write "<P>"
    	Response.Write "<TABLE border=3><TR><TD>Player</TD><TD>Hand</TD><TD>Score</TD></TR>"
    	Response.Write "<TR><TD>You</TD><TD>" & ReadHistory("User") & "</TD>"
    	Response.Write "<TD>" & Session("User") & "</TD></TR>"
    	Response.Write "<TR><TD>Dealer</TD><TD>" & ReadHistory("Dealer") & "</TD>"
    	Response.Write "<TD>" & Session("Dealer") & "</TD></TR></TABLE>"
    End Sub
    '---------------------------------------
    '     ---------
    ' Work out value of card
    '---------------------------------------
    '     ---------
    Sub NewHand
    	ClearHistory
    	Session("Dealer") = 0
    	Session("User") = 0
    	Session("Dealer") = Session("Dealer") + SelectCard("Dealer")
    	Session("User") = Session("User") + SelectCard("User")
    	Session("GameOver") = False
    	ReportStatus	
    End Sub
    '---------------------------------------
    '     ---------
    ' Dealer Move
    '---------------------------------------
    '     ---------
    Sub DealerMove
    	While Session("Dealer") < 17
    		Session("Dealer") = Session("Dealer") + SelectCard("Dealer")
    	Wend
    	ReportStatus
    End Sub
    '---------------------------------------
    '     ---------
    ' You Move
    '---------------------------------------
    '     ---------
    Sub UserMove
    	Session("User") = Session("User") + SelectCard("User")
    	if Session("User") > 21 Then
    	Response.Write "<H2>You busted!</H2>"
    		Session("GameOver") = True
    	End if
    	ReportStatus
    End Sub
    '---------------------------------------
    '     ---------
    ' Get Game Status
    '---------------------------------------
    '     ---------
    Sub LookAtHands
    	if Session("Dealer") > 21 Then
    		Response.Write "<H2>House busts! You win!</H2>"
    	ElseIf Session("User") > Session("Dealer") Then
    		Response.Write "<H2>You win</H2>"
    	ElseIf Session("User") = Session("Dealer") Then
    		Response.Write "<H2>Push!</H2>"
    	Else
    		Response.Write "<H2>House wins!</H2>"
    	End if
    	Session("GameOver") = True
    End Sub
    ' Maincode starts here
    Dim action
    Response.Write "<CENTER>"
    action = Request("action") & ""
    if action = "Hit Me" Then
    	UserMove
    ElseIf action = "Stand" Then
    	DealerMove
    	LookAtHands
    Else
    	NewHand
    End if
    Response.Write "<FORM action=blacksource.asp>"
    if Session("GameOver") <> True Then
    	Response.Write "<INPUT TYPE=SUBMIT NAME=action VALUE='Hit Me'>"
    	Response.Write "<INPUT TYPE=SUBMIT NAME=action VALUE='Stand'>"
    End if
    Response.Write "<INPUT TYPE=SUBMIT NAME=action VALUE='New Hand'>"
    Response.Write "</FORM>"
    Response.Write "</CENTER>"
    %>


Other 1 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
5/3/2001 4:21:53 PM:Dreamingweb
Soz if i seen like a total dunce, i 
have done some VB programming and 
Visual Basic programming 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/24/2002 4:44:06 AM:
can't see anything
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.