Skip to content

Instantly share code, notes, and snippets.

@evanfarrar
Created October 16, 2008 16:41
Show Gist options
  • Save evanfarrar/17191 to your computer and use it in GitHub Desktop.
Save evanfarrar/17191 to your computer and use it in GitHub Desktop.
diff --git a/lib/race_presenter.rb b/lib/race_presenter.rb
index b08d602..eec6be8 100644
--- a/lib/race_presenter.rb
+++ b/lib/race_presenter.rb
@@ -1,7 +1,7 @@
module RacePresenterMod
def race_window(match, race_distance, sensor, title)
- window :title => title, :width => 800, :height => 600 do
- background "media/trappedsprints-800.jpg"
+ background black
+# background 'media/background.jpg' if File.readable?("media/background.jp
stack do
subtitle title, :top => 150, :align => "center", :background => magenta
@@ -41,7 +41,6 @@ module RacePresenterMod
close
end
end
- end
end
end
@@ -98,15 +97,12 @@ class RacePresenter
@blue.finish_time = @sensor.values[:blue_finish]
if @race.complete?
- @shoes_instance.title "#{@race.winner.name.upcase} WINS!!!\n", :align =
- :top => 380, :width => 800, :stroke => @shoes_instance.ivory
- @shoes_instance.title "#{@red.name}: #{@sensor.values[:red_finish]/1000
- :align => 'center', :top => 450, :width => 800
-
+ #@shoes_instance.title "#{@race.winner.name.upcase} WINS!!!\n", :align
+ #:top => 380, :width => 800, :stroke => @shoes_instance.ivory
+ @shoes_instance.alert "#{@red.name}: #{@red.finish_time/1000.0}s, #{@bl
+ quit
@sensor.stop
@continue = false
- @shoes_instance.owner.tournament_record(@race)
- @shoes_instance.owner.post_race
end
end
end
diff --git a/main.rb b/main.rb
index c750ddb..f55c5d5 100755
--- a/main.rb
+++ b/main.rb
@@ -6,13 +6,12 @@ begin
rescue
alert "You must write a conf.yml. See sample in conf-sample.yml"
end
-Infinity = 1/0.0
-require 'lib/units/base'
-require 'lib/units/standard'
-
+#Infinity = 1/0.0
+#require 'lib/units/base'
+#require 'lib/units/standard'
RACE_DISTANCE = options['race_distance']
-$ROLLER_CIRCUMFERENCE = options['roller_circumference'].mm.to_km
+$ROLLER_CIRCUMFERENCE = options['roller_circumference']
TITLE = options['title']
require 'lib/racer'
require 'lib/race'
@@ -26,103 +25,11 @@ SENSOR = Sensor.new(queue, options['sensor']['device'])
UNIT_SYSTEM = (options['units'] == 'standard') ? :mph : :kmph
-Shoes.app :title => TITLE, :width => 800, :height => 600 do
- background white
- extend InterfaceWidgets
+Shoes.app :title => "foo", :width => 800, :height => 600 do
extend RacePresenterMod
@tournament = Tournament.new(RACE_DISTANCE)
- def list_racers
- flow do
- flow(:width => 115) { para 'Name' }
- flow(:width => 50) { para 'Wins' }
- flow(:width => 25) { para 'Best' }
- end
- @tournament.racers.each do |racer|
- flow do
- border black
- flow(:width => 115) { para racer.name }
- flow(:width => 50) { para racer.wins, " / ", racer.races }
- flow(:width => 25) { para racer.best_time, "s" unless racer.best_time
- add_to_race racer
- delete_racer racer
- end
- end
- end
-
- def post_race
- relist_tournament
- end
-
- def tournament_record(race)
- @tournament.record(race)
- end
-
- def list_matches
- border black
- title "Matches"
- @tournament.matches.each do |match|
- flow(:margin => 5) do
- background lightgrey
- border black
- flow(:width => 180) do
- if match.racers.length == 1
- para match.racers.first.name
- else
- para span(match.blue_racer.name, :stroke => blue),
- " vs ",
- span(match.red_racer.name, :stroke => red)
- end
- end
- button("race")do
- race_window(match, RACE_DISTANCE, SENSOR, TITLE)
- end
- redblue(match)
- delete_race(match)
- end
- end
- end
-
- def add_racer(name)
- duped = @tournament.racers.any? do |racer|
- racer.name == name
- end
- if !duped && name!='enter name'
- @tournament.racers << Racer.new(:name => name, :units => UNIT_SYSTEM)
- relist_tournament
- end
- end
-
- def relist_tournament
- @matches.clear {list_matches}
- @racer_list.clear {list_racers}
- end
-
- stack(:width => 380, :margin => 5) do
- border black
- title "Racers"
- @racer_list = stack { list_racers }
- flow do
- @racer_name = edit_line "enter name", :width => 110
- create_racer
- end
- end
-
- @matches = stack(:width => 290, :margin => 5) do
- list_matches
- end
-
- button "autofill matches" do
- @tournament.autofill_matches
- relist_tournament
- end
-
- button "save" do
- File.open(ask_save_file, 'w+') { |f| f << @tournament.to_yaml }
- end
-
- button "open" do
- @tournament = YAML::load(File.open(ask_open_file))
- relist_tournament
- end
+ match = Race.new(Racer.new(:name => ask("red?"), :units => UNIT_SYSTEM),
+ Racer.new(:name => ask("blue?"), :units => UNIT_SYSTEM), RACE_DISTANC
+ race_window(match, RACE_DISTANCE, SENSOR, TITLE)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment