data "1,5,3,7,2", "5,3,7,2,6,4,5,9,1,2", "2,6,3,5,2,8,1,4,2,2,5,3,5,7,4,1", "5,5,5,5", "5,6,7,8", "8,7,7,6", "6,7,10,7,6"
nomainwin
dim array$( 20, 20)
WindowWidth = 400
WindowHeight = 500
open "Water Towers" for graphics_nsb as #wg
#wg "trapclose quit"
#wg "down ; fill darkblue"
#wg "font Ubuntu_Mono 15 bold"
for k =1 to 7
rain =0
read wt$
towersIn =1
for i =1 to len( wt$)
if mid$( wt$, i, 1) ="," then towersIn =towersIn +1
next i
#wg "cls"
gosub [clearArray]
for i =1 to towersIn
v =val( word$( wt$, i, ","))
for j =0 to 20
if j <v then array$( i, j) ="red" else array$( i, j) ="white" ' red if tower, white if empty
#wg "backcolor "; array$( i, j)
#wg " color "; array$( i, j)
#wg "up ; goto "; 20 +i *20; " "; 450 -20 *j; " ; down ; boxfilled "; 40 +i *20; " "; 430 -20 *j
next j
next i
call delay 1000
#wg "getbmp scr 0 0 400 500"
bmpsave "scr", "rain" +str$( k) +"a.bmp"
for i =2 to towersIn -1
for v =0 to 19
me$ =array$( i, v)
left$ =array$( i -1, v)
right$ =""
for w =i +1 to towersIn
if array$( w, v) ="red" then right$ ="red"
next w
if ( me$ ="white" and left$ ="red" and right$ ="red") or ( me$ ="white" and left$ ="cyan" and right$ ="red") then
array$( i, v) ="cyan": rain =rain +1
end if
#wg "backcolor "; array$( i, v)
#wg " color "; array$( i, v)
#wg "up ; goto "; 20 +i *20; " "; 450 -20 *v; " ; down ; boxfilled "; 40 +i *20; " "; 430 -20 *v
next v
next i
#wg "up ; goto 100 80 ; down ; color black"
#wg "\" +"Run "; k; " Rain ="; rain
#wg "getbmp scr 0 0 400 500"
bmpsave "scr", "rain" +str$( k) +"b.bmp"
call delay 1000
next k
wait
end
sub quit h$
close #wg
end
end sub
[clearArray]
for i =0 to 10
for j =0 to 20
array$( i, j) ="" ' state not known
next j
next i
return
sub delay t
timer t, [o]
wait
[o]
timer 0
end sub