War card game for yaBasic.
Forum » ASCII board. / ASCII programming. » War card game for yaBasic.
started by: Anonymous (85.157.185.254)
on: 1195764856|%e %b %Y, %H:%M %Z|agohover
number of posts: 1
rss icon RSS: new posts
summary:
And more "not so serious" stuff here :D
War card game for yaBasic.
Anonymous (85.157.185.254) 1195764856|%e %b %Y, %H:%M %Z|agohover

errr…have fun i guess :D

// WAR Card Game for yaBasic
// E.K.Virtanen 2007
// www.ascii-world.com
// Public Domain

// ==================================== Main loop of game
CanExit = FALSE
while(CanExit = FALSE)
    clear screen
    print ""
    print color("red") " --- War ---"
    print ""
    print " Card game for yaBasic."
    print " E.K.Virtanen, www.ascii-world.com"
    print " Public Domain"
    print ""
    print color("yellow") " 1.)"; : print " Play"
    print color("yellow") " 2.)"; : print " Help"
    print color("yellow") " 3.)"; : print " Quit"
    temp$ = inkey$
    if temp$ = "1" gosub play
    if temp$ = "2" gosub help
    if temp$ = "3" CanExit = TRUE
wend

print ""
print " Thank you for playing."
end

// ==================================== Play sub
label play
    gosub createDeck    // we need to create deck with what we play
    gosub shuffleDeck    // and then we shuffle it
    gosub playGame        // now we play
return

// ==================================== createDeck sub
label createDeck
    dim cardColor$(4, 2)
        cardColor$(1, 1) = "red" : cardColor$(1, 2) = "Heart" : cardColor$(2, 1) = "red" : cardColor$(2, 2) = "Diamond"
        cardColor$(3, 1) = "white" : cardColor$(3, 2) = "Spade" : cardColor$(4,1) =  "white" : cardColor$(4,2) = "Cross"

    // some nifty looping and MOD to get a deck of cards
    dim cardDeck(52, 2)
    for counter = 0 to 51
        cardDeck(counter + 1, 1) = int(counter / 4 + 1)
        cardDeck(counter + 1, 2) = Mod(counter, 4) + 1
    next counter
return

// ==================================== shuffleDeck sub
label shuffleDeck
    dim temp(2)
    for counter = 1 TO 10000        // ten thousand rounds should be more than enough :D
        tempFirst = int(ran(52) + 1)
        tempSecond = int(ran(52) + 1)
            if tempFirst <> tempSecond then
                temp(1) = cardDeck(tempFirst, 1)
                temp(2) = cardDeck(tempFirst, 2)
                cardDeck(tempFirst, 1) = cardDeck(tempSecond, 1)
                cardDeck(tempFirst, 2) = cardDeck(tempSecond, 2)
                cardDeck(tempSecond, 1) = temp(1)
                cardDeck(tempSecond, 2) = temp(2)
            end if
    next counter
return

// ==================================== playGame sub
label playGame
    canExit = false
    roundNumber = 0
    cardNumber = 1
    plrTotal = 0
    cpuTotal = 0

    clear screen    
    print ""
    print color("red") " --- War ---"
    print ""
    print " You can start."

    while(canExit = false)
        print " Choose, do you want first or second card?"
        print color("yellow") " 1.)"; : print " First"
        print color("yellow") " 2.)"; : print " Second"
        print " Any other key for Cpu choose."
        choice$ = inkey$

        print ""
        if(choice$ <> "1" and choice$ <> "2") gosub cpuChoose

        if choice$ = "1" then
            print " You take first."
            plrCard = cardNumber
            cpuCard = cardNumber + 1
        end if

        if choice$ = "2" then
            print " Cpu takes first."
            plrCard = cardNumber + 1
            cpuCard = cardNumber
        end if

        cardNumber = cardNumber + 2
        roundNumber = roundNumber + 1
        if cardNumber = 53 canExit = true

        gosub revealCards
        gosub whoWin
        clear screen
    wend
    print ""
    print " War is over and results are:"
    print color("yellow") " You: "; : print plrTotal; : print " cards."
    print color("red") " Cpu: "; : print cpuTotal; : print " cards."
    print ""
    print " Press any key for back to menu."
    inkey$
return

// ==================================== whoWin sub
label whoWin
    if cardDeck(plrCard, 1) > cardDeck(cpuCard, 1) then
        print ""
        print color("green") " You win!"
        print " You got both cards. ";
        plrTotal = plrTotal + 2
        if cardDeck(plrCard, 1) - cardDeck(cpuCard, 1) > 8 print " You really did crash Cpu!"
        if cardDeck(plrCard, 1) - cardDeck(cpuCard, 1) < 3 print " So tight!"
    end if

    if cardDeck(plrCard, 1) < cardDeck(cpuCard, 1) then
        print ""
        print color("red") " You lose!"
        print " Cpu got both cards.";
        if cardDeck(cpuCard, 1) - cardDeck(plrCard, 1) > 8 print " Cpu really did override you!"
        if cardDeck(cpuCard, 1) - cardDeck(plrCard, 1) < 3 print " Close, so close!"

        cpuTotal = cpuTotal + 2
    end if

    if cardDeck(plrCard, 1) = cardDeck(cpuCard, 1) then
        print ""
        print color("yellow") " It's a tie."
        print " Both got their own card."
        cpuTotal = cpuTotal + 1 : plrTotal = plrTotal + 1
    end if

    print ""
    print color("yellow") " Winned cards after round: "; : print roundNumber
    print ""
    print " You: "; : print plrTotal
    print " Cpu: "; : print cpuTotal
    gosub uselessComments
    print ""
    print color("yellow") " Press a key for next round."
    inkey$
return

// ==================================== uselessComments sub
label uselessComments
    if plrTotal > cpuTotal then
        temp$ = " You are leading here!!!"
        if plrTotal - cpuTotal > 5 temp$ = " Making a good lead there."
        if plrTotal - cpuTotal > 10 temp$ = " You trying to escape?"
        if plrTotal - cpuTotal > 15 temp$ = " HEHE, youre really crushing Cpu here!!!"
    end if
    if plrTotal < cpuTotal then
        temp$ = " You are loosing!!!"
        if cpuTotal - plrTotal > 5 temp$ = " Cpu leads clearly!"
        if cpuTotal - plrTotal > 10 temp$ = " Cpu is trying to escape?"
        if cpuTotal - plrTotal > 15 temp$ = " LOL, Cpu really kicks your ass here."
    end if
    if plrTotal = cpuTotal temp$ = " Side by side!"
    print temp$
return

// ==================================== revealCards sub
label revealCards
    print ""
    print " Your card is...";
    print  color(cardColor$(cardDeck(plrCard, 2), 1)) cardColor$(cardDeck(plrCard, 2), 2); : print " "; : print cardDeck(plrCard, 1)
    print " ...and Cpu slowly reveales hes card what is.";
    for counter = 1 to 2
        sleep 1
        print ".";
    next counter
    print  color(cardColor$(cardDeck(cpuCard, 2), 1)) cardColor$(cardDeck(cpuCard, 2), 2); : print " "; : print cardDeck(cpuCard, 1)
    print ""
return

// ==================================== cpuChoose sub
label cpuChoose
    choice$ = "1"
    if ran() = true choice$ = "2"
return

// ==================================== help sub
label help
    clear screen
    print ""
    print color("red") " --- War ---"
    print ""
    print " Card game for yaBasic."
    print " E.K.Virtanen, www.ascii-world.com"
    print " Public Domain"
    print ""
    print " I game of War, a normal card deck is shuffled."
    print " Then from a top of deck, both players gets an card."
    print " Who's card is higher (in numerical value) wins and he get's the cards."
    print " This way, whole deck is revealed to the end. Who has more cards is the winner."
    print ""
    print " You opponent is Cpu (computer) so this is one player game."
    print ""
    print color("yellow") " Press any key to return for menu."
    inkey$
return

E.K.Virtanen

unfold War card game for yaBasic. by Anonymous (85.157.185.254), 1195764856|%e %b %Y, %H:%M %Z|agohover
new post
page_revision: 0, last_edited: 1181740773|%e %b %Y, %H:%M %Z (%O ago)
Unless stated otherwise Content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.