ruby-blackjack 0.1.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/blackjack/blackjack_cli.rb +14 -9
- data/lib/blackjack/objects/card.rb +4 -4
- data/lib/blackjack/strings/string.rb +37 -1
- data/lib/ruby-blackjack.rb +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efe3747adde761eea4f77c2afa6855c569c4288a
|
4
|
+
data.tar.gz: 819656988aba32192bdecda5ec00ac03e63a7631
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
60
|
+
puts ' You won :D '.set_attributes([GREEN_BG, BLACK_FG])
|
60
61
|
elsif result[2] == 'loss'
|
61
|
-
puts 'You lost :('.set_attributes([
|
62
|
+
puts ' You lost :( '.set_attributes([RED_BG, BLACK_FG])
|
62
63
|
elsif result[2] == 'draw'
|
63
|
-
puts "It's a draw".set_attributes([
|
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(
|
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])})"
|
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 "\
|
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(
|
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(
|
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([
|
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([
|
79
|
+
suit = suit.set_attributes([BLACK_FG], [WHITE_BG, BLACK_FG])
|
80
80
|
else
|
81
|
-
suit = suit.set_attributes([
|
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([
|
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
|
-
#
|
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
|
data/lib/ruby-blackjack.rb
CHANGED