Game "playing with buckets" (iPad version)

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Game "playing with buckets" (iPad version)

Post by Henko »

This was a well known game on hobby computers in the past century.
You have 3 buckets (or cans) of different size and each initially filled with an amount of liquid. You repeatedly pour the contents of a bucket in another bucket to finish up with a bucket with a predefined volume of liquid.
This version is a simple one with only one set of buckets and starting volumes. The game could also be made fit for iPhones (anyone?). A little music or sound of flowing liquid could be added and pouring the content of a bucket into another could be animated. Those are however game attributes in wich i am not interested. There are forum members who are far better than me in that respect.
Another extension would be to add more bucket sets. The could be loaded into the program from a file, or be generated by an analyzing program function.
In the program, buckets are named "cans". The liquid used has a yellow color, which is my favourite color for liquid.

Code: Select all

option base 1 ! randomize
graphics ! graphics clear ! draw color 0,0,0
dim vm(3),vo(3),v(3),val(9),sol(5,2)

init_prog
loop: slowdown
if bp("reset") then reset_cans(vm,v)
if bp("sol") then
  reset_cans(vm,v)
  for i=1 to k_ind
    draw text sol(i,1) & "->" & sol(i,2) at 270-60*k_ind+120*i,820
    next i
  end if
get touch 0 as xt,yt ! if xt=-1 then loop
for i=1 to 3
  xo=200*i-100 ! ye=700-30*vm(i)
  if xt>xo and xt<xo+120 and yt<700 and yt>ye then break
  next i
if i=4 then loop else pause .3
if select=0 then
  draw_can(vm(i),v(i),200*i-100,700,.3)
  select=i ! goto loop
  end if
if select=i then
  draw_can(vm(i),v(i),200*i-100,700,1)
  select=0 ! goto loop
  end if
q=trans(select,i) ! v(select)-=q ! v(i)+=q
draw_can(vm(select),v(select),200*select-100,700,1)
draw_can(vm(i),v(i),200*i-100,700,1)
select=0 ! pause .3
if not done then loop
end

def reset_cans(vm(),v())
for i=1 to 3 ! v(i)=.vo(i) ! next i ! draw_cans(vm,v)
end def

def draw_cans(vm(),v())
for i=1 to 3 ! draw_can(vm(i),v(i),200*i-100,700,1) ! next i
end def

def draw_can(size,vol,x,y,alfa)
t=12 ! draw size t ! draw color .3,.3,.3
h=30*size ! w=120 ! tt=t/2
fill rect x-tt+1,y+tt-1 to x+w+tt-1,y-h
draw alpha alfa ! fill alpha alfa
draw line x,y to x,y-h
draw line x-tt,y to x+w+tt,y
draw line x+w,y to x+w,y-h
draw size 2 ! draw line x-tt,y-h to x+w+tt,y-h
fill rect x+tt,y-tt to x+w-tt,y-h+2
fill color .9,.9,0
if vol then fill rect x+tt,y-tt to x+w-tt,y-30*vol
fill color 1,1,1
xm=x+60-t/2
for i=1 to size ! ym=y-30*i ! draw line xm,ym to xm+t,ym ! next i
end def

def done
for i=1 to 3 ! if .v(i)=.target then break ! next i
if i>3 then return 0
draw color 0,0,1 ! draw text .target & "!" at 200*i-58,612
return 1
end def

def bp(a$) = button_pressed(a$)
def trans(i,j) = min(.v(i),.vm(j)-.v(j))

def init_prog
for i=1 to 5 ! read .diff$(i) ! next i
for i=1 to 3 ! read .vm(i),.vo(i) ! .v(i)=.vo(i) ! next i
for i=1 to 7 ! read .val(i) ! next i
for i=1 to 5 ! for j=1 to 2 ! read .sol(i,j) ! next j ! next i
data "little kids","easy","moderate","difficult","irritating"
data 5,3, 8,5, 8,5
data 0,2,8,6,7,1,4
data 2,3, 3,1, 1,2, 3,1, 1,2
draw font size 30
draw text "Pour cans into other cans and try to get" at 20,10
draw text "the indicated quantity in one of the cans" at 20,40
draw text "with the least amount of operations." at 60,70
draw font size 20
draw text "first touch the can to pour from, then touch" at 80,110
draw text " the can to pour into" at 230,130
draw color 0,0,1 
draw text "choose difficulty level" at 230,180
for i=1 to 5 ! button i text .diff$(i) at 140*i-120,220 size 120,30 ! next i
wait: slowdown
for k=1 to 5 ! if bp(""&k) then break ! next k
if k>5 then wait
button "6" title "^" at 140*k-70,260 size 20,25 ! .k_ind=k
if k=1 then .target=.val(1+rnd(3))
for i=2 to 5 ! if k=i then .target=.val(i+2) ! next i
draw font size 30
draw text "Try to produce a can with " & .target & " liters." at 50,320
draw_cans(.vm,.v)
button "reset" title "reset" at 200,740 size 120,50
button "sol" title "solution" at 400,740 size 120,50
end def

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: Game "playing with buckets" (iPad version)

Post by Dav »

I enjoyed this. Thanks.

- Dav

Post Reply