blackjack1 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +2 -1
- data/bin/blackjack1 +4 -11
- data/lib/hand.rb +5 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzcwNjYyOThmZDljYTU4OTk2ZTNkMDIyNWY1M2E5M2NkZGE2NzQ3OA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWExZWNlYmUzNDA0ZDkyOTNiOGNmYjY5NGNlN2Q2YzMwNDU2YThmNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTg3MmMxZjAyNWY5Y2JmMjRlODYxMThlOTQ4M2IwMzdlZTczMTE4YzE1YWIz
|
10
|
+
MjlmZDkzMDNjZWQzN2YwOGJkZjk1MGNmNDkzMGIxMWM4NDcyZjYzYWRhMjQy
|
11
|
+
MGQ3NWIyN2VkZGJhYjdmZGZiNmIwNTdmM2YyMjZhZTUwMGI2NDI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmZiNTRkYzFjZjIzMmM3MjBiOGM5ZmRlOGU4NDc3MjRhYmRmMTY0MDdhYzhl
|
14
|
+
Mjc3MWQxNzdlODg4ODA1NjNmNjVjY2YwZjFkNGY3ZDQyZjgxMjZlZjNkY2M3
|
15
|
+
YjM5MThjZmE1ZTQ0ZWZjN2M3MmNlOGI5MWRiYjk3OTNlOTE4MjE=
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# blackjack
|
2
|
-
The commonly played card game in casinos and for fun.
|
2
|
+
The commonly played card game in casinos and for fun. Have fun!
|
3
3
|
## Badges
|
4
4
|
[![Build Status](https://travis-ci.org/Zrp200/blackjack1.svg?branch=master)](https://travis-ci.org/Zrp200/blackjack1)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/Zrp200/blackjack1/badges/gpa.svg)](https://codeclimate.com/github/Zrp200/blackjack1)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/Zrp200/blackjack1/badges/coverage.svg)](https://codeclimate.com/github/Zrp200/blackjack1)
|
data/bin/blackjack1
CHANGED
@@ -13,18 +13,11 @@ unless player.blackjack?
|
|
13
13
|
sleep 1
|
14
14
|
loop do
|
15
15
|
puts
|
16
|
-
catch inputerror do
|
17
|
-
print "(h)it or (s)tay? "
|
18
|
-
action = gets.chomp.downcase
|
19
|
-
if action.include?("s") then break
|
20
|
-
elsif !action.include?("h") then throw inputerror
|
21
|
-
end
|
22
|
-
end
|
23
|
-
sleep(1)
|
24
|
-
player.hit
|
25
16
|
print view.call player
|
26
|
-
|
27
|
-
|
17
|
+
print "(h)it or (s)tay? "
|
18
|
+
action = gets.chomp.downcase
|
19
|
+
player.hit if action.include?("h")
|
20
|
+
break if action.include?("s") || player.value >= 21
|
28
21
|
end
|
29
22
|
puts ""
|
30
23
|
unless player.bust?
|
data/lib/hand.rb
CHANGED
@@ -2,20 +2,16 @@ require_relative "card.rb" rescue require "card_deck"
|
|
2
2
|
class Hand # The player
|
3
3
|
attr_accessor :cards # The cards in the hand
|
4
4
|
MDHV = 16 # Maximum Dealer Hit Value; If the dealer's hand is valued more than this number, he will stay.
|
5
|
-
def self.deck=(deck) # Set which deck the game is using. Also shuffles the deck.
|
6
|
-
|
7
|
-
|
8
|
-
def self.deck # The deck the game is using
|
9
|
-
@@deck
|
10
|
-
end
|
5
|
+
def self.deck=(deck); @@deck = deck.cards.shuffle; end # Set which deck the game is using. Also shuffles the deck.
|
6
|
+
|
7
|
+
|
8
|
+
def self.deck; @@deck; end # The deck the game is using
|
11
9
|
def bust?; value > 21; end # Returns true if the value is greater than 21.
|
12
10
|
def blackjack?; value == 21 && @cards.length == 2; end # Returns true if you have blackjack.
|
13
11
|
def initialize(cards=[@@deck.shift, @@deck.shift])
|
14
12
|
@cards = cards
|
15
13
|
end
|
16
|
-
def view # The view of the cards
|
17
|
-
@cards.each {|card| "#{card.abbr}\t"}
|
18
|
-
end
|
14
|
+
def view; @cards.each {|card| "#{card.abbr}\t"}; end # The view of the cards
|
19
15
|
def hit; @cards.push @@deck.shift; end # Add a card to @cards from @@deck
|
20
16
|
def value # The value of the cards in @cards
|
21
17
|
v, aces = 0, 0
|