require "braingame"
require "fltk"

class GUI < Fltk::Window
	COLORS=[ 0x55, 0xF5, 0x5F, 0x45 ]
	def initialize
		dim = 25
		off = 15
		board = GameBoard.new
		size = board.board.size
		super( size*dim+off,(size+1)*dim+(off*2), "Brain Game")
		buttons = []
		cb = proc {|m,n,v|
			buttons[m][n].label v.to_s
			buttons[m][n].color COLORS[v]
			buttons[m][n].redraw
		}
		size.times{ |x|
			buttons[x] = []
			size.times{ |y|
				buttons[x][y] = Fltk::Button.new( x*dim+5, y*dim+5, dim, dim, board.board[x][y].to_s )
				buttons[x][y].color COLORS[0]
				buttons[x][y].callback { board.click( x,y,&cb ) }
			}
		}
		button = Fltk::Button.new( 10, size*dim+off, 50, dim, "New" )
		button.callback { board.clear ; board.scramble(&cb) }
		button = Fltk::Button.new( 60+off, size*dim+off, 50, dim, "Undo" )
		button.callback { board.undo(&cb) }
	end
end

g = GUI.new
g.show
Fltk::run
