to caos (local "n "r) repeat 100 [ make "r random 2 make "n (1 + random 5) ifelse :r = 0 [repeat :n [IzqHor]] [repeat :n [DerHor]] ] end to DerAntihor local "nn push "listamovs "D make "nn [] push "nn item 1 :numeros push "nn item 2 :numeros push "nn item 21 :numeros push "nn item 20 :numeros push "nn item 19 :numeros push "nn item 18 :numeros push "nn item 17 :numeros push "nn item 16 :numeros push "nn item 15 :numeros push "nn item 14 :numeros push "nn item 11 :numeros push "nn item 10 :numeros push "nn item 9 :numeros push "nn item 8 :numeros push "nn item 7 :numeros push "nn item 6 :numeros push "nn item 5 :numeros push "nn item 4 :numeros push "nn item 3 :numeros push "nn item 12 :numeros push "nn item 13 :numeros make "numeros :nn end to DerHor local "nn push "listamovs "d make "nn [] push "nn item 19 :numeros push "nn item 18 :numeros push "nn item 17 :numeros push "nn item 16 :numeros push "nn item 15 :numeros push "nn item 14 :numeros push "nn item 13 :numeros push "nn item 12 :numeros push "nn item 1 :numeros push "nn item 2 :numeros push "nn item 11 :numeros push "nn item 10 :numeros push "nn item 9 :numeros push "nn item 8 :numeros push "nn item 7 :numeros push "nn item 6 :numeros push "nn item 5 :numeros push "nn item 4 :numeros push "nn item 3 :numeros push "nn item 20 :numeros push "nn item 21 :numeros make "numeros :nn end to Distancia :p1 :p2 output sqrt (((first :p1)-(first :p2))*((first :p1)-(first :p2))+((last :p1)-(last :p2))*((last :p1)-(last :p2))) end to Ejecuta :lista mostrar :l "borrar foreach :lista [ if ?="i [IzqHor] if ?="I [IzqAntiHor] if ?="d [DerHor] if ?="D [DerAntiHor] ] mostrar :l "normal end to IzqAntihor local "n push "listamovs "I repeat 10 [ make "n item 12 :numeros make "numeros remove :n :numeros push "numeros :n ] end to IzqHor local "n push "listamovs "i repeat 2 [ make "n item 12 :numeros make "numeros remove :n :numeros push "numeros :n ] end to jugar ; Principal; empezar por aquí make "caseignoredp "false cs gifload "puzzler.gif pu ht setxy -500 500-343 bitcut 559 343 setxy -559/2+10 -343/2-6 bitpaste make "numeros [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21] make "listamovs [] mostrar :l "normal setfocus [MSWLogo Screen] keyboardon [MiraTeclado] mouseon [MiraRaton] [] [] [] [] end to MiraRaton if ((Distancia mousepos [-100 0]) < 40) [ mostrar :l "borrar ifelse ((last mousepos) > 0) [IzqHor] [IzqAntihor] mostrar :l "normal ] if ((Distancia mousepos [110 0]) < 40) [ mostrar :l "borrar ifelse ((last mousepos) > 0) [DerHor] [DerAntihor] mostrar :l "normal ] end to MiraTeclado (local "t "m) make "t keyboardvalue ;print :t if :t=105 [ ; i = Rueda izquierda en sentido horario mostrar :l "borrar IzqHor mostrar :l "normal ] if :t=73 [ ; I = Rueda izquierda en sentido antihorario mostrar :l "borrar IzqAntihor mostrar :l "normal ] if :t=100 [ ; d = Rueda derecha en sentido horario mostrar :l "borrar DerHor mostrar :l "normal ] if :t=68 [ ; D = Rueda derecha en sentido antihorario mostrar :l "borrar DerAntihor mostrar :l "normal ] if :t=101 [ ; e = Ordenar mostrar :l "borrar make "numeros [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21] make "listamovs [] mostrar :l "normal ] if :t=99 [ ; c = Desordenar mostrar :l "borrar caos make "listamovs [] mostrar :l "normal ] if :t=8 [ ; backspace = Retroceder if :listamovs = [] [stop] mostrar :l "borrar make "m pop "listamovs if :m="i [IzqAntihor] if :m="I [IzqHor] if :m="d [DerAntihor] if :m="D [DerHor] make "m pop "listamovs mostrar :l "normal ] if :t=111 [ ; o = iDId mostrar :l "borrar IzqHor DerAntihor IzqAntihor DerHor mostrar :l "normal ] if :t=112 [ ; p = idID mostrar :l "borrar IzqHor DerHor IzqAntihor DerAntihor mostrar :l "normal ] end to mostrar :l :borrar ; Dibuja (o borra) el puzzle (local "o "i "n) home rt 180 make "i 0 ; Rueda izquierda repeat 6 [ make "o heading make "i :i+1 make "n item :i :numeros ifelse :borrar = "borrar [setpc [255 255 255]] [ ifelse :n=:i [setpc [0 0 0]] [setpc [255 0 0]] ] seth 90 label :n seth :o fd :l make "i :i+1 make "n item :i :numeros ifelse :borrar = "borrar [setpc [255 255 255]] [ ifelse :n=:i [setpc [0 0 0]] [setpc [255 0 0]] ] seth 90 label item :i :numeros seth :o rt 60 fd :l ] ; Rueda derecha rt 180 fd :l rt 60 fd :l repeat 4 [ make "o heading make "i :i+1 make "n item :i :numeros ifelse :borrar = "borrar [setpc [255 255 255]] [ ifelse :n=:i [setpc [0 0 0]] [setpc [255 0 0]] ] seth 90 label :n seth :o fd :l make "i :i+1 make "n item :i :numeros ifelse :borrar = "borrar [setpc [255 255 255]] [ ifelse :n=:i [setpc [0 0 0]] [setpc [255 0 0]] ] seth 90 label :n seth :o rt 60 fd :l ] make "i :i+1 make "n item :i :numeros ifelse :borrar = "borrar [setpc [255 255 255]] [ ifelse :n=:i [setpc [0 0 0]] [setpc [255 0 0]] ] seth 90 label :n end Make "ciclo_huesos [i D I d I D i d I D i i d I] Make "ciclo_piedras [I I I I d i i D i d I D I d i D i d I D I d i i D i d I D i d I D i d I I D i d I D i d I D i d I I I D i i i i] Make "clave_movs [a mov_a_hor A mov_a_antihor b mov_b_hor B mov_b_antihor c mov_c_hor C mov_c_antihor d mov_d_hor D mov_d_antihor] Make "l 60 Make "listamovs [] Make "numeros [1 2 5 4 3 8 7 6 9 10 11 12 13 14 15 16 17 18 19 20 21]