blackjack1 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c1d779dcde71a700696d492427e1ceb1f965532
4
+ data.tar.gz: 8bdc62c837233802283a0a81138f259eed31f1b0
5
+ SHA512:
6
+ metadata.gz: ed6fcaf5144f2f250c839f3b75075d37d31a6c8714f1b50fc7ae34012f57b4b141f659956438ab48cb001ab8cf0c96dec450eac31366c0008db8e815de520e0b
7
+ data.tar.gz: 1ba0fa906ba408565137d52c7348082a223d484037813c13e432e6ab25c910f7f1c75d45f8c49a9d9e041dde5595fa099b89f3e80b0c16000029c330ca003712
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Zachary Perlmutter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # blackjack
2
+ ## Badges
3
+ [![Build Status](https://travis-ci.org/Zrp200/blackjack1.svg?branch=master)](https://travis-ci.org/Zrp200/blackjack1)
4
+ [![Code Climate](https://codeclimate.com/github/Zrp200/blackjack1/badges/gpa.svg)](https://codeclimate.com/github/Zrp200/blackjack1)
data/bin/blackjack1 ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ require "blackjack1"
3
+ Hand.deck = CardDeck::Deck.new
4
+ dealer, player, view = Hand.new, Hand.new, proc do |player|
5
+ puts "You have: #{player.view}"
6
+ sleep(0.5)
7
+ puts "Value: #{player.value}"
8
+ sleep(1)
9
+ end
10
+ view.call player
11
+ unless player.blackjack?
12
+ puts "The dealer is showing #{dealer.cards[1].abbr}\n"
13
+ sleep 1
14
+ print "Hit or stay? "
15
+ action = gets.chomp.downcase
16
+ f = true if action == "hit"
17
+ while action == "hit" and !player.bust?
18
+ unless f
19
+ puts
20
+ print "Hit or stay? "
21
+ action == gets.chomp.downcase
22
+ break unless action == "hit"
23
+ else
24
+ f = false
25
+ end
26
+ sleep(1)
27
+ player.hit
28
+ print view.call(player)
29
+ sleep(1.5)
30
+ end
31
+ puts ""
32
+ unless player.bust?
33
+ puts "You finished with #{player.value}."
34
+ else
35
+ puts "You busted."
36
+ end
37
+ sleep 2
38
+ if dealer.blackjack?
39
+ puts "Dealer got blackjack."
40
+ sleep 0.5
41
+ puts "Dealer wins."
42
+ sleep 2
43
+ exit
44
+ end
45
+ puts
46
+ while dealer.value <= Hand::MDHV
47
+ puts "The dealer hit!"
48
+ dealer.hit
49
+ sleep 0.5
50
+ end
51
+ puts
52
+ if dealer.bust? then puts "The dealer busted!"
53
+ else
54
+ puts "The dealer stays at #{dealer.value}"
55
+ end
56
+ sleep 2
57
+ puts compare_score player, dealer
58
+ else
59
+ puts "You got blackjack!"
60
+ sleep 1
61
+ puts "You win!"
62
+ sleep 0.5
63
+ end
data/lib/blackjack1.rb ADDED
@@ -0,0 +1,16 @@
1
+ require_relative "hand.rb"
2
+ def compare_score(p1, p2, args=Hash.new(false)) # Determines who wins. parameter p1 is the player and parameter p2 is the dealer.
3
+ unless args[:compare]
4
+ win, lose, tie = "You win!", "Dealer wins.", "Tie"
5
+ else
6
+ win, lose, tie = true, false, nil
7
+ end
8
+ if p1.bust? and p2.bust? then return tie
9
+ elsif p2.bust? then return win
10
+ elsif p1.bust? then return lose
11
+ elsif p1.value > p2.value then return win
12
+ elsif p2.value > p1.value then return lose
13
+ else
14
+ return tie
15
+ end
16
+ end
data/lib/card.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "card_deck"
2
+ class CardDeck::Card
3
+ def value # The points a card is worth
4
+ case num
5
+ when 2..10 then num.to_i
6
+ when "Ace" then 11
7
+ when "Jack" then 10
8
+ when "Queen" then 10
9
+ when "King" then 10
10
+ end
11
+ end
12
+ end
13
+
data/lib/hand.rb ADDED
@@ -0,0 +1,32 @@
1
+ require_relative "card.rb" rescue require "card_deck"
2
+ class Hand # The player
3
+ attr_accessor :cards # The cards in the hand
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
+ @@deck = deck.cards.shuffle
7
+ end
8
+ def self.deck # The deck the game is using
9
+ @@deck
10
+ end
11
+ def bust?; value > 21; end # Returns true if the value is greater than 21.
12
+ def blackjack?; value == 21 && @cards.length == 2; end # Returns true if you have blackjack.
13
+ def initialize(cards=[@@deck.shift, @@deck.shift])
14
+ @cards = cards
15
+ end
16
+ def view # The view of the cards
17
+ @cards.each {|card| "#{card.abbr}\t"}
18
+ end
19
+ def hit; @cards.push @@deck.shift; end # Add a card to @cards from @@deck
20
+ def value # The value of the cards in @cards
21
+ v, aces = 0, 0
22
+ for card in @cards
23
+ v += card.value
24
+ aces += 1 if card.num == "Ace"
25
+ end
26
+ while v > 21 && aces > 0
27
+ v -= 10
28
+ aces -= 1
29
+ end
30
+ return v
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blackjack1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Zachary Perlmutter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: card_deck
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-its
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email: zrp200@gmail.com
57
+ executables:
58
+ - blackjack1
59
+ extensions: []
60
+ extra_rdoc_files:
61
+ - README.md
62
+ - LICENSE
63
+ files:
64
+ - LICENSE
65
+ - README.md
66
+ - bin/blackjack1
67
+ - lib/blackjack1.rb
68
+ - lib/card.rb
69
+ - lib/hand.rb
70
+ homepage:
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.9.2
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements:
89
+ - Command Prompt
90
+ rubyforge_project:
91
+ rubygems_version: 2.4.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: The classic game of blackjack
95
+ test_files: []
96
+ has_rdoc: