RubyoffRails/Episode2 — pull request #6 by johnnygoodman (2012-05-06 05:16:15+00:00)
Title: Homework 1 and 2

I changed a lot of stuff up. The big decision was passing fighter information to the Turn class. I kept trying to work around the winning moves and winning fighters being decoupled and no matter how I did it, it wouldn't make sense. I wanted a SQL bridge table....

I also didn't like the "output the moves/score for each round and then the overall". I wanted to see which fighter won each round. I changed the winner method in the Match class to a score method, then passed back a hash instead of just an opponent back.

Here is sample script output:

Johnny-Goodmans-MacBook-Pro:Episode2 johnnygoodman$ ruby superfight.rb
What is your first fighter's name?
Ali
What is your second fighter's name?
Gee

Round 1
Winner: Gee (strike, 78)
Loser: Ali (strike, 23)

Round 2
Winner: Ali (strike, 48)
Loser: Gee (strike, 8)

Round 3
Winner: Ali (strike, 81)
Loser: Gee (strike, 41)

Round 4
Winner: Gee (strike, 20)
Loser: Ali (strike, 1)

Round 5
Winner: Gee (strike, 84)
Loser: Ali (strike, 11)

Round 6
Winner: Ali (strike, 93)
Loser: Gee (strike, 42)

Round 7
Winner: Ali (strike, 96)
Loser: Gee (strike, 25)

Round 8
Winner: Ali (strike, 69)
Loser: Gee (strike, 44)

Round 9
Winner: Ali (strike, 55)
Loser: Gee (strike, 53)

Round 10
Winner: Ali (strike, 89)
Loser: Gee (strike, 71)

Round 11
Winner: Ali (strike, 99)
Loser: Gee (strike, 47)

Round 12
Winner: Ali (strike, 94)
Loser: Gee (strike, 55)

Round 13
Winner: Ali (strike, 82)
Loser: Gee (strike, 74)

Final Match Results: Ali defeats Gee (10 to 3)

I'd love some feedback. I'm interested in both general correctness and style tips.

P.S. rand(100) returns a value from 0 to 99. rand(100) + 1 returns a value from 1 to 100. I had my rake tests randomly error out and was pretty confused for a while there.