Go Fish/Ruby: Difference between revisions

m
Fixed syntax highlighting.
mNo edit summary
m (Fixed syntax highlighting.)
 
(2 intermediate revisions by 2 users not shown)
Line 1:
{{collection|Go Fish}}[[Category:Ruby]]
 
<langsyntaxhighlight lang="ruby">class Card
RANKS = %w(2 3 4 5 6 7 8 9 10 J Q K A)
SUITS = %w(C D H S)
Line 74:
end
end
if @hand.length == 0empty? and not @game.deck.empty?
@game.deal(self, 1)
end
Line 149:
# sort ranks by ones with most cards in my hand. better chance to make a book
def sort_cards_by_most(array_of_ranks)
array_of_ranks.sort_by {|rank| 4 - @hand[rank].length}
end
end
Line 174:
if not Card::RANKS.include?(wanted)
puts "not a valid rank: #{wanted} -- try again."
elsif not @hand.keys.includehas_key?(wanted)
puts "you don't have a #{wanted} -- try again"
else
Line 214:
 
def deal(player, n=1)
if n >= [n, @deck.cards_remaining].min
n = @deck.cards_remaining
end
puts "Dealer: #{n} card(s) to #{player.name}"
player.take_cards(@deck.deal(n))
Line 226 ⟶ 224:
 
srand
GoFishGame.new.start</langsyntaxhighlight>
9,476

edits