Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Cards in general

edited December 2017 in Questions Posts: 93

Cards in General, this is just a study along with a Lua book

Comments

  • dave1707dave1707 Mod
    Posts: 6,486

    Do a search for Ignatz tutorials. I don't know it he did anything for card games. Do a forum search for what you want, you'll find some info there.

  • This prints to a compiler just fine, but how can I get these cards randomized ? I think I could put a table.insert and a math.random somewhere.....
    ~~~
    suit={"♠️","♣️","♥️","♦️"}
    val={"2","3","4","5","6","7","8","9","10","J","Q","K","A"}
    cards={}
    for x=1,4 do
    for y=1,13 do
    str=string.format(" %s\n%s",val[y],suit[x])
    table.insert(cards,str)
    print(val[y],suit[x])
    end
    end
    ~~~

    P.S. : This is just a study along with a Lua book....

  • dave1707dave1707 Mod
    Posts: 6,486

    @kendog400 There are a lot of card programs already written in this forum. Try doing a search for them and you’ll find code to randomize a deck of cards.

  • dave1707dave1707 Mod
    Posts: 6,486

    @kendog400 I don’t know what you’re doing, but in one of your other card game programs that you posted, you have a very nice shuffle function that shuffles a deck of cards.

  • dave1707dave1707 Mod
    Posts: 6,486

    Here’s something I came up with that you can look thru.

    displayMode(FULLSCREEN)
    supportedOrientations(LANDSCAPE_ANY)
    
    function setup()
        s={" ♥️"," ♠️"," ♦️"," ♣️"}
        v={" 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10"," J"," Q"," K"," A"}
        deck={}
        for z=0,51 do
            table.insert(deck,v[z%13+1]..s[z//13+1])
        end
    end
    
    function draw()
        background(151, 223, 223, 255)
        fontSize(40)
        fill(255)
        text("Tap screen to shuffle",WIDTH/2,HEIGHT-50)
        for z=0,51 do
            text(deck[z+1],275+(z//13)*150,50+(z%13)*50)
        end
    end
    
    function shuffle()
        for q=1,100 do
            a,b=math.random(52),math.random(52)
            deck[a],deck[b]=deck[b],deck[a]
        end
    end
    
    function touched(t)
        if t.state==BEGAN then
            shuffle()
        end
    end
    
  • Thanks !...I'm just reading a book on Lua and trying to get a good comprehension...If I can understand whats going on I can tackle it !..

Sign In or Register to comment.