ピコピココード
g=ppgraph
v=ppscreen
B=v:size()
Bw=B.width
se=ppsemml[1]
tex=pptex:load("main.png")
pptex:default(tex)
function cell(v)
local r=pprect(0,0,16,16)
r.v=v
r.draw=function(s,p,y)
local t
t=pppoint(p)
t:move(s)
t:move(0,y)
-- g:pos(t)
-- g:print(s.v)
g:put(t,s.v+1)
end
return r
end
function line(x,y)
local r=pprect(x,y,64,64*3)
r.d=0
r.v={}
r.sval=1
r.run=false
r.stop=true
for i=1,6 do
local c
c=cell(i)
c.y=i*32-32
r.v[#r.v+1]=c
end
r.draw=function(s)
for i=1,8 do
s.d=s.d+1
if not s.run
and s.sval==s:ind() then
local a
local b
a=math.floor((s.d-1)/32)
b=math.floor((s.d-2)/32)
if a~=b then
s.d=s.d-1
s.stop=true
end
end
if s.d>#s.v*32 then
s.d=s.d-#s.v*32
end
end
v:viewport(s)
g:scale(2,2)
g:pos(s/2)
for i,v in ipairs(s.v)
do
v:draw(s/2,s.d)
v:draw(s/2,s.d-#s.v*32)
end
g:scale(1)
end
r.ind=function(s,i)
local t
t=#s.v-math.floor((s.d+16)/32)
t=((t+1)%#s.v)+1
return t
end
r.val=function(s,i)
return s.v[s:ind(i)].v
end
return r
end
l={}
dx=(Bw-192)/2
l[#l+1]=line(dx,32)
l[#l+1]=line(dx+64,32)
l[#l+1]=line(dx+128,32)
bt=ppbutton("STOP")
bt.height=64
p=g:layout(bt,true,true,B)
bt:pos(p)
bt:move(0,32)
stopbt=bt
bt=ppbutton("BET")
bt.height=64
bt.y=stopbt.y
betbt=bt
idx=4
coin=100
bet=0
run=false
function stopval()
l[1].sval=math.random(1,6)
l[2].sval=math.random(1,6)
l[3].sval=math.random(1,6)
end
--stopval()
function start()
v:viewport(B)
for i,v in ipairs(l) do
v:draw()
end
v:viewport(B)
local lv={}
for i,v in ipairs(l) do
if v.stop then
g:pos(v)
g:move(0,-16)
lv[i]=v:val(1)
--g:print(lv[i])
end
end
if run and #lv>=3 then
run=false
local atari=0
local ch=0
if lv[1]==6 then
ch=2
if lv[2]==6 then
ch=8
if lv[3]==6 then
ch=16
end
end
end
atari=ch
if lv[1]==lv[2]
and lv[2]==lv[3]
and lv[1]==1 then
atari=400
end
if lv[1]==lv[2]
and lv[2]==lv[3]
and lv[1]==2 then
atari=100
end
coin=coin+bet*atari
bet=0
end
if stopbt:idle(pptouch()) then
if idx>3 then
if bet>0 and #lv==3 then
idx=1
for i,v in ipairs(l) do
v.run=true
v.stop=false
end
run=true
stopval()
lv={}
se:play("o6cgc")
end
else
l[idx].run=false
idx=idx+1
se:play("o7c")
end
end
stopbt:draw()
if betbt:idle(pptouch()) then
if coin>0 and #lv==3 then
bet=bet+1
coin=coin-1
se:play("o7cd")
end
end
betbt:draw()
g:pos(0,16)
g:print(bet)
g:pos(0,32)
g:print(coin)
end