- 50E95A02-714C-4D5F-8094-30B2848079C5.png (848.92 KiB) Viewed 4378 times
- Roulette.zip
- (621.05 KiB) Downloaded 3285 times
Code: Select all
' roulette project (final version oct. 25, 2019)
'
bw=64 ' basic dimension for generated board
xo=20 ! yo=20 ' left upper position of board
xr=485 ! yr=80 ' left upper corner of wheel and other controls
pot=2000 ' starting amount of money
prog_init
draw_board1(bw,xo,yo) ! draw_control_area(xr,yr)
do
init_round()
bidding()
number=wheel(619,214,70,120,0,15,.2)
payouts(number)
do slowdown
if bp("quit") then end_program()
if bp("go_on") then break
until forever
until forever
end
def prog_init()
graphics ! graphics clear 1,1,1 ! draw color 0,0,0
set toolbar off ! randomize
get screen size sw,sh
win(2,2,sw-2,sh-2,20,4,0,0,.5)
button "go_on" text "Next round" at 20,sh-50 size 120,30
button "quit" text "Stop" at 350,sh-50 size 120,30
ss=4 ! bidding.val=1
sprite "ball" begin 2*ss,2*ss
fill color 1,1,1 !fill circle ss,ss size ss
sprite "ball" end
dim .num(38), .col(37) ' field colors (1=red, 0=black)
dim .pos(154,2) ' position of bid buttons
dim .ch(5) ' chip amounts in pot
dim .stat$(201) ' packed string for the stat window
for i=1 to 36 ! read .col(i) ! next i
data 1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1
data 1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1
for i=0 to 37 ! read .num(i) ! next i
data 17,32,20,7,11,30,26,9,28,0,2,14,35
data 23,4,16,33,21,6,18,31,19,8,12,29,25
data 10,27,-1,1,13,36,24,3,15,34,22,5
if file_exists("save_pot") then
file "save_pot" input potsaved
.pot=max(.pot,potsaved)
end if
end def
def init_round()
dim bidding.potwin(43)
p1_bid.flag=1 ! button "turn" text ""
bidding.cur=0 ! bidding.totvalue=0
.pot=.npot ! field "c_pot" text .pot
bidding.totvalue=0 ! field "bid_v" text 0
field "wins" text 0
draw_board1(.bw,.xo,.yo)
end def
def bidding()
do slowdown
for i=0 to 4 ! if bp("c_"&i) then break ! next i
if i<5 then
cur=i ! val=chips.v(i) ! button "cur_chip" text val
end if
for i=1 to 38 ! if bp(str$(i)) then break ! next i
if i<39 then ! p1_bid(i) ! p2_bid(i,36) ! end if
if bp(str$(39)) then
p1_bid(39) ! p2_bid(37,18) ! p2_bid(38,18)
end if
for i=40 to 51 ! if bp(str$(i)) then break ! next i
if i<52 then
k=3*(i-40)
p1_bid(i) ! p2_bid(k+1,18) ! p2_bid(k+2,18)
end if
for i=52 to 63 ! if bp(str$(i)) then break ! next i
if i<64 then
k=3*(i-52)
p1_bid(i) ! p2_bid(k+2,18) ! p2_bid(k+3,18)
end if
for i=64 to 74 ! if bp(str$(i)) then break ! next i
if i<75 then
k=3*(i-64)
p1_bid(i) ! p2_bid(k+1,18) ! p2_bid(k+4,18)
end if
for i=75 to 85 ! if bp(str$(i)) then break ! next i
if i<86 then
k=3*(i-75)
p1_bid(i) ! p2_bid(k+2,18) ! p2_bid(k+5,18)
end if
for i=86 to 96 ! if bp(str$(i)) then break ! next i
if i<97 then
k=3*(i-86)
p1_bid(i) ! p2_bid(k+3,18) ! p2_bid(k+6,18)
end if
for i=97 to 108 ! if bp(str$(i)) then break ! next i
if i<109 then
k=3*(i-97) ! p1_bid(i)
for i=1 to 3 ! p2_bid(k+i,12) ! next i
end if
if bp(str$(109)) then
p1_bid(109) ! p2_bid(37,12) ! p2_bid(38,12) ! p2_bid(2,12)
end if
for i=110 to 120 ! if bp(str$(i)) then break ! next i
if i<121 then
k=3*(i-110) ! p1_bid(i)
p2_bid(k+1,9) ! p2_bid(k+2,9) ! p2_bid(k+4,9) ! p2_bid(k+5,9)
end if
for i=121 to 131 ! if bp(str$(i)) then break ! next i
if i<132 then
k=3*(i-121) ! p1_bid(i)
p2_bid(k+2,9) ! p2_bid(k+3,9) ! p2_bid(k+5,9) ! p2_bid(k+6,9)
end if
if bp(str$(132)) then
p1_bid(132) ! p2_bid(37,7) ! p2_bid(38,7)
for i=1 to 3 ! p2_bid(i,7) ! next i
end if
for i=133 to 143 ! if bp(str$(i)) then break ! next i
if i<144 then
k=3*(i-133)+1 ! p1_bid(i)
for i=k to k+5 ! p2_bid(i,6) ! next i
end if
if bp(str$(144)) then
p1_bid(144) ! for i=1 to 12 ! p2_bid(i,3) ! next i
end if
if bp(str$(145)) then
p1_bid(145) ! for i=13 to 24 ! p2_bid(i,3) ! next i
end if
if bp(str$(146)) then
p1_bid(146) ! for i=25 to 36 ! p2_bid(i,3) ! next i
end if
if bp(str$(147)) then
p1_bid(147) ! for i=1 to 34 step 3 ! p2_bid(i,3) ! next i
end if
if bp(str$(148)) then
p1_bid(148) ! for i=2 to 35 step 3 ! p2_bid(i,3) ! next i
end if
if bp(str$(149)) then
p1_bid(149) ! for i=3 to 36 step 3 ! p2_bid(i,3) ! next i
end if
if bp(str$(150)) then ! p1_bid(150) ! p2_bid(39,2) ! end if
if bp(str$(151)) then ! p1_bid(151) ! p2_bid(40,2) ! end if
if bp(str$(152)) then ! p1_bid(152) ! p2_bid(41,2) ! end if
if bp(str$(153)) then ! p1_bid(153) ! p2_bid(42,2) ! end if
until bp("turn") and p1_bid.flag=0
end def
def p1_bid(k)
if chips(.ch,0)-bidding.val<0 then ! bidding.val=0 ! return ! end if
if flag then ! flag=0 ! button "turn" text "Turn the wheel" ! end if
val=bidding.val ! chips(.ch,-val) ! disp_chips()
bidding.totvalue+=val ! field "bid_v" text bidding.totvalue
.npot-=val ! field "n_pot" text .npot
fill color 0,1,0
fill circle .pos(k,0),.pos(k,1) size 9
fill color 1,1,1
end def
def p2_bid(pwn,pay)
bidding.potwin(pwn)+=pay*bidding.val
end def
def disp_chips()
fill rect .xr+30,490 to .xr+260,520
for i=0 to 4 ! draw text .ch(i) at .xr+30+50*i,490 ! next i
end def
def payouts(number)
wins=0 ! if number<1 then number=37-number
dw=bidding.potwin(number)
if dw then add_win(dw)
if number<37 then
if .col(number) then red=1 else red=0 ! black=1-red
if even(number) then evene=1 else evene=0 ! odde=1-evene
wred=bidding.potwin(39) ! if wred and red then add_win(wred)
wblk=bidding.potwin(40) ! if wblk and black then add_win(wblk)
weve=bidding.potwin(41) ! if weve and evene then add_win(weve)
wodd=bidding.potwin(42) ! if wodd and odde then add_win(wodd)
end if
.npot+=wins ! field "n_pot" text .npot
v=chips(.ch,wins) ! disp_chips()
'y'
if icl<200 then
.stat$(icl)=str$(number)&" , "&bidding.totvalue&" , "&wins&" , "
eff=int(100*(wins-bidding.totvalue)/bidding.totvalue)
.stat$(icl)&=eff&"%" ! icl+=1
c_list("xyz"," Bid results",.stat$,icl,.xr+25,660,220,330)
end if
''
if v<=0 then
button "turn" text "YOU ARE BROKE!" ! stop
end if
end def
def add_win(dw)
beep ! payouts.wins+=dw
field "wins" text payouts.wins
pause .5
end def
def draw_board1(bw,xo,yo)
bw2=2*bw ! bw3=3*bw ! bw4=4*bw
draw size 4 ! fill color 1,1,1 ! fill rect 15,15 to 450,920
draw line xo+bw2,yo to xo+bw2+bw3,yo
draw line xo,yo+bw to xo+bw3+bw4,yo+bw
draw line xo,yo+13*bw to xo+bw3+bw4,yo+13*bw
draw line xo+bw2,yo+14*bw to xo+bw2+bw3,yo+14*bw
draw line xo+bw2,yo to xo+bw2,yo+14*bw
draw line xo+bw2+bw3,yo to xo+bw2+bw3,yo+14*bw
draw line xo,yo+bw to xo,yo+13*bw
draw line xo+bw3+bw4,yo+bw to xo +bw3+bw4,yo+13*bw
draw line xo,yo+bw+bw3 to xo+bw2,yo+bw+bw3
draw line xo,yo+bw+2*bw3 to xo+bw2,yo+bw+2*bw3
draw line xo,yo+bw+3*bw3 to xo+bw2,yo+bw+3*bw3
draw line xo+bw2+bw3,yo+bw+bw4 to xo+bw4+bw3,yo+bw+bw4
draw line xo+bw2+bw3,yo+bw+2*bw4 to xo+bw4+bw3,yo+bw+2*bw4
draw line xo+bw2+bw3/2,yo to xo+bw2+bw3/2,yo+bw
draw line xo+bw3,yo+13*bw to xo+bw3,yo+14*bw
draw line xo+bw4,yo+13*bw to xo+bw4,yo+14*bw
draw size 2
draw line xo+bw3,yo+bw to xo+bw3,yo+13*bw
draw line xo+bw4,yo+bw to xo+bw4,yo+13*bw
for i=2 to 12
draw line xo+bw2,yo+i*bw to xo+bw2+bw3,yo+i*bw
next i
for i=1 to 3 ! for j=0 to 11
k=i+3*j ! c=.col(k) ! x=xo+(i+1)*bw+2 ! y=yo+(j+1)*bw+2
if c then fill color .8,0,0 else fill color .2,.2,.2
fill rect x,y to x+bw-2,y+bw-3
bsiz=30 ! ds=(bw-bsiz)/2 ! xx=x+ds ! yy=y+ds
button k text k at xx,yy size bsiz,bsiz ! put(k,xx,yy)
next j ! next i
bs=.7*bw ! fill color 1,1,1
set buttons font size int(bw/3.12)
xx=int(xo+(5.5*bw-bs)/2) ! yy=int(yo+(bw-bs)/2)
button 37 text "0" at xx,yy size bs,bs ! put(37,xx,yy)
xx=int(xo+(8.5*bw-bs)/2) ! yy=int(yo+(bw-bs)/2)
button 38 text "00" at xx,yy size bs,bs ! put(38,xx,yy)
xx=int(xo+bw-bs) ! yy=int(yo+bw+(bw3-bs)/2)
button 150 text "Red" at xx,yy size 2*bs,bs ! put(150,xx,yy)
xx=int(xo+bw-bs) ! yy=int(yo+bw4+(bw3-bs)/2)
button 153 text "Odd" at xx,yy size 2*bs,bs ! put(153,xx,yy)
xx=int(xo+bw-bs) ! yy=int(yo+8.5*bw-bs/2)
button 152 text "Even" at xx,yy size 2*bs,bs ! put(152,xx,yy)
xx=int(xo+bw-bs) ! yy=int(yo+11.5*bw-bs/2)
button 151 text "Black" at xx,yy size 2*bs,bs ! put(151,xx,yy)
xx=int(xo+6*bw-bs) ! yy=int(yo+bw3-bs/2)
button 144 text "1-12" at xx,yy size 2*bs,bs ! put(144,xx,yy)
xx=int(xo+6*bw-bs) ! yy=int(yo+7*bw-bs/2)
button 145 text "13-24" at xx,yy size 2*bs,bs ! put(145,xx,yy)
xx=int(xo+6*bw-bs) ! yy=int(yo+11*bw-bs/2)
button 146 text "25-36" at xx,yy size 2*bs,bs ! put(146,xx,yy)
xx=int(xo+2.5*bw-bs/2) ! yy=int(yo+13.5*bw-bs/2)
button 147 text "^" at xx,yy size bs,bs ! put(147,xx,yy)
xx=int(xo+3.5*bw-bs/2)
button 148 text "^" at xx,yy size bs,bs ! put(148,xx,yy)
xx=int(xo+4.5*bw-bs/2)
button 149 text "^" at xx,yy size bs,bs ! put(149,xx,yy)
bs=14 ! xb=int(xo+bw2-bs/2) ! xs=xb+7
for i=1 to 12
yy=int(yo+(i+0.5)*bw-bs/2) ! ys=yy+7
button 96+i text "" at xb,yy size bs,bs ! put(96+i,xs,ys)
button 39+i text "" at xb+bw,yy size bs,bs ! put(39+i,xs+bw,ys)
button 51+i text "" at xb+bw2,yy size bs,bs ! put(51+i,xs+bw2,ys)
next i
xb=xo+bw2+(bw-bs)/2 ! xs=xb+7
for i=1 to 11
yy=int(yo+(i+1)*bw-bs/2) ! ys=yy+7
button 63+i text "" at xb,yy size bs,bs ! put(63+i,xs,ys)
button 74+i text "" at xb+bw,yy size bs,bs ! put(74+i,xs+bw,ys)
button 85+i text "" at xb+bw2,yy size bs,bs ! put(85+i,xs+bw2,ys)
next i
xb=xo+bw3-bs/2 ! xs=xb+7
for i=1 to 11
yy=int(yo+(i+1)*bw-bs/2) ! ys=yy+7
button 109+i text "" at xb,yy size bs,bs ! put(109+i,xs,ys)
button 120+i text "" at xb+bw,yy size bs,bs ! put(120+i,xs+bw,ys)
button 132+i text "" at xb+bw2,yy size bs,bs !put(132+i,xs+bw2,ys)
next i
xx=int(xo+bw2-bs/2) ! yy=int(yo+bw-bs/2)
button 132 text "" at xx,yy size bs,bs ! put(132,xx+7,yy+7)
xx=int(xo+3.5*bw-bs/2) ! yy=int(yo+(bw-bs)/2)
button 39 text "" at xx,yy size bs,bs ! put(39,xx+7,yy+7)
xx=int(xo+3.5*bw-bs/2) ! yy=int(yo+bw-bs/2)
button 109 text "" at xx,yy size bs,bs ! put(109,xx+7,yy+7)
button "cur_chip" text bidding.val at 60,28 size 45,45
end def
def draw_board2(bw,xo,yo)
draw image "roulette.jpg" at xo,yo scale 1.203
end def
def draw_control_area(xr,yr)
draw image "wheel.jpg" at xr,yr
chips(.ch,.pot) ' spread the starting pot over the chips
set buttons custom
set buttons font size 24
button "turn" text "" at .xr+20,380 size 230,40
set buttons font size 14
fill rect .xr+20,488 to .xr+260,520
fill alpha 0
for i=0 to 4
xx=.xr+20+50*i
button "c_"&i text "" at xx,440 size 40,40
fi$="fiche_"&i&".jpg"
draw image fi$ at xx-4,436 scale .4
draw text .ch(i) at .xr+35+50*i,490
next i
set buttons default ! fill alpha 1
.npot=.pot
draw text "Current pot : " at .xr+20,530
field "c_pot" text .pot at .xr+185,526 size 80,30 RO
draw text "Bid value : " at .xr+20,560
field "bid_v" text 0 at .xr+185,556 size 80,30 RO
draw text "Winnings : " at .xr+20,590
field "wins" text 0 at .xr+185,586 size 80,30 RO
draw text "New pot : " at .xr+20,620
field "n_pot" text .pot at .xr+185,616 size 80,30 RO
draw size 4
win(.xr+20,660,.xr+250,1000,12,4,0,0,0.5)
draw size 1
end def
def wheel(cx,cy,ri,ru,ai,au,fric)
rad=atan(1)/45 ! ai*=rad ! au*=rad
p=(tan(au)-tan(ai))/(ru-ri)/2 ! q=tan(ai)-2*p*ri
vs=sqrt(9.81*ru*(2*p*ru+q)) ! dt=2/vs
vt=(1+0.7*rnd(1))*vs ! vr=0 ! r=ru
psi=rad*rnd(360)
do
a=atan(2*p*r+q)
psi+=(vt*dt-.5*fric*dt*dt)/r ! if psi>=2*pi then psi-=2*pi
ar=9.81*sin(a)-vt*vt/r*cos(a)
if ar>0 then ! r-=(vr*dt+.5*ar*dt*dt)*cos(a) ! vr+=ar*dt ! end if
x=cx+r*cos(psi) ! y=cy-r*sin(psi)
sprite "ball" at x-4,y-4 ! sprite "ball" show
vt-=fric*dt !
pause .01
if bp("quit") then stop
until vt<=0
alfa=int(psi/rad)
number=int((psi-4.5*rad)*19/pi) ! psi=4.5*rad+pi*number/19
x=cx+r*cos(psi) ! y=cy-r*sin(psi)
sprite "ball" at x-4,y-4 ! sprite "ball" show
number=.num(number)
file "roulette_stat" print number,alfa
if number=-1 then n$="00" else n$=str$(number)
if number>0 then
if even(number) then n$&=", even" else n$&=", odd"
if .col(number) then n$&=", red" else n$&=", black"
end if
button "turn" text n$
return number
end def
def end_program()
f$= "save_pot" ! if file_exists(f$) then file f$ delete
file f$ print .npot
stop
end def
' add/subtract payout, and spread over the chip values
' a() = array with current (in) and new (out) numbers of chips
' ds = payout to be added to the total value
' function returns the new total value
'
def chips(a(),ds)
if not v(0) then
v(0)=1 ! v(1)=5 ! v(2)=10 ! v(3)=25 ! v(4)=100
end if
s=ds ! for i=0 to 4 ! s+=a(i)*v(i) ! next i ! sum=s
for i=0 to 4
nc=min(5,floor(s/v(i))) ! a(i)=nc ! s-=nc*v(i) ! next i
for i=4 to 0 step -1
nc=floor(s/v(i)) ! a(i)+=nc ! s-=nc*v(i)
next i
return sum
end def
' draw a rounded rectangle
' xo,yo,xe,ye -> left upper and right bottom pixel coordinates
' d -> round radius
' t -> line thickness
' r,g,b -> color of line
'
def win(xo,yo,xe,ye,d,t,r,g,b)
pi2=pi/2 ! pi4=pi ! pi6=1.5*pi
fill rect xo,yo to xe,ye
t2=t/2 ! xo+=t2 ! yo+=t2 ! xe-=t2 ! ye-=t2
draw color r,g,b ! draw size t
draw arc xo+d,ye-d,d,pi2,pi4,0 ! draw arc xe-d,ye-d,d,pi2,0,1
draw arc xe-d,yo+d,d,0,pi6,1 ! draw arc xo+d,yo+d,d,pi6,pi4,1
draw line xo+d,yo to xe-d,yo ! draw line xo+d,ye to xe-d,ye
draw line xo,yo+d to xo,ye-d ! draw line xe,yo+d to xe,ye-d
end def
' id$ = object name
' cont$ = array met elementen
' size = aantal elementen in de list
'
def c_list(id$,title$,cont$(),size,xt,yt,w,h)
dim temp$(size)
for i=0 to size-1 ! temp$(i)=cont$(i) ! next i
list id$ text temp$ at xt+2,yt+32 size w-4,h-34
draw size 3 ! draw line xt,yt+30 to xt+w,yt+30
draw color 0,0,1 ! draw text title$ at xt+5,yt+5
end def
def put(k,x,y) ! .pos(k,0)=x ! .pos(k,1)=y ! end def
def bp(a$) = button_pressed(a$)
def bug ! debug pause ! end def
def pi = 3.1415926536