Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# read me for week 7 metis class work

####pokr####
a poker game

############
17 changes: 17 additions & 0 deletions dealer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Dealer
attr_reader :deck
def initialize(deck)
@deck = deck
deck.build
deck.shuffle
end

def deal(players)
5.times do
players.each do |player|
player.cards << deck.cards.shift
end
end
players
end
end
36 changes: 36 additions & 0 deletions packofcards.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
class Card
attr_reader :rank, :suit
def initialize(suit, rank)
@suit = suit
@rank = rank
end

def to_s
puts "#{suit}#{rank}"
end
end

class Deck
attr_reader :cards
def build
@cards = []
ranks = %w(1 2 3 4 5 6 7 8 9 10 11 12 13)
suits = %w(H H H H)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all of these hearts?


suits.each do |suit|
ranks.each do |rank|
cards << Card.new(suit,rank.to_i)
end
end
end

def show
cards.each do |card|
card.show
end
end

def shuffle
cards.shuffle!
end
end
28 changes: 28 additions & 0 deletions player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Player
attr_reader :name
attr_accessor :cards, :hand
def initialize(index)
@cards = Array.new
@name = give_player_name(index)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting pass through

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense not to give them explicit names, but assign them when there is output. It only really matters on output

@hand = ""
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like hand makes more sense as an array

end

def show_cards
cards.each do |card|
card.to_s
end
end

def show_hand
puts name
show_cards
puts hand
end

private

def give_player_name(index)
index = index + 1
index = "player" + index.to_s
end
end
83 changes: 83 additions & 0 deletions pokr.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
require_relative "packofcards.rb"
require_relative "player.rb"
require_relative "dealer.rb"

class PokerGame
attr_reader :number_of_players
attr_accessor :players
def initialize(number_of_players=4)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the default. make sure to have a space on either side of =

@number_of_players = number_of_players
@players = Array.new
end

def play
create_players
players = deal_cards
determine_hand = HandCaculator.new(players)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HandCaculator should probably be HandCalculator

determine_hand.start
reveal_hands
end

def deal_cards
dealer = Dealer.new(Deck.new)
dealer.deal(players)
end

def create_players
number_of_players.times { |index| players << Player.new(index) }
end

def reveal_hands
players.each { |player| puts player.show_hand }
end
end

class HandCaculator
attr_reader :players
def initialize(players)
@players = players
end

def start
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the method to be called calculate

players.each do |player|
Flush.new(player)
end
end
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of spacing

class Flush
attr_reader :cards, :player, :results
def initialize(player)
@player = player
@cards = player.cards
@results = []
determine
end

def determine
cards.each { |card| results << card.suit }
results.uniq!
if results.length == 1
player.hand = "Flush"
end
end
end

class OnePair
attr_reader :cards
def initialize(player)
@cards = player.cards
list_ranks
determine
end

def determine
results = cards.uniq
puts results
end
end



game = PokerGame.new(4)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a default here of 4 already, no need to put it in explicitly.

game.play