Loading
Scriptbox
 VBScript Links 
 About VBscript 
 JavaScript Links 
 About JavaScript 
 Powershell Links 
 PSCRIPT the Script Launcher 
 PowerShell Shortcut Keys 
 About Powershell 
     VBScript
    JavaScript
    Powershell
Disclaimer
Contact
Latest 10 Scripts
Script search
  :: { Category } :: 0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ
         

Search Options:  2008  Scripting  Games  Advanced  VBScript  Event  10  

 Content of 2008 Scripting Games Advanced VBScript Event 10.vbs
MD5 Hash: 3B8EE6F18D27F5D75D371242B9013EA3
' This is my Solution for the Scripting Games 2008
' For more Information look at
' http://www.microsoft.com/technet/scriptcenter/funzone/games/games08.mspx

Option Explicit

Dim sDealerCards
Dim sPlayerCards
Dim iDealerPoints
Dim iPlayerPoints
Dim iCountCardOut : iCountCardOut = 0


Call Main()


' ---------------------------------------
Sub Main()

Dim iCount, iCount2
Dim iCards : iCards = 0

Dim arrTemplateCards(12)
Dim arrCards(51,1)

Dim bPlay : bPlay = true
Dim iRound : iRound = 0

arrTemplateCards(0) = "Two"
arrTemplateCards(1) = "Three"
arrTemplateCards(2) = "Four"
arrTemplateCards(3) = "Five"
arrTemplateCards(4) = "Six"
arrTemplateCards(5) = "Seven"
arrTemplateCards(6) = "Eight"
arrTemplateCards(7) = "Nine"
arrTemplateCards(8) = "Ten"
arrTemplateCards(9) = "Jack"
arrTemplateCards(10) = "Queen"
arrTemplateCards(11) = "King"
arrTemplateCards(12) = "Ace"

For iCount = 1 to 4

For iCount2 = 0 to Ubound(arrTemplateCards)

Select Case iCount

Case 1

arrCards(iCards,0) = arrTemplateCards(iCount2) & " of Hearts"
arrCards(iCards,1) = GetCardScore(arrTemplateCards(iCount2))
iCards = iCards +1

Case 2

arrCards(iCards,0) = arrTemplateCards(iCount2) & " of Spades"
arrCards(iCards,1) = GetCardScore(arrTemplateCards(iCount2))
iCards = iCards +1

Case 3

arrCards(iCards,0) = arrTemplateCards(iCount2) & " of Diamonds"
arrCards(iCards,1) = GetCardScore(arrTemplateCards(iCount2))
iCards = iCards +1

Case 4

arrCards(iCards,0) = arrTemplateCards(iCount2) & " of Clubs"
arrCards(iCards,1) = GetCardScore(arrTemplateCards(iCount2))
iCards = iCards +1

End Select
Next


Next



For iCount = 0 to RadomeInt(13)
call MixArray(arrCards)
Next


Dim sStayOrHit
Dim StdIn, StdOut
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut


Do until bPlay = false

iRound = iRound +1

Select Case iRound

Case 1

Call AddCardPlayer(arrCards)
Call AddCardPlayer(arrCards)
Call EchoCards(sPlayerCards, "Player")

Call AddCardDealer(arrCards)
Call EchoCards(sDealerCards, "Dealer")
Call AddCardDealer(arrCards)

Case Else


If iPlayerPoints = 21 then

wscript.echo "You have 21. You win."
bPlay = false
Exit Sub

Elseif iPlayerPoints > 21 then

wscript.echo "Over 21. Sorry, you lose."
bPlay = false
Exit Sub

Else

StdOut.Write "Stay (s) or hit (h)?"
sStayOrHit = StdIn.ReadLine

Select Case Ucase(sStayOrHit)

Case "S"
wscript.echo ""
wscript.echo "You have " & iPlayerPoints & "."
wscript.echo ""
bPlay = false

Case "H"
Call AddCardPlayer(arrCards)
wscript.echo ""
Call EchoCards(sPlayerCards, "Player")

End Select

End if

End Select

Loop



If Ucase(sStayOrHit) = "S" then

Call EchoCards(sDealerCards, "Dealer")
If iDealerPoints >= iPlayerPoints then

wscript.echo "The dealer has " & iDealerPoints & ". Sorry, you lose."
Exit Sub

End if

bPlay = true

Do until bPlay = false

If iDealerPoints > 21 then

wscript.echo "The dealer has " & iDealerPoints & ". You win."
bPlay = false
Exit Sub

ElseIf iDealerPoints >= iPlayerPoints then
wscript.echo "The dealer has " & iDealerPoints & ". Sorry, you lose."
bPlay = false
Exit Sub

Else
Call AddCardDealer(arrCards)
Call EchoCards(sDealerCards, "Dealer")

End if
Loop

End if




End Sub



' --------------------------------------
Private Function AddCardPlayer(arrSource)

sPlayerCards = sPlayerCards & arrSource(iCountCardOut,0) & ","
iPlayerPoints = iPlayerPoints + arrSource(iCountCardOut,1)

iCountCardOut = iCountCardOut +1

End Function

' --------------------------------------
Private Function AddCardDealer(arrSource)

sDealerCards = sDealerCards & arrSource(iCountCardOut,0) & ","
iDealerPoints = iDealerPoints + arrSource(iCountCardOut,1)

iCountCardOut = iCountCardOut +1

End Function






' --------------------------------------
Private Function EchoCards(strCards, gTyp)

Dim arrstrCards, iCount

strCards = Left(strCards, Len(strCards) -1)

If IsArray(arrstrCards) then Erase arrstrCards

arrstrCards = Split(strCards, ",", -1, 1)

Select Case gTyp

Case "Player"
wscript.echo "Your cards:"
Case "Dealer"
wscript.echo "Dealer's cards:"
End Select

For iCount = 0 to Ubound(arrstrCards)

wscript.echo arrstrCards(iCount)

Next

wscript.echo ""
strCards = strCards & ","

End Function


' --------------------------------------
Private Function MixArray(arrSource)
Dim iCount
Dim iMix
Dim tmpField, tmpField2

For iCount = 0 to Ubound(arrSource)

iMix = RadomeInt(52) -1

tmpField = arrSource(iMix,0)
tmpField2 = arrSource(iMix,1)

arrSource(iMix,0) = arrSource(iCount,0)
arrSource(iMix,1) = arrSource(iCount,1)

arrSource(iCount,0) = tmpField
arrSource(iCount,1) = tmpField2
Next

End Function



' --------------------------------------
Private Function GetCardScore(sCardName)

Select Case sCardName


Case "Two"
GetCardScore = 2

Case "Three"
GetCardScore = 3

Case "Four"
GetCardScore = 4

Case "Five"
GetCardScore = 5

Case "Six"
GetCardScore = 6

Case "Seven"
GetCardScore = 7

Case "Eight"
GetCardScore = 8

Case "Nine"
GetCardScore = 9

Case "Jack","Queen","King", "Ten"
GetCardScore = 10

Case "Ace"
GetCardScore = 11

End Select


End Function


'---------------------------
Private Function RadomeInt(iMax)

Randomize
RadomeInt = Int((iMax * Rnd) + 1)

End Function


   © 2008 - 2013 Boris Toll      :: Scripts available: 6.481 ::      :: scriptbox.toll.at ::      :: powered by www.toll.at ::
  Google Entries:n/a
  Yahoo Backlinks:n/a
  Live Backlinks:n/a
  del.icio.us Bookmarks:n/a
  Technorati Links:n/a