Go Fish/Ruby: Difference between revisions
m
Fixed syntax highlighting.
(Created page with '{{collection|Go Fish}}Category:Ruby <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) def initialize(rank, suit) @rank = rank @…') |
m (Fixed syntax highlighting.) |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 1:
{{collection|Go Fish}}
<
RANKS = %w(2 3 4 5 6 7 8 9 10 J Q K A)
SUITS = %w(C D H S)
Line 9:
@suit = suit
end
def <=>(other)
Line 74:
end
end
if @hand.
@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|
end
end
Line 174:
if not Card::RANKS.include?(wanted)
puts "not a valid rank: #{wanted} -- try again."
elsif not @hand.
puts "you don't have a #{wanted} -- try again"
else
Line 214:
def deal(player, n=1)
puts "Dealer: #{n} card(s) to #{player.name}"
player.take_cards(@deck.deal(n))
Line 226 ⟶ 224:
srand
GoFishGame.new.start</
|