%
'--------------------------------------------------------------
' ASPBlackJack v1.0
' (x) Ugh!! 2000 - 15/10/2000
'
' Converted to ASP from JScript obtained at
' http://www.javascriptsearch.com/scripts/Games/blackjack.html
' Original author: Unknown
'
' Written for http://www.only-network.com/games Any comments,
' flames, requests, postcards etc to owen@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 & "
"
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 & "
"
selectCard = CardValue(iCardNum)
WriteHistory strWho , theCard
end function
'------------------------------------------------
' Show current status on screen
'------------------------------------------------
sub ReportStatus
Response.Write "
" Response.Write "
| Player | Hand | Score |
| You | " & ReadHistory("User") & " | " Response.Write "" & Session("User") & " |
| Dealer | " & ReadHistory("Dealer") & " | " Response.Write "" & Session("Dealer") & " |