Skip to content

Instantly share code, notes, and snippets.

@miles
Created July 21, 2011 03:22
Show Gist options
  • Save miles/1096428 to your computer and use it in GitHub Desktop.
Save miles/1096428 to your computer and use it in GitHub Desktop.
Acey Ducey Game
#!/usr/bin/env ruby -wKU
class MyCard
attr_reader :value, :facevalue
def initialize
@value = rand(13)+2
case
when @value == 11
@facevalue = "Jack"
when @value == 12
@facevalue = "Queen"
when @value == 13
@facevalue = "King"
when @value == 14
@facevalue = "Ace"
else
@facevalue = @value
end
end
end
puts <<-MESSAGE
Acey-Ducey is played in the following manner.
The dealer (computer) deals two cars face up.
You have an option to bet or not bet depending
on whether or not you feel the card will have
a value between the first two.
If you do not want to bet, input a 0.
MESSAGE
money = 100
while money > 0 do
puts "\nYou have #{money} dollars.\n"
puts "Here are your two cards:"
cards = [MyCard.new,MyCard.new]
cards = cards.reverse if cards[0].value > cards[1].value
puts "#{cards[0].facevalue} and #{cards[1].facevalue}"
value = 0
while value == 0
print "Bet? "
bet = gets.to_i
if bet == 0
puts "Chicken!"
value = 2
next
end
if bet > money
puts "You don't have enough cash"
next
end
value = 1
end
next if value == 2
card3 = MyCard.new
puts "Card is: #{card3.facevalue}"
if (card3.value > cards[0].value) and (card3.value < cards[1].value)
puts "You won!"
money = money + bet
else
puts "You lost :("
money = money - bet
end
end
puts "You've run out of cash"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment