Created
April 12, 2012 18:11
-
-
Save vanpelt/2369749 to your computer and use it in GitHub Desktop.
Virtual Hat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'pp' | |
| @candidates = { | |
| "Joseph Childress" => 7, | |
| "Brian Reavey" => 6, | |
| "Vaughn Hester" => 10, | |
| "Lukas Biewald" => 1 | |
| } | |
| def pick_winner | |
| pool = @candidates.map do |name, quarters| | |
| [name] * quarters | |
| end.flatten.shuffle | |
| winner = pool[rand(pool.length)] | |
| @candidates.delete(winner) | |
| winner | |
| end | |
| @script = { | |
| :welcome => "Welcome to CVP's amazing virtual hat!", | |
| :current_candidates => "Our current candidates are", | |
| :lucky_winner => "And our lucky winner is..." | |
| } | |
| @exclamations = ["fuck", "shit", "bloody hell", "yowza"] | |
| puts "#{@script[:welcome]}\n\n\n\n" | |
| `say "#{@script[:welcome]}"` | |
| funny = 0 | |
| while(@candidates.length > 0) do | |
| funny += 1 | |
| puts "#{@script[:current_candidates]}" | |
| `say "#{@script[:current_candidates]}"` | |
| pp @candidates | |
| i = @candidates.length | |
| @candidates.map do |name,likelihood| | |
| `say "#{name}"` | |
| i -= 1 | |
| `say "and"` unless i == 0 | |
| end | |
| puts "\nPress Enter to draw a name!" | |
| `say "Let's.... do.... this!....'"` | |
| foo = gets | |
| puts "#{@script[:lucky_winner]}" | |
| Thread.new do | |
| `say "#{@script[:lucky_winner]}"` | |
| end | |
| whirly = ["|", "/", "-", "\\",] | |
| 80.times do |i| | |
| i += 1 | |
| $stdout.print whirly[i % 4] | |
| $stdout.flush | |
| $stdout.print "\r\r" | |
| sleep(0.04) | |
| end | |
| winner = pick_winner | |
| Thread.new do | |
| 5.times do | |
| `say "#{winner}"` | |
| end | |
| end | |
| 5.times do |i| | |
| $stdout.print "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r" | |
| $stdout.print winner+"!!!!!" | |
| $stdout.flush | |
| sleep(0.8) | |
| $stdout.print "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r" | |
| $stdout.print " " | |
| $stdout.flush | |
| sleep(0.8) | |
| end | |
| puts "\n\n" | |
| `say "Well #{@exclamations[rand(@exclamations.length)]}, that was fun!"` | |
| `say "Let's do it again"` | |
| if funny == 1 | |
| `say "Wait, hold up... This just in... I've detected a DIY user has just spent 5 million dollars and only given us 5... Oh well."` | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment