ruby-blackjack 0.1.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1db3c69bee044512f2d1451b2635305ada2bac89
4
- data.tar.gz: ab5e09392533545361379727f1dad80f1169d3bf
3
+ metadata.gz: efe3747adde761eea4f77c2afa6855c569c4288a
4
+ data.tar.gz: 819656988aba32192bdecda5ec00ac03e63a7631
5
5
  SHA512:
6
- metadata.gz: f9c02eb4f9b9e737f914290fcdbbe4e1ce182dce86d4d68bfd91553ee7d40f1ee1fcda15de93af99709e31bf9a26307be73d294faa9bab5ae22afe6a2156f07a
7
- data.tar.gz: eb6810b56e57ab59a4d2a5de6bd1fd882530e738daa84f8258f8a155c0578368f9262e8db40617629c9e24d1d54ed2a02ed3ad648660fc2ca7cd355f4f5d0946
6
+ metadata.gz: 55a3e2a588222eb38d1219e65770bc947d14d162c4da6c76528c753caa9cc21a1bebd11c8a1586721ce1595c2a478c198354dde1aa666070e87f6e0d72267304
7
+ data.tar.gz: 320f47ecda727b8264749a8b846db8a9fa0a381d5a071c6d71941c90b33c48c62ced35c6ed24ec1a6a52eeb18e4656399fee8d9036caeef548d1b2e1ad3987fa
data/README.md CHANGED
@@ -1 +1,11 @@
1
1
  # Ruby Blackjack
2
+
3
+ This is a simple Command Line Blackjack game written in ruby
4
+
5
+ To install the program, simply run
6
+
7
+ gem install ruby-blackjack
8
+
9
+ Then start the program using the command 'blackjack'
10
+
11
+ [Rubygems site]("https://rubygems.org/gems/ruby-blackjack")
@@ -28,7 +28,8 @@ class BlackjackCli
28
28
  # Constructor for the BlackJackCli class
29
29
  # @return [nil]
30
30
  def initialize
31
- puts 'Blackjack CLI started'.set_attributes([47, 30])
31
+ @default_text_color = [LIGHT_GRAY_BG, BLACK_FG]
32
+ puts " Blackjack CLI started \n\n".set_attributes(@default_text_color)
32
33
  @blackjack = Game.new
33
34
  end
34
35
 
@@ -56,11 +57,11 @@ class BlackjackCli
56
57
  print_result(result)
57
58
 
58
59
  if result[2] == 'win'
59
- puts 'You won!'.set_attributes([47, 30])
60
+ puts ' You won :D '.set_attributes([GREEN_BG, BLACK_FG])
60
61
  elsif result[2] == 'loss'
61
- puts 'You lost :('.set_attributes([47, 30])
62
+ puts ' You lost :( '.set_attributes([RED_BG, BLACK_FG])
62
63
  elsif result[2] == 'draw'
63
- puts "It's a draw".set_attributes([47, 30])
64
+ puts " It's a draw ".set_attributes([[YELLOW_BG, BLACK_FG]])
64
65
  end
65
66
 
66
67
  if result[2] != 'undecided'
@@ -74,7 +75,7 @@ class BlackjackCli
74
75
  # This pauses the game until the user presses enter/return before starting a new game
75
76
  # @return [nil]
76
77
  def pause_when_game_ends
77
- puts 'Press enter to start a new game'.set_attributes([47, 30])
78
+ puts ' Press enter to start a new game '.set_attributes(@default_text_color)
78
79
  gets
79
80
  end
80
81
 
@@ -82,10 +83,13 @@ class BlackjackCli
82
83
  # @param [Card Array, Card Array] result the result to be displayed
83
84
  # @return [nil]
84
85
  def print_result(result)
85
- puts "Player Cards: (#{Game.calculate_optimal_card_score(result[0])})".set_attributes([47, 30])
86
+ puts " Player Cards: (#{Game.calculate_optimal_card_score(result[0])}) \n"
87
+ .set_attributes(@default_text_color)
86
88
  puts format_cards(result[0])
87
- puts "\nDealer Cards: (#{Game.calculate_optimal_card_score(result[1])})".set_attributes([47, 30])
89
+ puts "\n Dealer Cards: (#{Game.calculate_optimal_card_score(result[1])}) \n"
90
+ .set_attributes(@default_text_color)
88
91
  puts format_cards(result[1])
92
+ puts "\n"
89
93
  end
90
94
 
91
95
  # Formats cards to be displayed side-by-side
@@ -115,12 +119,13 @@ class BlackjackCli
115
119
  # Gets the user's input on what to do next
116
120
  # @return [string] the (validated) user input
117
121
  def get_play_command
118
- puts 'What would you like to do? (hit|stand)'.set_attributes([47, 30])
122
+ puts ' What would you like to do? (hit|stand) '.set_attributes(@default_text_color)
119
123
  input = gets
120
124
  while not input == "hit\n" and not input == "stand\n"
121
- puts "Please enter 'hit' or 'stand'".set_attributes([47, 30])
125
+ puts " Please enter 'hit' or 'stand' ".set_attributes(@default_text_color)
122
126
  input = gets
123
127
  end
128
+ puts "\n"
124
129
  input
125
130
  end
126
131
 
@@ -57,7 +57,7 @@ class Card
57
57
  ascii_card = "#{top}\n| #{number}" + ' ' * offset + "|\n"
58
58
  ascii_card += empty_row * 2 + "| #{suit} |\n" + empty_row * 2
59
59
  ascii_card += '|' + ' ' * offset + "#{number} |\n#{bottom}"
60
- ascii_card.set_attributes([107, 30]) # BG = White, FG = Black
60
+ ascii_card.set_attributes([WHITE_BG, BLACK_FG])
61
61
  end
62
62
 
63
63
 
@@ -76,9 +76,9 @@ class Card
76
76
 
77
77
  suit = suits[type]
78
78
  if type == 'spades' or type == 'clubs'
79
- suit = suit.set_attributes([30], [107, 30]) # FG = Black, return to BG = White, FG = Black
79
+ suit = suit.set_attributes([BLACK_FG], [WHITE_BG, BLACK_FG])
80
80
  else
81
- suit = suit.set_attributes([31], [107, 30]) # FG = Red, return to BG = White, FG = Black
81
+ suit = suit.set_attributes([RED_FG], [WHITE_BG, BLACK_FG])
82
82
  end
83
83
 
84
84
  if number < 10 and number != 1
@@ -101,7 +101,7 @@ class Card
101
101
  def generate_cardback
102
102
  ("┌─────────┐\n" +
103
103
  ("│░░░░░░░░░│\n" * 7) +
104
- '└─────────┘').set_attributes([107, 30]) # BG = White, FG = Black
104
+ '└─────────┘').set_attributes([WHITE_BG, BLACK_FG])
105
105
  end
106
106
 
107
107
  # Flips over the card so that the cardback is shown instead of the generated ASCII card
@@ -46,4 +46,40 @@ class String
46
46
 
47
47
  end
48
48
 
49
- # TODO Maybe replace previous attributes by just replacing all 0m's
49
+ # Foregrounds
50
+ DEFAULT_FG = 39
51
+ BLACK_FG = 30
52
+ RED_FG = 31
53
+ GREEN_FG = 32
54
+ YELLOW_FG = 33
55
+ BLUE_FG = 34
56
+ MAGENTA_FG = 35
57
+ CYAN_FG = 36
58
+ LIGHT_GRAY_FG = 37
59
+ DARK_GRAY_FG = 90
60
+ LIGHT_RED_FG = 91
61
+ LIGHT_GREEN_FG = 92
62
+ LIGHT_YELLOW_FG = 93
63
+ LIGHT_BLUE_FG = 94
64
+ LIGHT_MAGENTA_FG = 95
65
+ LIGHT_CYAN_FG = 96
66
+ WHITE_FG = 97
67
+
68
+ # Backgrounds
69
+ DEFAULT_BG = 49
70
+ BLACK_BG = 40
71
+ RED_BG = 41
72
+ GREEN_BG = 42
73
+ YELLOW_BG = 43
74
+ BLUE_BG = 44
75
+ MAGENTA_BG = 45
76
+ CYAN_BG = 46
77
+ LIGHT_GRAY_BG = 47
78
+ DARK_GRAY_BG = 100
79
+ LIGHT_RED_BG = 101
80
+ LIGHT_GREEN_BG = 102
81
+ LIGHT_YELLOW_BG = 103
82
+ LIGHT_BLUE_BG = 104
83
+ LIGHT_MAGENTA_BG = 105
84
+ LIGHT_CYAN_BG = 106
85
+ WHITE_BG = 107
@@ -19,4 +19,7 @@
19
19
  # along with ruby-blackjack. If not, see <http://www.gnu.org/licenses/>.
20
20
  #
21
21
 
22
- require_relative('../lib/blackjack/blackjack_cli')
22
+ require_relative('../lib/blackjack/blackjack_cli')
23
+
24
+ cli = BlackjackCli.new
25
+ cli.game_loop
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-blackjack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hermann Krumrey