! SameGame for PiBasic ! 2016.2.13. Toshi Nagata ! UTF-8 encoding xx = 18 ! 盤面の幅 yy = 12 ! 盤面の高さ n = 5 ! 駒の種類 num = 0 ! 残り駒の数 point = 0 ! ポイント cx = 0 ! 現在のカーソル位置 (x) cy = 0 ! 現在のカーソル位置 (y) dim board(xx, yy) ! 盤面 sub disppiece(x, y) global board(*,*), cx, cy c = board(x, y) if c = 1 then col = 1 : s$ = "♦♦" elseif c = 2 then col = 2 : s$ = "♥♥" elseif c = 3 then col = 3 : s$ = "♣♣" elseif c = 4 then col = 4 : s$ = "♠♠" elseif c = 5 then col = 5 : s$ = "**" else col = 7 : s$ = "  " end if if x = cx and y = cy then bcol = 8 else bcol = 0 end if color col, bcol locate x * 4, y * 2 + 1 print s$; locate x * 4, y * 2 + 2 print s$; end sub sub dispinfo() global num, point color 7, 0 locate 0, 0 : print "【さめがめ for PiBasic】 "; print "残り "; num; " "; print "得点 "; point; " "; clearline end sub sub display() global xx, yy, board(*,*), num, point for x = 0 to xx - 1 for y = 0 to yy - 1 call disppiece(x, y) next next call dispinfo() end sub func mark(x, y) global xx, yy, board(*,*) c = board(x, y) board(x, y) = c + 100 n = 1 if x > 0 and board(x - 1, y) = c then n = n + mark(x - 1, y) if x < xx - 1 and board(x + 1, y) = c then n = n + mark(x + 1, y) if y > 0 and board(x, y - 1) = c then n = n + mark(x, y - 1) if y < yy - 1 and board(x, y + 1) = c then n = n + mark(x, y + 1) return n end func for x = 0 to xx - 1 for y = 0 to yy - 1 board(x, y) = int(rnd() * n) + 1 next next num = xx * yy cls call display() do @redo ch = inkey() if ch = 27 then exit do wx = cx wy = cy if ch = 28 then cx = mod(cx + 1, xx) elseif ch = 29 then cx = mod(cx - 1, xx) elseif ch = 30 then cy = mod(cy - 1, yy) elseif ch = 31 then cy = mod(cy + 1, yy) elseif ch = 13 then n = mark(cx, cy) if n = 1 then board(cx, cy) = board(cx, cy) - 100 else for x = 0 to xx - 1 for y = 0 to yy - 1 if board(x, y) > 100 then call disppiece(x, y) next next for x = 0 to xx - 1 y1 = yy - 1 for y = yy - 1 to 0 step -1 if board(x, y) < 100 then board(x, y1) = board(x, y) y1 = y1 - 1 end if next do while y1 >= 0 board(x, y1) = 0 y1 = y1 - 1 loop next x1 = 0 for x = 0 to xx - 1 if board(x, yy - 1) = 0 then @next if x <> x1 then for y = 0 to yy - 1 board(x1, y) = board(x, y) next end if x1 = x1 + 1 @next next for x1 = x1 to xx - 1 for y = 0 to yy - 1 board(x1, y) = 0 next next point = point + (n - 2) * (n - 2) num = num - n call display() end if goto @redo end if if wx <> cx or wy <> cy then call disppiece(wx, wy) call disppiece(cx, cy) end if loop locate 0, yy * 2 + 3 color 7, 0