Howdy, Stranger!

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

In this Discussion

Random cards....(Loops continiously)

edited March 22 in Code Sharing Posts: 117
-- Random Card

displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
   rectMode(CENTER)
   t=ElapsedTime+.7
   suit={"♠️","♣️","♥️","♦️"}
   u={" 2"," 3"," 4"," 5"," 6"," 7"," 8"," 9","10"," J"," Q"," K"," A"}
   deck={}                        -- Table for the cards
   createDeck()                   -- Goto createDeck
   getCard=true                   -- Show the first card
   cc = 52                        -- Keep count of the Cards
end

function draw()
   -- Background color
   background(31, 34, 97, 255)
   if getCard then                --card is showing
       getCard=false              
       randomCard()               --Goto the random card fx
       c=v%13+1                   --The card value
       s=math.ceil(v/13)
   end

   -- This is the white card background
   fill(255)
   rect(WIDTH/2,HEIGHT/2,350,500)      --This is the WHT rectangle, location & Size

   -- Font & font size of the suit & value
   font("AmericanTypewriter-Bold") 
   fontSize(160) --size of suit font

    --This is the card suit being printed to the screen
   text(suit[s],WIDTH/2,HEIGHT/2) --Smack dab in the middle

    -- This is the different colors of the suits
    if s==1 then --spades
       fill(0, 0, 0, 255)  
        elseif 
    s==2 then --clubs
       fill(0, 0, 0, 255)  
        elseif 
    s==3 then --hearts
       fill(255, 0, 0, 255)  
        elseif 
    s==4 then --cdia onds
       fill(255, 0, 31, 255)  
   end
    -- This is the card value
   text(u[c],WIDTH/2-85,HEIGHT/2+170)  
   rotate(180)                 --The next number will be rotated 180 degrees
   text(u[c],WIDTH/2-1110,HEIGHT/2-600)  --When rotating the number has to be adjusted
   rotate(180)                 --Aftre the rtation, rotate back 180

    -- Plain text
    font("Baskerville-BoldItalic")
    fontSize(60)
    fill(255, 255, 255, 255)
    text(str, WIDTH/2,HEIGHT-60)  

    -- Card count, this is being constantly updated
    font("Baskerville-BoldItalic")
    fontSize(50)
    fill(255, 255, 255, 255)
    text(cc, WIDTH-875,HEIGHT/2)  

    -- Plain text
    font("Copperplate-Bold")
    fontSize(50)
    fill(255, 255, 255, 255)
    text("Cards left\n in Deck :", WIDTH-855,HEIGHT/2+80)   

  if ElapsedTime>t then
    sound("Game Sounds One:Bell 2")
    getCard=true
   t=ElapsedTime+.7
        if cc==1 then
            setup()
        end
  end
end 



function createDeck()
  str = "Cards"
   for z=1,52 do
       deck[z]=z
   end
end

function randomCard()
-- This plucks a random card then subtracts it from the Main deck
   if #deck>0 then     --if there are any cards left in the deck, then pluck
       d=math.random(#deck)     --pluck at random
       v=deck[d]
       table.remove(deck,d)      --after being plucked, remove it from the deck
   else
        str = "End of Deck"
   end
-- This keeps track of the amount of cards left in the deck
    if cc <= 52 then   --cc means card-count
        cc = cc - 1
    end
end
Tagged:

Comments

  • dave1707dave1707 Mod
    edited March 22 Posts: 6,828

    Remove this code to stop picking a new card every second. You didn’t say how you want to select the next card or what you wanted to do by creating the loop of selecting cards. Just a suggestion, programs run exactly as you code them to run, not exactly as you want them to run.

      if ElapsedTime>t then
        sound("Game Sounds One:Bell 2")
        getCard=true
       t=ElapsedTime+.7
            if cc==1 then
                setup()
            end
      end
    
Sign In or Register to comment.