rem ********************* rem puzzle.bas rem ********************* rem def int a-z rem open "t.t" for output as #1 rem tron line #1 on error goto hay_error rem Cambiar esto de acuerdo a gustos o necesidades del sistema default_zoom= 2 zoom= val (programarg$ (1) ) if zoom = 0 then zoom = default_zoom esc$= chr$ (27) xpart= 5 ypart= 4 dim solucion (xpart, ypart) dim tablero (xpart, ypart) n= 1 for y= 1 to ypart for x= 1 to xpart solucion (x, y)= n n= n + 1 next next solucion (xpart, ypart)= 0 gosub define_funciones rem Dimensiones de cada pieza del puzzle xpieza= 21 * zoom ypieza= 13 * zoom ancho= xpart * xpieza alto= ypart * ypieza rem El IF es para compatibilidad descendente cuando se usa zoom 1 if zoom = 1 then mode ancho, alto else mode ancho, alto, 0, zoom, zoom repeat locate 1, 5: print "PUZZLE" locate 3, 1: print "ESC --> Fin" locate 5, 1: print "Otra--> jugar" clear input label pide_opcion repeat get opcion$ until opcion$ <> "RELEASE" if opcion$ <> "CLICK" then goto elegido y= int (ymouse / 8 / zoom) + 1 if y = 3 then opcion$= esc$ else if y <> 5 then goto pide_opcion label elegido cls if opcion$ <> esc$ then gosub partida until opcion$ = esc$ end rem ****************************** label partida rem ****************************** tag gosub barajar gosub pinta_tablero ganador= 0 inicio= time repeat repeat get a$ if a$ ="r" then gosub pinta_tablero until a$ = "CLICK" or a$ = esc$ if a$ = esc$ then goto continuar xx= xmouse: yy= ymouse x= int (xx / xpieza) + 1 y= int (yy / ypieza) + 1 if x > xpart or y > ypart then goto continuar xblanco= 0 for i= 1 to xpart if tablero (i, y) = 0 then xblanco= i next if xblanco <> 0 then goto horizontal yblanco= 0 for i= 1 to ypart if tablero (x, i) = 0 then yblanco= i next if yblanco <> 0 then goto vertical goto continuar label horizontal if xblanco = x then goto continuar if xblanco > x then goto derecha for i= xblanco to x - 1 tablero (i, y)= tablero (i + 1, y) void= fn pinta_pieza (i, y) next goto fin_movida label derecha for i= xblanco to x + 1 step -1 tablero (i, y)= tablero (i - 1, y) void= fn pinta_pieza (i, y) next goto fin_movida label vertical if yblanco = y then goto continuar if yblanco > y then goto abajo for i= yblanco to y - 1 tablero (x, i)= tablero (x, i + 1) void= fn pinta_pieza (x, i) next goto fin_movida label abajo for i= yblanco to y + 1 step - 1 tablero (x, i)= tablero (x, i - 1) void= fn pinta_pieza (x, i) next label fin_movida tablero (x, y)= 0 void= fn pinta_pieza (x, y) if fn victoria then ganador=1: a$= esc$ label continuar until a$ = esc$ final= time tagoff graphics cls if ganador = 0 then return beep for j= 1 to 2 for i= 14 to 0 step -1 pen i locate 2, 2: print "HAS GANADO" locate 4, 4: print "Tiempo" locate 5, 5: print final - inicio pause 200 next next beep clear input get a$ cls return ' Partida rem **************************** label define_funciones rem **************************** rem **************************** def fn pinta_pieza (x, y) rem **************************** local p, xx, yy xx= (x - 1) * xpieza + 1 yy= (y - 1) * ypieza + 1 xx2= xx + xpieza - 3 yy2= yy + ypieza - 3 p= tablero (x, y) graphics pen 15 line (xx, yy) - (xx2, yy2),,bf graphics pen 0 if p <> 0 then line (xx, yy) - (xx2, yy2),,b if p <> 0 and p < 10 then xx= xx + 4 * zoom move xx + 2 * zoom, yy + 2 * zoom if p <> 0 then print p; fn end rem **************************** def fn victoria rem **************************** local x, y victoria= 1 for y= 1 to ypart for x= 1 to xpart if tablero (x, y) <> solucion (x, y) then victoria= 0 next x, y fn end return ' define_funciones rem **************************** label pinta_tablero rem **************************** local x, y for y= 1 to ypart for x= 1 to xpart void= fn pinta_pieza (x, y) next next return rem **************************** label inicia_tablero rem **************************** for y= 1 to ypart for x= 1 to xpart tablero (x, y)= solucion (x, y) next next return rem **************************** label barajar rem **************************** randomize time gosub inicia_tablero x= xpart y= ypart for b= 1 to 500 j= 1 + int (rnd * 4) on j gosub barizq, barder, bararr, baraba next return label barizq if x = 1 then return tablero (x, y)= tablero (x - 1, y) x= x - 1 tablero (x, y) = 0 return label barder if x = xpart then return tablero (x, y)= tablero (x + 1, y) x= x + 1 tablero (x, y)= 0 return label bararr if y = 1 then return tablero (x, y)= tablero (x, y - 1) y= y - 1 tablero (x, y)= 0 return label baraba if y = ypart then return tablero (x, y)= tablero (x, y + 1) y= y + 1 tablero (x, y)= 0 return label hay_error on error goto 0 mode 0 print "Error: "; strerr$ (err); " en linea "; erl end rem ************************** rem Fin de puzzle.bas rem **************************