Created
November 20, 2012 22:55
-
-
Save nfriend21/4121831 to your computer and use it in GitHub Desktop.
war
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SUITS = %w{clubs hearts spades diamonds} | |
VALUES = [2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K", "A"] | |
Card = Struct.new(:value, :suit, :amount) | |
$deck = [] | |
SUITS.each do |suit| | |
VALUES.each do |value| | |
if value.class == Fixnum && value <= 10 | |
amount = value | |
end | |
if value == "J" | |
amount = 11 | |
elsif value == "Q" | |
amount = 12 | |
elsif value == "K" | |
amount = 13 | |
elsif value == "A" | |
amount = 14 | |
end | |
$deck << Card.new(value, suit, amount) | |
end | |
end | |
class Hand | |
attr_accessor :hands | |
def initialize(no_of_players) | |
@hands = {} | |
no_of_players.times do |number| | |
@hands["player_#{number}"] = [] | |
end | |
end | |
def deal(no_of_players) | |
$deck.shuffle | |
begin | |
no_of_players.times do |number| | |
@hands["player_#{number}"] << $deck.pop | |
end | |
end until $deck.empty? | |
end | |
end | |
class Game | |
attr_accessor :game | |
def initialize(no_of_players) | |
@game = {} | |
no_of_players.times do |number| | |
@game["player_#{number}"] = @hands["player_#{number}"].pop | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment