Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Posted my question here: http://stackoverflow.com/questions/14710039/vbscript-poker-game-what-hand-do-i-have

Here is the full code:

'buy a blank deck of cards

'declare variables
dim defaultDeck(51)
dim trueDeck(51)
dim isUsed(51)
numPlayers = 1
numCards = 12
intMyHand = 0 '0 through numPlayers-1... highest number is dealer
Set objStdOut = WScript.StdOut


'put values on the blank cards:

i=0
for suit=0 to 3
    for faceValue=0 to 12
        select case suit
            Case 0
                strSuit = chr(3)
            case 1
                strSuit = chr(4)
            case 2
                strSuit = chr(5)
            case 3
                strSuit = chr(6)
            case else
                strSuit = "SuitNotFound"
        end Select
        face = faceValue+1
        select case face
            case 11
                face = "J"      
            case 12
                face = "Q"
            case 13
                face = "K"
            case 1
                face = "A"
            case default
                face=face
        end select      
            defaultDeck(i) = face & strSuit
            i = i+1

    next
Next


function translateCard(number)

    translateCard = defaultDeck(number)

end function



'shuffle the deck

function randNum()
    max = 51
    min = 0
    Randomize
    randNum = Int((max-min+1)*Rnd+min)

end Function


function shuffleDeck()

    'reset from last shuffle
    y=0
    for i=0 to 51
        isUsed(i) ="n"
    next

    'draw a card and put it in the deck
    do while y<52
        card = randNum()
        if isUsed(card) <> "Y" then
            isUsed(card) = "Y"
            trueDeck(y) = card
            y = y+1
        end if
    loop
'   objStdOut.Write "Shuffling."
'   jsleep(1)
'   objStdOut.Write "."
'   jsleep(1)
'   objStdOut.Write "."
'   jsleep(1)
'   objStdOut.Write "."
'   jsleep(1)
'   objStdOut.Write "Shuffled."
    objStdOut.WriteBlankLines(1)    
    jsleep(1)
end Function

function showDeck()
    for i=0 to 50
        'wscript.echo i & ". " & truedeck(i)    

        strDeck = strDeck & translateCard(truedeck(i)) & ","
    next
    strDeck = strDeck & translateCard(trueDeck(51)) 'to get rid of last comma

    wscript.echo ""
    wscript.echo "Shuffled Deck"
    wscript.echo "-------------"
    wscript.echo strDeck
end Function





function showdefDeck()
    for i=0 to 51
        wscript.echo i & ". " & defaultdeck(i)  

    '   strDeck = strDeck & truedeck(i) & ", "
    next
    'strDeck = strDeck & trueDeck(51) 'to get rid of last comma


'   wscript.echo strDeck
end Function





playa = numPlayers-1
carda = numCards-1


Dim hands()
ReDim Hands(playa,carda)
dim myHand()
reDim myHand(carda)

function Dealcards()
    totalNumCards = (numPlayers * numCards)
    tnc =0
    i = 0
    do while tnc < totalnumCards
        for c=0 to (numCards - 1)
            for p=0 to (numPlayers -1)

                Hands(p,c) = trueDeck(i)

                'debug line
                'wscript.echo truedeck(i) & " dealt to player " & p+1 & "."


                i=i+1
                tnc = tnc+1
            next
        next

    loop

'   objStdOut.Write "Dealing."
'   jsleep(1)
'   objStdOut.Write "."
'   jsleep(1)
'   objStdOut.Write "."
'   jsleep(1)
'   objStdOut.Write "Dealt."
    objStdOut.WriteBlankLines(2)
    jsleep(1)

End function

function showHand(h)
    if (h = intMyHand) then
        specialString = "*(You)* "
    else
        specialString = ""
    end if

    wscript.echo specialString & "Player " & h+1 & "'s hand:"


    for i=0 to (numCards - 1)
        theCard = translatecard(Hands(h, i))
        wscript.echo theCard
    next
    wscript.echo ""
end Function


function showSortedHand(t)

    if (t = intMyHand) then
        specialString = "*(You)* "
    else
        specialString = ""
    end if

    wscript.echo specialString & "Player " & t+1 & "'s hand:"


    theSortedHand = getHand(t)

    for each card in theSortedHand
        transCard = translateCard(card)
        wscript.echo transCard
    next


end Function





function showMyHand()
    showHand(intMyHand)
end Function


function showAllHands()
    for q=0 to playa
        showHand(q)
    next
end Function





function jsleep (seconds)

    wscript.sleep seconds*1000
end function







'sort method

function SortArray(arrShort)
    dim i, j, temp
    for i = UBound(arrShort) - 1 To 0 Step -1
        for j= 0 to i
            if arrShort(j)>arrShort(j+1) then
                temp=arrShort(j+1)
                arrShort(j+1)=arrShort(j)
                arrShort(j)=temp
            end if
        next
    next
    SortArray = arrShort
end function 



function getHand(x)
    purple = numCards-1

    dim a()
    redim a(purple)

    for i=0 to (numCards-1)
        a(i) = Hands(x, i)
    next

    sortArray a

    getHand = a

end function













objstdOUt.Write "Welcome to PokerGame1.0"

objStdOut.WriteBlankLines(1)
objStdOut.Write "-----------------------"
objStdOut.WriteBlankLines(2)



'showdefdeck

shuffleDeck
showdeck

dealCards

'showMyHand
showAllHands



showSortedHand(0)
share|improve this question
As fun as this was, I'm switching to Python. – Jeff Feb 7 at 14:29

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.