Back to basic; Dice game
Forum » ASCII board. / ASCII programming. » Back to basic; Dice game
started by: EKVirtanenEKVirtanen
on: 1195651857|%e %b %Y, %H:%M %Z|agohover
number of posts: 1
rss icon RSS: new posts
summary:
Another not so serious code. I had boring here lol
Back to basic; Dice game
EKVirtanenEKVirtanen 1195651857|%e %b %Y, %H:%M %Z|agohover
// Dice game for yaBasic www.yabasic.de
// Just having a fun here. Nothing special

diceMax = 6        // max value of dice
diceMin = 1        // min value of dice
CanExit = false

// MAIN GAME LOOP
while(CanExit = false)
    clear screen
    print ""
    print "  Dice Game for yaBasic!"
    print " ************************"
    print ""
    print " Just having fun, nothing special here."
    print " E.K.Virtanen www.ascii-world.com"
    print " Public Domain"
    print ""
    print " Select:"
    print " 1.) Play"
    print " 2.) Help"
    print " 3.) Quit"
    temp$ = inkey$
        if(temp$ = "1") gosub play
        if(temp$ = "2") gosub help
        if(temp$ = "3") CanExit = true
wend
clear screen
print ""
print " Thank you for playing."
end

label play
    gosub plrPlay
    if plrTotal < 22 gosub cpuPlay
return

label plrPlay
    plrTotal = 0
    throwNum = 0
    done = false

    while(done = false)
        throwNum = (throwNum + 1)
        clear screen
        print ""
        print " This is throw #", throwNum
        print " Press a key to throw a dice"
        print ""
        inkey$

        diceVal = int(ran(diceMax) + diceMin)
        plrTotal = (plrTotal + diceVal)
        sleep 1

        print " You did throw ", diceVal
        // Now we check few things.
        if(plrTotal > 21) then
            print " You go over 21. You lost."
            done = true
        end if

        if(plrTotal = 21) then
            print " You got it. 21 excatly."
            done = true
            break
        end if

        print " Your total is ", plrTotal
        print " Press 's' to stay or any other key for more."
        if(inkey$ = "s") done = true
    wend
return

label cpuPlay
    cpuTotal = 0
    throwNum = 0
    done = false

    while(done = false)
        throwNum = (throwNum + 1)
        clear screen
        print ""
        print " This is my throw #", throwNum
        print ""
        sleep 1

        diceVal = int(ran(diceMax) + diceMin)
        cpuTotal = (cpuTotal + diceVal)

        print " I did throw ", diceVal
        // Now we check few things.
        if(cpuTotal > 21) then
            print " I did go over 21. I lost."
            break
        end if

        if(cpuTotal = 21) then 
            if(plrTotal < 21) print " You lost, i got 21."
            if(plrTotal = 21) print" Amazing, we both got 21. You lost since it's tie."
            break
        end if

        if(cpuTotal = plrTotal) then
            print " I have same result now, in tie so i win."
            break
        end if

        print " My total is ", cpuTotal
        print " Your total was ", plrTotal
        print ""
        if(plrTotal > cpuTotal) print " I just got to throw more to beat you."
        if(plrTotal < cpuTotal) then 
            print " No need to throw more, i did beat you"
            done = true
        end if
        sleep 3
    wend
    inkey$
return

label help
    clear screen
    print ""
    print "  Dice Game for yaBasic!"
    print " ************************"
    print ""
    print " In this game, you throw a single six sided dice."
    print " Result of your throw is counted after every round."
    print " Idea is to get as close of total 21 as possible."
    print " Basic idea is same than in BlackJack card game."
    print ""
    print " If you go over 21, you loose automaticly."
    print " After youre done, computer throws too and tries to beat you."
    print " In tie, computer wins."
    print ""
    print " Press any key to return for menu."
    inkey$
return
unfold Back to basic; Dice game by EKVirtanenEKVirtanen, 1195651857|%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.