Permalink
Browse files

Uploaded the revised codes for Red Shoes and Purple Shoes.

  • Loading branch information...
1 parent 57bbcbe commit d5cd69f70dc77cf2ccf18023bb982a9456f7eed2 @ashbb committed Apr 6, 2012
View
@@ -1,4 +1,4 @@
-Unblock Me on Green Shoes
+Unblock Me on Colorful Shoes
=====================
**Unblock Me** is a very famous puzzle game. It's simple and addictive.
@@ -7,7 +7,7 @@ The goal is to get the red block out of the board by sliding the other blocks ou
Snapshots
----------
-Do `ruby unblockme.rb`. You can play Unblock Me on Green Shoes.
+Do `ruby unblockme.rb`. You can play Unblock Me on Colorful Shoes, Red, Green and Purple.
![unblockme](https://github.com/ashbb/unblockme/raw/master/unblockme.png)
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,97 @@
+require 'purple_shoes'
+
+module Unblock
+ def show_hide j, i
+ n, m = j*6+i, COLORS.index(@color)
+ @colors[n].each &:hide
+ @colors[n][m].show
+ @game[j][i] = m.to_s
+ end
+
+ def cell_clear j, i
+ @colors[j*6+i].each &:hide
+ @game[j][i] = '*'
+ end
+
+ def output
+ out = '['
+ @game.each_with_index do |line, j|
+ line = line.join
+ i = line.index '0'
+ if i
+ out << format(j, i, 2, :pink, :true)
+ if line[i+2] == '0'
+ out << format(j, i+2, 2, :pink, :true)
+ elsif i < 3
+ ii = line[i+3..-1].index '0'
+ (out << format(j, i+3+ii, 2, :pink, :true)) if ii
+ end
+ end
+ i = line.index '1'
+ (out << format(j, i, 3, :lightgreen, :true)) if i
+ i = line.index '4'
+ (out << format(j, i, 2, :red, :true)) if i
+ end
+
+ 6.times do |i|
+ line = (0..5).to_a.map{|j| @game[j][i]}.join
+ j = line.index '2'
+ if j
+ out << format(j, i, 2, :lightblue, :false)
+ if line[j+2] == '2'
+ out << format(j+2, i, 2, :lightblue, :false)
+ elsif j < 3
+ jj = line[j+3..-1].index '2'
+ (out << format(j+3+jj, i, 2, :lightblue, :false)) if jj
+ end
+ end
+ j = line.index '3'
+ (out << format(j, i, 3, :gold, :false)) if j
+ end
+ file = ask_save_file
+ open file, 'w' do |f|
+ f.puts (out[0...-2] << ']')
+ end if file
+ end
+
+ def format j, i, l, color, vh
+ "[%s, %s, %s, %s, %s], " % [j, i, l, color, vh]
+ end
+end
+
+Shoes.app title: 'Unblock Me! - Make Game', width: 340, height: 370 do
+ X, Y, W = 20, 50, 50
+ COLORS = [pink, lightgreen, lightblue, gold, red]
+ ATTR = [:h2, :h3, :v2, :v3, :h2]
+ @colors, @game = [], Array.new(6){Array.new(6){'*'}}
+ @color = COLORS.first
+ extend Unblock
+ background dimgray
+ strokewidth 0
+ rect X-10, Y-10, W*6+20, W*6+20, fill: silver, curve: 10
+ rect X+10+W*6, Y+W/2*3, X, W*2, fill: silver
+ rect X+10+W*6, Y+W, X*2, W, fill: dimgray, curve: 5
+ rect X+10+W*6, Y+W*3, X*2, W, fill: dimgray, curve: 5
+
+ stroke white
+ strokewidth 1
+ nofill
+ 6.times do |j|
+ 6.times do |i|
+ rect(X+W*i, Y+W*j, W+1, W+1).
+ click{|b| b == 1 ? show_hide(j, i): cell_clear(j, i)}
+ color = []
+ COLORS.each{|c| color << rect(X+W*i+1, Y+W*j+1, W-1, W-1, strokewidth: 0, fill: c).hide}
+ @colors << color
+ end
+ end
+
+ nostroke
+ COLORS.each_with_index do |c, i|
+ rect(20+45*i, 5, 40, 30, fill: c).
+ click{@color = c}
+ para strong(ATTR[i]), left: 30+45*i, top: 10, stroke: white
+ end
+
+ button('save'){output}.move 280, 10
+end
View
@@ -0,0 +1,127 @@
+require 'purple_shoes'
+
+class Array
+ alias :_clear :clear
+ def clear
+ self.each{|e| e.clear if e.class.method_defined? :clear}
+ _clear
+ end
+end
+
+module Unblock
+ def range
+ min, max = 0, 6 - @car.len
+ @car.vertical ? (n, m = @car.x, @car.y) : (n, m = @car.y, @car.x)
+ case n
+ when min
+ max = cal_max n, m, max
+ when max
+ min = cal_min n, m, min
+ else
+ min, max = cal_min(n, m, min), cal_max(n, m, max)
+ end
+ d = @car.vertical ? X : Y
+ min, max = min*W+d, max*W+d
+ (min..max)
+ end
+
+ def cal_max n, m, max
+ ((n+1)..max).each do |x|
+ (max = x - 1; break) if(@car.vertical ? @board[m][x+@car.len-1] : @board[x+@car.len-1][m])
+ end
+ max
+ end
+
+ def cal_min n, m, min
+ (min..(n-1)).to_a.reverse.each do |x|
+ (min = x + 1; break) if(@car.vertical ? @board[m][x] : @board[x][m])
+ end
+ min
+ end
+end
+
+Shoes.app title: 'Unblock Me!', width: 340, height: 370 do
+ X, Y, W = 20, 50, 50
+ extend Unblock
+ background dimgray
+ strokewidth 0
+
+ rect X-10, Y-10, W*6+20, W*6+20, fill: silver, curve: 10
+ rect X+10+W*6, Y+W/2*3, X, W*2, fill: silver
+ rect X+10+W*6, Y+W, X*2, W, fill: dimgray, curve: 5
+ rect X+10+W*6, Y+W*3, X*2, W, fill: dimgray, curve: 5
+
+ stroke white
+ strokewidth 5
+
+ data, cars = [], []
+ games = Dir['./game/*']
+ number = games.map{|file| File.basename file}
+ len = number.length
+ games.each{|g| data << eval(IO.read g)}
+ run = proc do |num|
+ @flag = false
+ @board = Array.new(6){Array.new 6}
+ data[num].each do |y, x, len, color, vh|
+ if vh
+ len.times{|i| @board[y][x+i] = :exist}
+ w, h = W*len-4, W-4
+ else
+ len.times{|j| @board[y+j][x] = :exist}
+ w, h = W-4, W*len-4
+ end
+
+ car = rect(x*W+X, y*W+Y, w, h, curve: 10, fill: color, vertical: vh, x: x, y: y, len: len)
+ cars << car
+
+ car.click do
+ @flag, @car = true, car
+ b, l, t = mouse
+ @dl, @dt = car.left - l, car.top - t
+ end
+
+ car.release do
+ @flag = false
+ if @car.vertical
+ @car.len.times{|n| @board[@car.y][@car.x+n] = nil}
+ @car.move (@car.left.to_i - X + W/2) / W * W + X, @car.top
+ @car.x = (@car.left.to_i - X) / W
+ @car.len.times{|n| @board[@car.y][@car.x+n] = :exist}
+ else
+ @car.len.times{|n| @board[@car.y+n][@car.x] = nil}
+ @car.move @car.left, (@car.top.to_i - Y + W/2) / W * W + Y
+ @car.y = (@car.top.to_i - Y) / W
+ @car.len.times{|n| @board[@car.y+n][@car.x] = :exist}
+ end
+ if @car.fill == red and @car.x == 4
+ l, t = @car.left, @car.top
+ a = animate do |i|
+ i *= 10
+ @car.move l + i, t
+ a.stop if i > W * 2
+ end
+ end
+ end
+ end
+ end
+
+ run[n=0]
+
+ style Shoes::Link, underline: false
+ #style Shoes::LinkHover, underline: false, weight: 'bold', stroke: '#B82'
+ b = rect 150, 5, 60, 30, fill: dimgray, curve: 5, strokewidth: 0
+ bt = tagline number[n], left: 150, top: 5, stroke: white, weight: 'bold'
+ b.click{cars.clear; bt.text = number[n]; aflush; run[n]}
+ para link(strong(fg('<<', white))){cars.clear; bt.text = number[n=(n-1)%len]; aflush; run[n]}, left: 90, top: 10
+ para link(strong(fg('>>', white))){cars.clear; bt.text = number[n=(n+1)%len]; aflush; run[n]}, left: 240, top: 10
+
+ motion do |left, top|
+ if @flag
+ if @car.vertical
+ @car.move(left + @dl, @car.top) if range.include?(left + @dl)
+ else
+ @car.move(@car.left, top + @dt) if range.include?(top + @dt)
+ end
+ end
+ end
+end
View
@@ -0,0 +1,97 @@
+
+module Unblock
+ def show_hide j, i
+ n, m = j*6+i, $COLORS.index(@color)
+ @colors[n].each &:hide
+ @colors[n][m].show
+ @game[j][i] = m.to_s
+ end
+
+ def cell_clear j, i
+ @colors[j*6+i].each &:hide
+ @game[j][i] = '*'
+ end
+
+ def output
+ out = '['
+ @game.each_with_index do |line, j|
+ line = line.join
+ i = line.index '0'
+ if i
+ out << format(j, i, 2, :pink, :true)
+ if line[i+2] == '0'
+ out << format(j, i+2, 2, :pink, :true)
+ elsif i < 3
+ ii = line[i+3..-1].index '0'
+ (out << format(j, i+3+ii, 2, :pink, :true)) if ii
+ end
+ end
+ i = line.index '1'
+ (out << format(j, i, 3, :lightgreen, :true)) if i
+ i = line.index '4'
+ (out << format(j, i, 2, :red, :true)) if i
+ end
+
+ 6.times do |i|
+ line = (0..5).to_a.map{|j| @game[j][i]}.join
+ j = line.index '2'
+ if j
+ out << format(j, i, 2, :lightblue, :false)
+ if line[j+2] == '2'
+ out << format(j+2, i, 2, :lightblue, :false)
+ elsif j < 3
+ jj = line[j+3..-1].index '2'
+ (out << format(j+3+jj, i, 2, :lightblue, :false)) if jj
+ end
+ end
+ j = line.index '3'
+ (out << format(j, i, 3, :gold, :false)) if j
+ end
+ file = ask_save_file
+ open file, 'w' do |f|
+ f.puts (out[0...-2] << ']')
+ end if file
+ end
+
+ def format j, i, l, color, vh
+ "[%s, %s, %s, %s, %s], " % [j, i, l, color, vh]
+ end
+end
+
+Shoes.app title: 'Unblock Me! - Make Game', width: 350, height: 380 do
+ X, Y, W = 20, 50, 50
+ $COLORS = [pink, lightgreen, lightblue, gold, red]
+ ATTR = [:h2, :h3, :v2, :v3, :h2]
+ @colors, @game = [], Array.new(6){Array.new(6){'*'}}
+ @color = $COLORS.first
+ extend Unblock
+ background dimgray
+ strokewidth 0
+ rect X-10, Y-10, W*6+20, W*6+20, fill: silver, curve: 10
+ rect X+10+W*6, Y+W/2*3, X, W*2, fill: silver
+ rect X+10+W*6, Y+W, X*2, W, fill: dimgray, curve: 5
+ rect X+10+W*6, Y+W*3, X*2, W, fill: dimgray, curve: 5
+
+ stroke white
+ strokewidth 1
+ nofill
+ 6.times do |j|
+ 6.times do |i|
+ flag = false
+ rect(X+W*i, Y+W*j, W+1, W+1).
+ click{(flag = !flag) ? show_hide(j, i): cell_clear(j, i)}
+ color = []
+ $COLORS.each{|c| color << rect(X+W*i+1, Y+W*j+1, W-1, W-1, strokewidth: 0, fill: c, hidden: true)}
+ @colors << color
+ end
+ end
+
+ nostroke
+ $COLORS.each_with_index do |c, i|
+ rect(20+45*i, 5, 40, 30, fill: c).
+ click{@color = c}
+ para ATTR[i], left: 30+45*i, top: 10, stroke: white, weight: 'bold'
+ end
+
+ button('save'){output}.move 270, 10
+end
Oops, something went wrong.

0 comments on commit d5cd69f

Please sign in to comment.