…
I have here a program again, it dident go through last time. It prints the hand to the screen vertically, i’m trying to figure out i can get this printed horizontally, then use the "
" to print the suit on the next line, after that i would use the vec2’s to put a rectangle under it to make it look like a card.
Can anyone take a peek to help me find the spot where i could take control and make the print out horizontal(straight across) ?
I’ve been trying to figure this out, buy changing every spot, but I havent figured it out as of yet.
This looks like a good game here, and a good starting point.
-- Five Card Poker
supportedOrientations(LANDSCAPE_ANY)
displayMode(FULLSCREEN)
function setup()
font("ArialRoundedMTBold")
fontSize(40)
str="" -- matches
hand={} -- table of current hand
suit={"??","??","??","??"}
value={" 2"," 3"," 4"," 5"," 6"," 7"," 8",
" 9","10","J","Q","K","A"}
setup1()
end
function setup1()
shuf="New deck"
sc=shuffleCards() -- shuffle cards
r=0 -- card offset
setTable({sc[r+1],sc[r+2],sc[r+3],sc[r+4],sc[r+5]})
check() -- check current hand
end
function draw()
background(40,40,50)
fill(255)
text(shuf,WIDTH/2,HEIGHT-50)
text("Tap screen for Next Hand",WIDTH/2,HEIGHT-100)
show() -- show the current hand
end
function nextHand()
r=r+5
if r>49 then -- new deck
setup1()
else
setTable({sc[r+1],sc[r+2],sc[r+3],sc[r+4],sc[r+5]})
check()
end
end
function touched(t)
shuf=""
if t.state==ENDED then
nextHand()
end
end
function setTable(cards)
-- set table values to 0
for x=1,13 do
hand[x]={}
for y=1,4 do
hand[x][y]=0
end
end
-- update with new cards
for x=1,5 do
local s=math.floor((cards[x]-1)/13)+1
local v=(cards[x]-1)%13+1
hand[v][s]=1
end
end
function show()
pushStyle()
textMode(CORNER)
local cnt=0
for x=13,1,-1 do
for y=1,4 do
if hand[x][y]==1 then
cnt=cnt+1
local card=string.format("%5s of %s",value[x],suit[y])
text(card,370,HEIGHT-250-cnt*40)
end
end
end
popStyle()
text(str,WIDTH/2,HEIGHT-600)
end
function check() -- determine ranking of current hand
-- clear flags
local same2,same3,same4=0,0,0
local flush,straight,royal=0,0,0
local v2,v3,v4
-- check for pairs, 3 of a kind, 4 of a kind, full house
for x=1,13 do
v2=hand[x][1]+hand[x][2]+hand[x][3]+hand[x][4]
v3=hand[x][1]+hand[x][2]+hand[x][3]+hand[x][4]
v4=hand[x][1]+hand[x][2]+hand[x][3]+hand[x][4]
if v2==2 then
same2=same2+1
end
if v3==3 then
same3=1
end
if v4==4 then
same4=1
end
end
-- check for flush
local s1,s2,s3,s4=0,0,0,0
for x=1,13 do
s1=s1+hand[x][1]
s2=s2+hand[x][2]
s3=s3+hand[x][3]
s4=s4+hand[x][4]
end
if s1==5 or s2==5 or s3==5 or s4==5 then
flush=1
end
-- check for straight
local sum=0
local x=13 -- start with Ace for low straight
if hand[x][1]==1 or hand[x][2]==1 or hand[x][3]==1 or hand[x][4]==1 then
sum=sum+1
end
for x=1,13 do
if hand[x][1]==1 or hand[x][2]==1 or hand[x][3]==1 or hand[x][4]==1 then
if sum==0 and x==9 then
royal=1 -- possible royal 10,J,Q,K,A
end
sum=sum+1
if sum==5 and x==4 then
straight=1 -- Ace,2,3,4,5
end
else
if sum<5 then -- out of sequence
sum=0
end
royal=0 -- clear royal
end
end
if sum==5 then
straight=1
end
-- update str with results of hand
str="High card"
if same2==1 then
str="1 Pair"
end
if same2==2 then
str="2 Pair"
end
if same3==1 then
str="3 of a kind"
end
if straight==1 then
str="Straight"
end
if flush==1 then
str="Flush"
end
if same2==1 and same3==1 then
str="Full House"
end
if same4==1 then
str="4 of a kind"
end
if flush==1 and straight==1 then
str="Straight Flush"
end
if flush==1 and royal==1 then
str="Royal Flush"
end
end
function shuffleCards()
local d1, d2 = {}, {}
for z=1,52 do
d1[z]=z -- fill the deck (Unshuffled); 1-thru-52
end
for z=1,52 do
local r=math.random(1,#d1) -- get a random card from table (d1)
table.insert(d2,d1[r]) -- insert it into shuffled deck (d2)
table.remove(d1,r) -- remove it from unshuffled d1
end
return d2 -- return shuffled deck
end
Change the function show with this.
function show()
pushStyle()
textMode(CORNER)
local cnt=0
for x=13,1,-1 do
for y=1,4 do
if hand[x][y]==1 then
cnt=cnt+1
fill(255)
stroke(247, 192, 22, 255)
strokeWidth(4)
rect(240+cnt*80,HEIGHT-310,75,110)
fill(255,0,0)
local card=string.format("%5s",value[x])
text(card,225+cnt*80,HEIGHT-250)
local card=string.format("%5s",suit[y])
text(card,257+cnt*80,HEIGHT-300)
end
end
end
popStyle()
text(str,WIDTH/2,HEIGHT-600)
end
Thanks a Million !!!
…
@kendog400 You only need to swap 2 numbers and reduce the value of a third number then change it from portrait to landscape mode.
Thanks again !..I’LL be getting back to the drawing board. Next I would like to put in some shuffle sounds and such…I dont know which is the third number to reduce, but I’LL try to figure it out…
@kendog400 Once you run the code in landscape mode with the 2 values swapped, you’ll know what number to reduce.
@kendog400 You might like this code.
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
function setup()
rectMode(CENTER)
cc={x=WIDTH/2,y=50}
suit={"??","??","??","??"}
val={"2","3","4","5","6","7","8","9","10","J","Q","K","A"}
show=-1
tab={}
for y=1,4 do
for x=1,13 do
table.insert(tab,vec2(x*60+75,y*90+300))
end
end
done=true
offset=0
end
function draw()
background(0)
fill(255)
text("Tap screen to shuffle",WIDTH/2,HEIGHT-50)
if show>0 then
for z=1,show do
card(tab[z].x,tab[z].y,sDeck[z],1)
end
end
fill(0, 92, 255, 255)
if offset<=#tab then
rect(WIDTH/2,50,50,80)
rect(cc.x,cc.y,50,80)
end
end
function touched(t)
if t.state==BEGAN and done then
shuffle()
deal()
end
end
function deal()
cc={x=WIDTH/2,y=50}
show=show+1
offset=offset+1
done=false
sound("Game Sounds One:Whoosh 2")
if offset<=#tab then
t1=tween(.2,cc,{x=tab[offset].x,y=tab[offset].y},{loop=tween.loop.once},deal)
else
done=true
end
end
function shuffle()
offset=0
show=-1
sDeck={}
local t={}
for z=1,52 do
t[z]=z
end
for z=1,52 do
v=math.random(#t)
sDeck[z]=t[v]
table.remove(t,v)
end
end
function card(x,y,v,sc) -- x,y position Card value 1 to 52 sc=size of card
scale(sc)
local c=(v-1)%13
local s=(v-1)//13+1
fill(255)
stroke(0, 255, 182, 255)
strokeWidth(3)
rect(x,y,45,60)
fill(255,0,0)
if s<3 then
fill(0)
end
fontSize(25)
text(val[c+1],x,y)
fontSize(14)
text(suit[s],x-10,y+18)
text(suit[s],x+10,y-18)
scale(1/sc)
end