Skip to content

Instantly share code, notes, and snippets.

@kaplan
Last active December 20, 2015 19:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kaplan/6180526 to your computer and use it in GitHub Desktop.
Save kaplan/6180526 to your computer and use it in GitHub Desktop.
Scary Craps
class Die
def roll_die
rand(1..6)
end
end
class CrapsGame
attr_accessor :point, :dice_roll
def pass
(@dice_roll == 7 || @dice_roll == 11)
end
def no_pass
@dice_roll == 2 || @dice_roll == 3 || @dice_roll == 12
end
def craps
@dice_roll == 7
end
def win
@dice_roll == @point
end
def roll (die1, die2, first_roll)
self.dice_roll = die1.roll_die + die2.roll_die
if first_roll
puts "your first roll was a #{@dice_roll}"
if pass
puts dice_roll
puts "'natural' roll, you WIN!"
elsif no_pass
puts dice_roll
puts "'craps!' you LOSE!"
else
self.point = dice_roll
puts "set point is #{@point}"
roll(die1, die2, false)
end
else
puts "rolling again and you rolled a #{@dice_roll}"
if craps
puts "you crapped out with a #{@dice_roll}"
elsif win
puts "you win with #{@point}"
else
roll(die1, die2, false)
end
end
end
end
CrapsGame.new.roll(Die.new, Die.new, true)
@kaplan
Copy link
Author

kaplan commented Aug 11, 2013

I was looking at the @dice_roll and the @point v. using self.dice_roll and self.point. I thought maybe using self. for setting seemed ok and @ for retrieving, but I'm not sure about that and if there is a big difference other than style??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment