Created
February 13, 2014 20:48
-
-
Save apgordon/8983518 to your computer and use it in GitHub Desktop.
Initial testing of Classes in Ruby
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
| class Player | |
| def initialize(name, poss, shoot_pct, pass_pct) | |
| @name = name | |
| @@poss = poss | |
| @shoot_pct = shoot_pct | |
| @pass_pct = pass_pct | |
| end | |
| def shoot | |
| rand = rand(0) | |
| if rand > 0.5 | |
| puts "#{@name} shoots... and scores!" | |
| else | |
| puts "Better luck next time, #{@name}." | |
| end | |
| end | |
| def pass | |
| puts "#{@name} attempts a pass." | |
| rand = rand(0) | |
| if rand > 0.5 | |
| puts "Pass complete!" | |
| else | |
| puts "Incomplete pass." | |
| end | |
| end | |
| def announce_name | |
| puts "Hi, I'm #{@name}. My shooting % is #{100*@shoot_pct}, and my passing % is #{100*@pass_pct}." | |
| end | |
| end | |
| print "Goalie's name? " | |
| p1name = gets.chomp | |
| print "Skater 1's name? " | |
| p2name = gets.chomp | |
| print "Skater 2's name? " | |
| p3name = gets.chomp | |
| p1 = Player.new(p1name, 0, 0.001, 0.95) | |
| p2 = Player.new(p2name, 0, 0.5, 0.60) | |
| p3 = Player.new(p3name, 0, 0.65, 0.40) | |
| p1.announce_name | |
| p2.announce_name | |
| p3.announce_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment