Permalink
Browse files

ruby19 compatibility & Shoes 2 compatibility

  • Loading branch information...
1 parent 87187dd commit c166f7435425c16d8da8bd89e4da91f9344a4e6a @eregon eregon committed Feb 23, 2010
Showing with 59 additions and 47 deletions.
  1. +4 −4 bin/broadsides
  2. +1 −1 bin/log2html
  3. +1 −1 lib/broadsides/player.rb
  4. BIN shoes/Thumbs.db
  5. +10 −8 shoes/broadsides_battle_viewer.rb
  6. +43 −33 shoes/mod.rb
View
@@ -26,8 +26,8 @@ begin
game.run
winner = game.finish
puts "#{winner} wins."
-rescue Exception => error
- puts "USAGE: [--log NAME] #{$PROGRAM_NAME} PATH_TO_PLAYER_1 PATH_TO_PLAYER_2"
- puts
- puts "Error: #{error.message}"
+#rescue Exception => error
+# puts "USAGE: [--log NAME] #{$PROGRAM_NAME} PATH_TO_PLAYER_1 PATH_TO_PLAYER_2"
+# puts
+# puts "Error: #{error.message}"
end
View
@@ -7,7 +7,7 @@ end
require "erb"
def move(from, plus, horizontal)
- x = from[/[A-J]/][0]
+ x = from[/[A-J]/].unpack('c')[0]
y = from[/10|[1-9]/].to_i
horizontal ? "#{(x + plus).chr}#{y}" : "#{x.chr}#{y + plus}"
end
View
@@ -72,7 +72,7 @@ def shell_escape(string)
end
def move(where, plus, horizontal)
- x = where[/[A-J]/][0]
+ x = where[/[A-J]/].unpack('c')[0] # Made 1.8-9 compatible
y = where[/10|[1-9]/].to_i
to = horizontal ? "#{(x + plus).chr}#{y}" : "#{x.chr}#{y + plus}"
fail "Out of bounds" unless to =~ /\A[A-J](?:10|[1-9])\z/
View
Binary file not shown.
@@ -1,15 +1,17 @@
# broadsides_battle_viewer.rb
-require 'mod'
-Shoes.app title: 'Battle Viewer r0.1 for JEG2 broadsides', width: 700, height: 400 do
+require File.dirname(__FILE__) + '/mod'
+
+Shoes.app :title => 'Battle Viewer r0.1 for JEG2 broadsides', :width => 700, :height => 400 do
extend Mod
@bgs = []
- POS.each do |x|
- @bgs << rect(x, 50, 300, 300, stroke: blue, fill: white, )
- 9.times{|i| line x, 80+30*i, x+300, 80+30*i, stroke: blue}
- 9.times{|i| line x+30*(i+1), 50, x+30*(i+1), 350, stroke: blue}
+
+ Mod::POS.each do |x|
+ @bgs << rect(x, 50, 300, 300, :stroke => blue, :fill => white)
+ 9.times { |i| line x, 80+30*i, x+300, 80+30*i, :stroke => blue }
+ 9.times { |i| line x+30*(i+1), 50, x+30*(i+1), 350, :stroke => blue }
end
- para link('read log'){read_game_log; @sb.show}, left: 40, top: 360
- @sb = para(link('start battle'){start_battle}, left: 150, top: 360).hide
+ para link('read log') { read_game_log; @sb.show }, :left => 40, :top => 360
+ @sb = para( link('start battle') { start_battle } , :left => 150, :top => 360).hide
end
View
@@ -1,86 +1,96 @@
# mod.rb
module Mod
- POS = [40, 360]; RPOS = POS.reverse
-
+ POS = [40, 360]
+ RPOS = POS.reverse
+
def read_game_log
file = ask_open_file
file ||= '../log/last_game.log'
IO.readlines(file).each do |line|
key, *log = line.split
case key
- when /SETUP/
- @players = log.first.split(':').last.split(',')
- when /SHIPS/
- @ships ||= []; log.shift; @ships << log
- when /SHOTS/
- @shots ||= []; log.shift; @shots << log
- when /WINNER/
- @winner = log.first
- else
- error 'invarid game log...'
+ when /SETUP/
+ @players = log.first.split(':').last.split(',')
+ when /SHIPS/
+ @ships ||= []; log.shift; @ships << log
+ when /SHOTS/
+ @shots ||= []; log.shift; @shots << log
+ when /WINNER/
+ @winner = log.first
+ else
+ error 'invarid game log...'
end
end
end
-
+
def start_battle
- POS.each.with_index{|x, i| caption @players[i], left: x, top: 10, stroke: forestgreen, weight: 'bold' }
- show_ships; make_bombs; show_battle
+ POS.each_with_index do |x, i|
+ caption @players[i], :left => x, :top => 10, :stroke => forestgreen, :weight => 'bold'
+ end
+ show_ships
+ make_bombs
+ show_battle
end
-
+
def show_ships
- @ships.each.with_index do |ships, i|
+ @ships.each_with_index do |ships, i|
ships.each do |ship|
len, pos, hv = ship.split ':'
hv == 'H' ? (x, y = len.to_i, 1) : (x, y = 1, len.to_i)
l, t = convert pos
- image 'ship.gif', width: 30*x, height: 30*y, left: POS[i]+30*l, top: 50+30*t
+ image 'ship.gif', :width => 30*x, :height => 30*y, :left => POS[i]+30*l, :top => 50+30*t
end
end
- @bgs[1].style fill: rand_color
+ @bgs[1].style :fill => rand_color
end
-
+
def make_bombs
@bombs = []
- @shots.each.with_index do |shots, i|
+ @shots.each_with_index do |shots, i|
shots.each do |shot|
pos, hm = shot.split ':'
l, t = convert pos
img = hm == 'hit' ? 'fire.gif' : 'bomb.gif'
- @bombs << image(img, width: 30, height: 30, left: RPOS[i%2]+30*l, top: 50+30*t).hide
+ @bombs << image(img, :width => 30, :height => 30, :left => RPOS[i%2]+30*l, :top => 50+30*t).hide
end
@bombs << 2
end
@times = @bombs.length - 1
end
-
+
def show_battle
e = every do |i|
@bombs[i] == 2 ? change_focus : @bombs[i].show
- (e.stop; show_winner) if i == @times
+ if i == @times
+ e.stop
+ show_winner
+ end
end
end
-
+
def show_winner
@players.each do |player|
- stack width: 500, height: 340, left: 100, top: 30 do
- background rgb(240, 230, 140, 0.7), curve: 30
- subtitle "\n WINNER:", stroke: green
+ stack :width => 500, :height => 340, :left => 100, :top => 30 do
+ background rgb(240, 230, 140, 0.7), :curve => 30
+ subtitle "\n WINNER:", :stroke => green
para
- title @winner, align: 'center', stroke: deeppink, weight: 'bold'
+ title @winner, :align => 'center', :stroke => deeppink, :weight => 'bold'
end
end
end
-
+
def change_focus
- @bgs.each{|bg| bg.style[:fill] == white ? (bg.style fill: rand_color) : (bg.style fill: white)}
+ @bgs.each { |bg|
+ bg.style[:fill] == white ? (bg.style :fill => rand_color) : (bg.style :fill => white)
+ }
sleep 2
end
-
+
def convert pos
l, t = pos[0, 1], pos[1..-1]
[('A'..'J').to_a.index(l), t.to_i - 1]
end
-
+
def rand_color
rgb(rand(255), rand(255), rand(255), 0.5)..rgb(rand(255), rand(255), rand(255), 0.5)
end

0 comments on commit c166f74

Please sign in to comment.