#Code was written by Nick Zorin in 2002 #Changes by Tim Alexeevsky in 2002 require "fox" include Fox $redball= "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\ \x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\x00\x00\x00\x1f\xf3\xff\ \x61\x00\x00\x00\x06\x62\x4b\x47\x44\x00\xba\x00\x21\x00\x21\xd6\ \xd2\x97\x43\x00\x00\x00\x09\x70\x48\x59\x73\x00\x00\x0b\x12\x00\ \x00\x0b\x12\x01\xd2\xdd\x7e\xfc\x00\x00\x00\x07\x74\x49\x4d\x45\ \x07\xd2\x0b\x02\x0d\x1b\x38\xc7\x17\x0e\x49\x00\x00\x01\x71\x49\ \x44\x41\x54\x78\x9c\xdd\x92\xbb\x6a\x02\x51\x10\x86\xff\x3d\x17\ \xdc\x18\x83\x85\x20\x88\x16\x82\xad\xfd\x42\x1a\x1b\xc1\x07\x48\ \x65\x91\xda\x07\x48\x1e\x43\x0b\x4b\x41\x52\xa4\x49\x69\x1f\x48\ \x97\xc6\x3e\x55\xf0\x92\x4a\x70\xbd\xad\xa8\xeb\x71\xcf\x65\x53\ \x18\x61\xa3\x31\x7d\xf2\x77\x33\xcc\xf7\x31\x30\x03\xfc\xf9\x58\ \x3f\x35\x7b\xcd\x66\x95\x70\x5e\x33\x52\x3a\xca\xf3\xb0\x73\xdd\ \xae\x18\x8d\x5a\x4e\xa7\xf3\x74\x3c\x4b\x8f\x1b\x1f\xed\x76\xdd\ \xce\x66\x1b\xb1\x74\x3a\xcf\x12\x09\x66\x51\xca\x60\x4c\xde\x04\ \xc1\xcd\x6d\x2a\x75\xf5\x30\x18\x3c\x9f\x15\xf4\x9a\xcd\xaa\x9d\ \xcd\x36\x2e\x72\x39\xd8\x99\x0c\x48\x2c\x86\x50\x6b\x68\x21\xa0\ \x7d\x1f\x7a\xbd\xbe\xae\x72\xfe\xfe\xe8\xba\x6f\x07\x86\x44\x05\ \x84\xf3\x1a\xb5\x6d\xf0\x64\x12\x97\x85\x02\x78\x32\x09\x6a\xdb\ \x20\x9c\xc3\x62\x0c\x16\xa5\xb0\x08\xa9\x7d\x63\xa2\x85\x91\xd2\ \xd1\x42\x40\x2e\x97\xd8\xf4\xfb\x90\xcb\x25\xb4\x10\x30\x52\x22\ \x54\x0a\xa1\xd6\x08\x8d\x71\xa2\x0c\x8b\x16\xca\xf3\x10\x4c\x26\ \x00\x80\x60\x3a\x85\x16\x02\xc1\x64\x02\xe5\x79\x50\xab\x15\x94\ \xef\x43\x6f\xb7\x38\x2b\xd8\xb9\x6e\x17\x40\x49\x6d\x36\x20\x9c\ \xc3\x48\x89\xaf\x2b\x40\xce\xe7\x50\x9e\x87\xd0\x98\xee\x59\x81\ \x18\x8d\x5a\x5a\x88\x12\x5b\x2c\x60\x31\x86\x50\x29\xa8\xd5\x0a\ \x72\x3e\xc7\x6e\x3c\xc6\x6e\x36\x03\x80\x56\x94\x39\xf9\x83\xd7\ \x72\xb9\xce\xe2\xf1\x3b\x8b\x52\x84\x5a\x43\xf9\xfe\x7e\x8b\x3d\ \xdc\xa8\x0c\x87\xf7\xbf\x0a\x00\xe0\xa5\x58\xac\x5a\x84\xd4\x42\ \x63\x1c\xbd\xdd\x1e\xd6\x6e\x55\x86\xc3\x93\x47\xfa\x07\xf9\x04\ \xd5\x2b\xbc\x6c\x98\xe6\x6b\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\ \xae\x42\x60\x82" $greenball= "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\ \x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\x00\x00\x00\x1f\xf3\xff\ \x61\x00\x00\x00\x06\x62\x4b\x47\x44\x00\x35\x00\xbf\x00\x20\x65\ \xee\x15\x6c\x00\x00\x00\x09\x70\x48\x59\x73\x00\x00\x0b\x12\x00\ \x00\x0b\x12\x01\xd2\xdd\x7e\xfc\x00\x00\x00\x07\x74\x49\x4d\x45\ \x07\xd2\x0b\x02\x0d\x1b\x0e\x08\xad\x9b\xd0\x00\x00\x01\x7c\x49\ \x44\x41\x54\x78\x9c\xdd\x92\x4f\x6b\x13\x61\x10\x87\x9f\x7d\xdf\ \xdd\xec\xda\x1a\x2a\x0a\x5a\xad\x42\xc0\xa3\x47\x0f\x01\x2f\xa1\ \xf8\x11\xc4\x43\xc0\x83\xb7\x7c\x00\xfd\x18\x0d\xf4\x1a\x5a\xe8\ \x49\xbc\x7a\xf6\xe8\x2d\xf4\x2a\x1e\x04\x89\x11\x0a\xb5\x49\x24\ \xbb\x4d\xf7\xdf\x64\xde\xf5\x62\x60\x6d\x8d\x77\x9d\xdb\x0c\xf3\ \x3c\x0c\xcc\x0f\xfe\xf9\xf2\xfe\x34\x3c\x18\xed\x77\x03\xd3\xe8\ \x89\x2b\xdb\x89\xc4\x4c\xcb\xb3\xe1\x69\x71\x32\x38\x7a\xfc\xee\ \xed\xe5\x5d\x7b\x79\xf0\xe6\xdb\xe1\xde\x76\xb4\xd3\xbf\x15\xde\ \x6e\x6d\xda\xa6\x6f\x3d\xeb\xbb\xca\xb5\xca\x4a\x9e\x3d\x78\x79\ \xb3\xf9\xe9\x70\xf4\x7e\xad\xe0\x60\xb4\xdf\xdd\x8e\x76\xfa\xf7\ \xa2\xfb\xdc\x89\xee\x12\x9a\x10\xad\x94\xc2\x65\xa4\x9a\x92\xea\ \xe2\xc9\x8d\x17\xc1\xe7\xf1\xd1\xe4\xe3\x8a\x31\x75\x41\x60\x1a\ \xbd\xd0\x46\x34\x83\x2d\x5a\x1b\x0f\x69\x06\x5b\x84\x36\x22\x30\ \x0d\x7c\xe3\x63\x3d\x8b\xf1\x6c\xaf\xce\xfc\x26\x10\x57\xb6\x0b\ \xcd\x39\x97\x98\xaf\xe9\x17\xce\x25\xa6\xd0\x1c\x71\x25\x4b\xb7\ \x44\x2b\xc5\x55\xda\xae\x33\x7e\xbd\x49\x24\x66\x66\x27\x00\x84\ \x32\xa5\xd0\x9c\x59\x39\x21\x91\x98\x0b\x5d\x90\x69\x4a\xae\x19\ \x6b\x05\xd3\xf2\x6c\x08\x74\x52\x5d\x10\x98\x06\xe2\x4a\x7e\x7d\ \x81\xb9\xcc\x48\x64\x8e\x43\x87\x6b\x05\xa7\xc5\xc9\x20\x77\x79\ \x67\x53\xae\xe3\x1b\x9f\xa5\x5b\x72\xa1\x0b\xe6\x32\x63\x52\x7c\ \xe7\x87\x4c\x01\x06\x75\xe6\x4a\x0e\x9e\x0f\x9f\xee\x5d\xb3\x1b\ \xaf\xac\x67\xd1\x4a\xc9\x34\x25\x91\xf9\x0a\xee\x1f\xef\x8e\x5f\ \xff\x55\x00\xd0\xf9\xf0\xa8\x6b\x3c\xdb\x73\x95\xb6\x73\xcd\x56\ \x67\x0f\x8e\x77\xc7\x57\x82\xf4\x1f\xd4\x4f\xf9\x4e\xb8\xfa\xcb\ \x89\xbc\xa1\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82" class CoolButt < FXButton @@icons=nil def initialize(x,y) super(x,y) if @@icons.nil? @@icons=[FXPNGIcon.new(getApp, $redball), FXPNGIcon.new(getApp, $greenball)] end self.icon=@@icons[0] @state = false @neighbors = Array.new end def create super @@icons.each{|i| i.create} end def addN(n) @neighbors.push(n) unless n==nil end def toggle @neighbors.each {|n| n.switch} self.switch end def switch @state = !@state @state ? self.icon=@@icons[1] : self.icon=@@icons[0] end def state @state end end class Main < FXMainWindow def initialize(app, s) super(app, "Lock puzzle", nil, nil, DECOR_ALL, 0, 0, 400, 400) @game = FXMatrix.new(self, s, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_RIDGE|MATRIX_BY_COLUMNS) @buttons=Array.new @size = s drawGame(s) end def clearGame @buttons.each do |l| l.each { |b| b.switch } end end def drawGame(s) for x in 0..s*s-1 do b = CoolButt.new(@game, nil) if x % s == 0 then line = Array.new @buttons.push(line) end line.push(b) b.layoutHints = LAYOUT_FILL_ROW|LAYOUT_FILL_COLUMN| LAYOUT_FILL_X|LAYOUT_FILL_Y b.connect(SEL_COMMAND) do |sender, x, y| sender.toggle checkState end end @buttons.each do |line| y = @buttons.index(line) line.each do |b| x = line.index(b) b.addN(line[x-1]) unless x==0 b.addN(line[x+1]) m = @buttons[y+1] b.addN(m[x]) unless m==nil y==0 ? m=nil : m = @buttons[y-1] b.addN(m[x]) unless m==nil end end end def checkState r = true @buttons.each do |l| l.each { |b| r = r && b.state } end complete unless !r end def complete d = FXDialogBox.new(self, "Finish", DECOR_TITLE|DECOR_BORDER, 0,0,0,0,20,20,20,20) FXLabel.new(d, "Unlocked! Try Again?") m=FXMatrix.new(d, 2, MATRIX_BY_COLUMNS) FXButton.new(m, " Yes ", nil, d, FXDialogBox::ID_ACCEPT) FXButton.new(m, " No ", nil, d, FXDialogBox::ID_CANCEL) d.execute() ==1 ? clearGame : exit end def play Thread.new { for x in 1..10 do x = rand(@size) y = rand(@size) @buttons[x][y].toggle sleep 0.1 end } end def create super show(PLACEMENT_SCREEN) end end app = FXApp.new Main.new(app, 5) app.init ARGV app.create app.run