Posted: Sun Apr 06, 2008 9:49 pm Post subject: A very crude Blackjack.
Here is a very crude blackjack, I'm just trying to learn ruby, so I thought it would be a fun project to try out. It's pretty crude, I'm actually making a really cool deck class for super-accurate shuffling, and probability.
I'd love feed back/things I did wrong. Trying to get out of the Turing mindset proves difficult.
if turnChoice.include?("1") :
playerCards += [rand(10)] if total(playerCards) > 21 :
playAgain = "2" end elsif turnChoice.include?("2") :
playAgain = "2" end end
cls
end_of_round(playerCards, dealerCards)
puts"\n1: Play Again" puts"2: Exit"
playAgain = gets if playAgain == "2\n" :
menuChoice = "2"
playAgain = "2" else
dealerCards = [rand(10),rand(10)]
playerCards = [rand(10),rand(10)]
playAgain = "1" end
end
Sponsor Sponsor
wtd
Posted: Mon Apr 07, 2008 12:42 am Post subject: RE:A very crude Blackjack.
code:
def cls
puts "\n" * 22
end
code:
def clear_screen
22.times { puts }
end
wtd
Posted: Mon Apr 07, 2008 11:03 am Post subject: RE:A very crude Blackjack.
code:
if turnChoice.include?("1") :
playerCards += [rand(10)]
if total(playerCards) > 21 :
playAgain = "2"
end
elsif turnChoice.include?("2") :
playAgain = "2"
end
Try making use of regular expressions instead of include?
Mackie
Posted: Mon Apr 07, 2008 1:16 pm Post subject: Re: RE:A very crude Blackjack.
wtd @ Mon Apr 07, 2008 12:42 am wrote:
code:
def cls
puts "\n" * 22
end
code:
def clear_screen
22.times { puts }
end
Thanks wtd, I changed it, I just don't know if there is any advantage to the change. Is it just common practice to do it your way?
wtd @ Mon Apr 07, 2008 11:03 am wrote:
code:
if turnChoice.include?("1") :
playerCards += [rand(10)]
if total(playerCards) > 21 :
playAgain = "2"
end
elsif turnChoice.include?("2") :
playAgain = "2"
end
Try making use of regular expressions instead of include?
I had a feeling someone was going to mention that.
I wasn't sure why regular expressions weren't working until later on, when i realized it added the eol character.
wtd
Posted: Mon Apr 07, 2008 2:09 pm Post subject: Re: RE:A very crude Blackjack.
Mackie @ Tue Apr 08, 2008 2:16 am wrote:
wtd @ Mon Apr 07, 2008 12:42 am wrote:
code:
def cls
puts "\n" * 22
end
code:
def clear_screen
22.times { puts }
end
Thanks wtd, I changed it, I just don't know if there is any advantage to the change. Is it just common practice to do it your way?
Which is more self-documenting?
ambok
Posted: Tue Nov 16, 2010 7:48 am Post subject: Re: A very crude Blackjack.
if turnChoice.include?("1") :
playerCards += [rand(10)]
if total(playerCards) > 21 :
playAgain = "2"
end
elsif turnChoice.include?("2") :
playAgain = "2"
end
Insectoid
Posted: Tue Nov 16, 2010 10:31 am Post subject: RE:A very crude Blackjack.