RubyoffRails/Episode2 — pull request #4 by telemachus (2012-05-03 13:00:01+00:00)
Title: Hw ep2 extracredit

Ok. This is the extra-credit version.

For this, I rearranged a lot, and I didn't do it exactly as you asked. But once I got going with the game, it took on a life of its own. So:

+ Each fighter gets a name.
+ The driver file (`superfighter.rb`) creates a `Match` and that class has a method to deal with a "round". One round is each player striking or blocking.
+ Each round has a winner. Moves are directly comparable by `include`-ing `Comparable` and defining `<=>`.
+ If both moves are blocks, nobody wins. Otherwise, the rank of each move is compared directly. The game is weighted in favor of strikes because a strike is a random number 1-100, but blocks are only 1-75.
+ Fighters now have a read/write property for their points. Each round they win, they get a point.
+ At the end of twelve rounds, whichever fighter has more points wins. Fighters are also comparable, by their number of points.

It's a little tedious, but if you run `ruby superfighter.rb`, you can play a game. In the process, I removed the `Turn` class and its specs (I moved things around - turns became rounds in the match.) If I had more time, I might redistribute more between `Fighter` and `Match` classes.

My remaining annoyance: almost all of the round-by-round and winning logic is in the driver file, not a class. I did this because I'm always reluctant to put too much io into classes. But maybe that's wrong? Also the driver file itself isn't tested at all. I never know how to best test heavy-io stuff.