-
Notifications
You must be signed in to change notification settings - Fork 0
pokr.rb #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
pokr.rb #1
Changes from all commits
24907c0
ee36b9d
ae15161
4eff75c
77d2639
8698bda
b90e50c
daa4763
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
| ############ |
| 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 |
| 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) | ||
|
|
||
| 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 | ||
| 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting pass through There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = "" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the method to be called |
||
| players.each do |player| | ||
| Flush.new(player) | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment.
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?