7_half 0.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/bin/7_1-2 +42 -0
  3. data/lib/card.rb +15 -0
  4. data/lib/deck.rb +19 -0
  5. data/lib/hand.rb +21 -0
  6. metadata +93 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 500b4007cc9d29c3bca8fc5747b2bc77acf366af
4
+ data.tar.gz: f561605d9f45c810d0194e586e6ce8ae812b2388
5
+ SHA512:
6
+ metadata.gz: 910576c7f53fcecab57a30b4ac94407f7676bf573770b83bb06b27baa25c5503c58b94b61a1b775d28e4214712e023155bc671daef1d37a9ba4c9afec461d54c
7
+ data.tar.gz: 89878dc6abd32ed85d732454e0d6a2360d40e01d7ac62ede1ef22c66913b6296f01addfa8ed95c14d6c968f2386496597b0c2371e5d20c4a1f2d166055ed42a2
data/bin/7_1-2 ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "hand"
4
+ def s_puts(message, time=0.5)
5
+ puts "\t" + message
6
+ sleep time
7
+ end
8
+
9
+ player, dealer = Hand.new, Hand.new
10
+ s_puts "Your turn!", 1
11
+ loop do # Player's turn
12
+ s_puts "You have #{player.cards.view}"
13
+ break if (player.bust? || player.value == 7.5)
14
+ print "\tDo you want to (h)it or (s)tay? "
15
+ case gets.chomp.downcase[0]
16
+ when 'h' then player.hit
17
+ when 's' then break
18
+ end
19
+ s_puts String.new, 1
20
+ end
21
+ if player.bust?
22
+ s_puts "You bust @ #{player.value}!", 1
23
+ s_puts "You lose"
24
+ exit
25
+ end
26
+ until dealer.value > Hand::MDSV
27
+ s_puts "The dealer hits"
28
+ dealer.hit
29
+ end
30
+ if dealer.bust?
31
+ s_puts "The dealer busts @ #{dealer.value}
32
+ s_puts "You win!", 2
33
+ elsif dealer.value > player.value || dealer.value == player.value
34
+ s_puts "You lose"
35
+ elsif dealer.value < player.value
36
+ s_puts "You win"
37
+ else
38
+ raise "Win error"
39
+ end
40
+
41
+
42
+
data/lib/card.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "card_deck"
2
+ class CardDeck::Card # Main object used. Makes this a 'Card' game
3
+ def value
4
+ case num
5
+ when "Ace" then 1
6
+ when 2..7 then num
7
+ when "King" then 0.5
8
+ when "Queen" then 0.5
9
+ when "Jack" then 0.5
10
+ end
11
+ end
12
+ end
13
+
14
+
15
+
data/lib/deck.rb ADDED
@@ -0,0 +1,19 @@
1
+ require_relative "card.rb" # Load modified CardDeck::Card
2
+ class Deck # The 40-card deck used in this game
3
+ attr_reader :cards # The cards in the deck
4
+ def initialize
5
+ @cards = Array.new
6
+ for suit in CardDeck::Card::SUIT
7
+ stock "Ace", suit
8
+ stock "King", suit
9
+ stock "Queen", suit
10
+ stock "Jack", suit
11
+ for num in (2..7).to_a; stock num, suit; end
12
+ end
13
+ @cards.shuffle!
14
+ end
15
+ def length; @cards.length; end # How many cards are in @cards
16
+ def draw; @cards.shift; end # Draw a card from @cards
17
+ private
18
+ def stock(card, suit); @cards.push CardDeck::Card.new(card, suit); end # Creates a card and puts it into @cards
19
+ end
data/lib/hand.rb ADDED
@@ -0,0 +1,21 @@
1
+ require_relative "deck.rb" # Load Deck
2
+ class Hand # Acts as the player
3
+ attr_accessor :cards # The cards in your hand
4
+ DECK = Deck.new # The deck used in the game
5
+ MDSV = 7.5 * (17.0/21.0) # Minimum value the dealer can stay at. Uses the same ratio as blackjack1.
6
+ def initialize; @cards = [DECK.draw]; end
7
+ def hit; @cards.push DECK.draw; end # Adds a card to your hand, increasing your value
8
+ def value # The combined value of all the cards in your hand
9
+ sum = 0.0
10
+ for c in @cards; sum += c.value; end
11
+ return sum
12
+ end
13
+ def bust? # Returns true if #value > 7.5
14
+ if value > 7.5 then true
15
+ else
16
+ false
17
+ end
18
+ end
19
+ end
20
+
21
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: 7_half
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.pre
5
+ platform: ruby
6
+ authors:
7
+ - Zachary Perlmutter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-its
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: card_deck
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ description: "\tThe is a game played in parts of Africa. It is played with a 30 card
56
+ deck or a 52 card deck with all the 8s, 9s. and 10s removed. It works like blackjack
57
+ except you bust at 7½ and face cards are worth ½. You start with one card and play
58
+ against the dealer.\n"
59
+ email: zrp200@gmail.com
60
+ executables:
61
+ - 7_1-2
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - bin/7_1-2
66
+ - lib/card.rb
67
+ - lib/deck.rb
68
+ - lib/hand.rb
69
+ homepage: http://github.com/zrp200/7_1-2
70
+ licenses: []
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">"
84
+ - !ruby/object:Gem::Version
85
+ version: 1.3.1
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.4.1
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: The game of 7½
92
+ test_files: []
93
+ has_rdoc: