Skip to content

Commit

Permalink
Refractor Card Class and the Deck Class
Browse files Browse the repository at this point in the history
  • Loading branch information
davidortizfrau committed Mar 4, 2014
1 parent cb8ad58 commit 1a0a1cc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 9 additions & 0 deletions card.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
class Card
attr_accessor :suit, :value, :face

@SUITS = ["s", "h", "c", "d"]

@FACE_VALUES = {"A" => 13, "K" => 12, "Q" => 11, "J" => 10, "10" => 9, "9" => 8,
"8" => 7, "7" => 6, "6" => 5, "5" => 4, "4" => 3, "3" => 2, "2" => 1}

class << self
attr_reader :SUITS, :FACE_VALUES
end
end
5 changes: 2 additions & 3 deletions deck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ class Deck

def initialize
self.cards = []
%w(s h c d).each do |suit|
{"A" => 13, "K" => 12, "Q" => 11, "J" => 10, "10" => 9, "9" => 8,
"8" => 7, "7" => 6, "6" => 5, "5" => 4, "4" => 3, "3" => 2, "2" => 1}.each do |key, value|
Card.SUITS.each do |suit|
Card.FACE_VALUES.each do |key, value|
card = Card.new
card.face = key
card.suit = suit
Expand Down

0 comments on commit 1a0a1cc

Please sign in to comment.