Class: BetweenTheSheets::Game
- Inherits:
-
Object
- Object
- BetweenTheSheets::Game
- Extended by:
- Messages
- Defined in:
- lib/between_the_sheets/game.rb,
lib/between_the_sheets/game/screens.rb,
lib/between_the_sheets/game/messages.rb,
lib/between_the_sheets/game/constants.rb,
lib/between_the_sheets/game/rules/win/joker.rb,
lib/between_the_sheets/game/rules/bust/joker.rb,
lib/between_the_sheets/game/rules/win/same_cards.rb,
lib/between_the_sheets/game/rules/bust/consecutive.rb
Defined Under Namespace
Modules: Constants, Messages, Rules, Screens
Constant Summary
Constants included from Messages
Constants included from Constants
Constants::ANTE, Constants::JACKPOT_ANTE, Constants::MINIMUM_BET, Constants::STARTING_CREDITS, Constants::STARTING_JACKPOT
Instance Attribute Summary collapse
-
#card1 ⇒ Object
readonly
Returns the value of attribute card1.
-
#card2 ⇒ Object
readonly
Returns the value of attribute card2.
-
#card3 ⇒ Object
readonly
Returns the value of attribute card3.
-
#jackpot ⇒ Object
readonly
Returns the value of attribute jackpot.
-
#play ⇒ Object
readonly
Returns the value of attribute play.
Instance Method Summary collapse
-
#draw_final_card ⇒ Object
Loads the 3rd card and checks for rules.
-
#draw_initial_cards ⇒ Object
Loads the first 2 cards and checks rules.
-
#execute ⇒ Object
The main game loop.
-
#initialize(jackpot = STARTING_JACKPOT) ⇒ Game
constructor
A new instance of Game.
-
#is_between? ⇒ Boolean
Bool whether card 3 is between cards 1 & 2.
-
#lose(credits = nil) ⇒ Object
Prints the lost message and decrements the players credits.
-
#win(credits = nil) ⇒ Object
Prints the win message and increments the players credits.
-
#win_jackpot ⇒ Object
Prints the jackpot message and increments the players credits.
Methods included from Messages
Methods included from Screens
#intro_screen, #is_between_screen, #transition_screen
Constructor Details
#initialize(jackpot = STARTING_JACKPOT) ⇒ Game
Returns a new instance of Game.
17 18 19 20 21 |
# File 'lib/between_the_sheets/game.rb', line 17 def initialize(jackpot = STARTING_JACKPOT) @rounds = 1 @credits = STARTING_CREDITS @jackpot = jackpot end |
Instance Attribute Details
#card1 ⇒ Object (readonly)
Returns the value of attribute card1.
15 16 17 |
# File 'lib/between_the_sheets/game.rb', line 15 def card1 @card1 end |
#card2 ⇒ Object (readonly)
Returns the value of attribute card2.
15 16 17 |
# File 'lib/between_the_sheets/game.rb', line 15 def card2 @card2 end |
#card3 ⇒ Object (readonly)
Returns the value of attribute card3.
15 16 17 |
# File 'lib/between_the_sheets/game.rb', line 15 def card3 @card3 end |
#jackpot ⇒ Object (readonly)
Returns the value of attribute jackpot.
15 16 17 |
# File 'lib/between_the_sheets/game.rb', line 15 def jackpot @jackpot end |
#play ⇒ Object (readonly)
Returns the value of attribute play.
15 16 17 |
# File 'lib/between_the_sheets/game.rb', line 15 def play @play end |
Instance Method Details
#draw_final_card ⇒ Object
Loads the 3rd card and checks for rules.
39 40 41 42 43 44 45 |
# File 'lib/between_the_sheets/game.rb', line 39 def draw_final_card @card3 = Card.draw(@card1.id, @card2.id) puts "The next card is the #{@card3}" # player wins if card is Joker raise Rules::Win::Joker if @card3.joker? end |
#draw_initial_cards ⇒ Object
Loads the first 2 cards and checks rules.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/between_the_sheets/game.rb', line 24 def draw_initial_cards @card1 = Card.draw @card2 = Card.draw(@card1.id) # check for joker raise Rules::Bust::Joker if @card1.joker? || @card2.joker? # check for consecutive raise Rules::Bust::Consecutive if (@card1.value - @card2.value).abs == 1 # player wins if the cards are the same raise Rules::Win::SameCards if @card1.value == @card2.value end |
#execute ⇒ Object
The main game loop.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/between_the_sheets/game.rb', line 74 def execute loop do transition_screen if @rounds > 1 # Show the intro screen intro_screen @rounds += 1 @credits -= ANTE @jackpot += JACKPOT_ANTE puts "\nAfter ante you have #{@credits.to_s.colorize(:green)} credits" continue = begin draw_initial_cards rescue Rules::Bust::Joker puts "House drew a Joker " lose rescue Rules::Bust::Consecutive puts "House drew consecutive cards #{@card1} & #{@card2} " lose rescue Rules::Win::SameCards puts "House drew #{@card1} and #{@card2} " win_jackpot else true end next unless !!continue # Ask player if next card is between is_between_screen # Ask player for their wager wager = Wager.get(@credits, @jackpot) continue = begin draw_final_card rescue Rules::Win::Joker puts "You drew a #{@card3}" win wager else true end next unless !!continue # check the between rules if is_between? win wager else lose wager end end end |
#is_between? ⇒ Boolean
Bool whether card 3 is between cards 1 & 2
48 49 50 51 52 |
# File 'lib/between_the_sheets/game.rb', line 48 def is_between? is_between = @card3.value.between?(@card1.value, @card2.value) is_between && @play == "y" || !is_between && @play == "n" end |
#lose(credits = nil) ⇒ Object
Prints the lost message and decrements the players credits.
68 69 70 71 |
# File 'lib/between_the_sheets/game.rb', line 68 def lose(credits=nil) @credits -= credits if credits puts self.class.(:lose).colorize :red end |
#win(credits = nil) ⇒ Object
Prints the win message and increments the players credits.
55 56 57 58 |
# File 'lib/between_the_sheets/game.rb', line 55 def win(credits=nil) @credits += credits if credits puts self.class.(:win).colorize :green end |
#win_jackpot ⇒ Object
Prints the jackpot message and increments the players credits.
61 62 63 64 65 |
# File 'lib/between_the_sheets/game.rb', line 61 def win_jackpot @credits += @jackpot @jackpot = STARTING_JACKPOT puts self.class.(:jackpot).colorize :green end |