I am having a little trouble getting my code to run and have been at it for at least 4 hours...I can't seem to figure it out. BTW I am a newb at programming.
This is the UML diagram for the card/deck https://i.stack.imgur.com/CyTA5.jpg
class Card
#Cards rank from lowest to highest
VALUE = %w(2 3 4 5 6 7 8 9 10 J Q K A)
SUITS = %w(C D H S)
#(Club Diamond Heart Spade)
def initialize(the_rank, the_suit)
[@rank = the_rank]
[@suit = the_suit]
[@symbols = [nil, nil, '2', '3', '4', '5', '6', '7',
'8', '9', '10', 'J', 'Q', 'K', 'A']
end
def rank
[return @symbols[@rank]]
end
def suit
return @suit
end
def to_s
"#{rank()}#{suit()}"
end
end
#double loop for Deck#initialize
@cards = [ ]
for rank in 2..14
for suit in ['C', 'D', 'H', 'S']
# create a new card with the specified rank
# and suit and append it to the array.
end
end
suits.each do |suit|
(ranks.size).times do |i|
@cards.push(Card.new(ranks[i], suit,(i+1)))
end
end
#Remove a card from the top
def deal
[@cards.pop()](1)
end
#Add card to the bottom of the deck
def add_to_bottom(the_card)
@cards.insert(0, the_card)
end
#Add card to the top of the deck
def add_to_top(the_card)
@cards << the_card
end
#Shuffle the Card objects in the deck
def shuffle!
@cards.shuffle!
end
def count()
@cards.count()
end
def empty?
@cards.length == 0
end
def to_s
string = ""
@cards.each do |card|
string += card.to_s + " "
end
end
def cards
@cards
end
end
tags on stackoverflow - just make sure all code is indented by 4 spaces.
– joshua.paling Oct 14 '14 at 08:41