ninety_eight 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: 9c6f9007d908551b692189485674a0b124ef0278
4
+ data.tar.gz: d5e6cbb6c364d78bd53f47d86238dff27d8c6c19
5
+ SHA512:
6
+ metadata.gz: 5fbf263b6ef95b906606dc0845664a1abb8eb10bbd14ac06b75e7bc36f3a94189a29f844f2acdb5021bb7f0f793e7472b8ee23345af81a1be632a764ec0cacaa
7
+ data.tar.gz: a977aabfd13c8a48156235af62ad397e98463c744e99da9aba82a7be711e77431d33bf7e7cbca137381135224decce57f693711b5855f04af874e094891b02eb
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
4
+ --f doc
data/bin/ninety_eight ADDED
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby
2
+ require 'ninety_eight'
3
+ BEGIN {
4
+ puts %Q{\t\tThe Game of 98}
5
+ puts %Q{\t\t--------------}
6
+ print "\tWould you like to see the rules? (y/n) => "
7
+ if gets.chomp.downcase.include?("y")
8
+ puts
9
+ sleep(1.5)
10
+ puts "\t\tRules"
11
+ puts "\t\t-----"
12
+ puts
13
+ sleep(2)
14
+ puts "\tThe point of the game is to get your opponent to raise the value above 98 by \nputting down one of four cards that either increase or decrease the value."
15
+ puts
16
+ sleep(3.5)
17
+ puts "\t\tValues"
18
+ puts "\t\t------"
19
+ puts
20
+ sleep(2)
21
+ # \u00B7 is a bullet point
22
+ puts "\t\u00B7 Aces are worth 1"
23
+ sleep(2.5)
24
+ puts "\t\u00B7 2 through 9 are worth themselves; example: 2 is worth 2"
25
+ sleep(2.5)
26
+ puts "\t\u00B7 10s are worth -10"
27
+ sleep(2.5)
28
+ puts "\t\u00B7 Jacks and Queens are worth nothing"
29
+ sleep(2.5)
30
+ puts "\t\u00B7 Kings set the value to 98"
31
+ gets
32
+ end
33
+ puts
34
+ puts
35
+ puts
36
+ }
37
+ def test(value, card)
38
+ if card.num == "King"; value = 98
39
+ else; value = $value + card.value
40
+ end
41
+ value = -100 if value > 98
42
+ end
43
+ def pause(p)
44
+ sleep(p)
45
+ puts
46
+ end
47
+ END {
48
+ puts
49
+ sleep(2.5)
50
+ puts "\tThanks for playing '98'!"
51
+ sleep(2.5)
52
+ }
53
+ deal = Hand.new
54
+ user = Hand.new
55
+ $value1, $value2, $value3, $value4, $value = 0,0,0,0,0
56
+ loop {
57
+ $deck.shuffle!
58
+ pause(1.5)
59
+ puts "\tIt's the dealer's turn!"
60
+ pause(2.5)
61
+ i = 1
62
+ for card in deal.hand
63
+ case i
64
+ when 1 then test($value1, card)
65
+ when 2 then test($value2, card)
66
+ when 3 then test($value3, card)
67
+ when 4 then test($value4, card)
68
+ end
69
+ i += 1
70
+ end
71
+ if $value1 >= $value2 && $value1 >= $value3 && $value1 >= $value4
72
+ $card = deal.hand[0]
73
+ deal.play(deal.hand[0])
74
+ elsif $value2 >= $value3 && $value2 >= $value4
75
+ $card = deal.hand[1]
76
+ deal.play(deal.hand[1])
77
+ elsif $value3 >= $value4
78
+ $card = deal.hand[2]
79
+ deal.play(deal.hand[2])
80
+ else
81
+ $card = deal.hand[3]
82
+ deal.play(deal.hand[3])
83
+ end
84
+ puts "\tThe dealer played a(n) #{$card.num}"
85
+ puts
86
+ sleep(0.5)
87
+ puts "\tThe value is now #{$value}"
88
+ puts
89
+ pause(1.5)
90
+ if $value > 98
91
+ puts "\tYou win!"
92
+ break
93
+ end
94
+ puts "\tIt's your turn!"
95
+ pause(1.5)
96
+ print "\tThese are your cards: "
97
+ user.list
98
+ pause(0.5)
99
+ print "\tType in either the name of the card you want to play or the first letter of it => "
100
+ user.play(UserCard.new(gets.chomp))
101
+ pause (1.5)
102
+ puts "\tYou drew a #{user.hand[3].num}"
103
+ pause(0.5)
104
+ puts "\tThe value is now #{$value}"
105
+ pause(1.5)
106
+ if $value > 98
107
+ puts "\tYou lose!"
108
+ break
109
+ end
110
+ $deck.shuffle!
111
+ }
@@ -0,0 +1,81 @@
1
+ class CardError < StandardError; end
2
+ class Card
3
+ attr_reader :num
4
+ def initialize(card); @num = card; end
5
+ def value
6
+ case self.num
7
+ when "Ace" then return 1
8
+ when 2..9 then return self.num
9
+ when 10 then return -10
10
+ when "King" then return 98 #Sets value to 98
11
+ else; return 0
12
+ end
13
+ end
14
+ end
15
+ class UserCard < Card
16
+ @@num = {King: "King", K: "King", Queen: "Queen", Q: "Queen", Ace: "Ace", A: "Ace", Jack: "Jack", J: "Jack"}
17
+ def initialize(card)
18
+ @@num.default = card.to_i
19
+ @num = @@num[card.capitalize.to_sym]
20
+ end
21
+ end
22
+ class Hand
23
+ attr_reader :hand
24
+ def initialize
25
+ $deck.shuffle!
26
+ @hand = [$deck.shift, $deck.shift, $deck.shift, $deck.shift]
27
+ $deck.shuffle!
28
+ end
29
+ def list; @hand.each {|card| print "\t#{card.num}"}; end
30
+ def play(card)
31
+ $legal, i, done = false, 0, false
32
+ for cards in @hand
33
+ if cards.num == card.num and done == false
34
+ done = true
35
+ $legal = true
36
+ $deck.shuffle!
37
+ draw = $deck.shift
38
+ discard = @hand[i]
39
+ @hand.delete_at(i)
40
+ $deck.push(discard)
41
+ $deck.shuffle!
42
+ @hand.push(draw)
43
+ end
44
+ i += 1
45
+ end
46
+ raise CardError, "\aCard not Allowed\a" unless $legal
47
+ if card.num == "King"; $value = 98
48
+ else; $value += card.value
49
+ end
50
+ end
51
+ end
52
+ $deck = Array.new
53
+ 4.times do
54
+ $deck.shuffle!
55
+ $deck.push(Card.new("Ace"))
56
+ $deck.shuffle!
57
+ $deck.push(Card.new("King"))
58
+ $deck.shuffle!
59
+ $deck.push(Card.new("Queen"))
60
+ $deck.shuffle!
61
+ $deck.push(Card.new("Jack"))
62
+ $deck.shuffle!
63
+ $deck.push(Card.new(10))
64
+ $deck.shuffle!
65
+ $deck.push(Card.new(9))
66
+ $deck.shuffle!
67
+ $deck.push(Card.new(8))
68
+ $deck.shuffle!
69
+ $deck.push(Card.new(7))
70
+ $deck.shuffle!
71
+ $deck.push(Card.new(6))
72
+ $deck.shuffle!
73
+ $deck.push(Card.new(5))
74
+ $deck.shuffle!
75
+ $deck.push(Card.new(4))
76
+ $deck.shuffle!
77
+ $deck.push(Card.new(3))
78
+ $deck.shuffle!
79
+ $deck.push(Card.new(2))
80
+ $deck.shuffle!
81
+ end
data/spec/98spec.rb ADDED
@@ -0,0 +1,5 @@
1
+ require_relative "spec_helper"
2
+ require "ninety_eight"
3
+ describe "Card" do
4
+ cards
5
+ end
@@ -0,0 +1,76 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # The settings below are suggested to provide a good initial experience
19
+ # with RSpec, but feel free to customize to your heart's content.
20
+ # These two settings work together to allow you to limit a spec run
21
+ # to individual examples or groups you care about by tagging them with
22
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
23
+ # get run.
24
+ config.filter_run :focus
25
+ config.run_all_when_everything_filtered = true
26
+
27
+ # Many RSpec users commonly either run the entire suite or an individual
28
+ # file, and it's useful to allow more verbose output when running an
29
+ # individual spec file.
30
+ if config.files_to_run.one?
31
+ # Use the documentation formatter for detailed output,
32
+ # unless a formatter has already been configured
33
+ # (e.g. via a command-line flag).
34
+ config.default_formatter = 'doc'
35
+ end
36
+
37
+ # Print the 10 slowest examples and example groups at the
38
+ # end of the spec run, to help surface which specs are running
39
+ # particularly slow.
40
+ config.profile_examples = 10
41
+
42
+ # Run specs in random order to surface order dependencies. If you find an
43
+ # order dependency and want to debug it, you can fix the order by providing
44
+ # the seed, which is printed after each run.
45
+ # --seed 1234
46
+ config.order = :random
47
+
48
+ # Seed global randomization in this process using the `--seed` CLI option.
49
+ # Setting this allows you to use `--seed` to deterministically reproduce
50
+ # test failures related to randomization by passing the same `--seed` value
51
+ # as the one that triggered the failure.
52
+ Kernel.srand config.seed
53
+
54
+ # rspec-expectations config goes here. You can use an alternate
55
+ # assertion/expectation library such as wrong or the stdlib/minitest
56
+ # assertions if you prefer.
57
+ config.expect_with :rspec do |expectations|
58
+ # Enable only the newer, non-monkey-patching expect syntax.
59
+ # For more details, see:
60
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
+ expectations.syntax = :expect
62
+ end
63
+
64
+ # rspec-mocks config goes here. You can use an alternate test double
65
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
66
+ config.mock_with :rspec do |mocks|
67
+ # Enable only the newer, non-monkey-patching expect syntax.
68
+ # For more details, see:
69
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
70
+ mocks.syntax = :expect
71
+
72
+ # Prevents you from mocking or stubbing a method that does not exist on
73
+ # a real object. This is generally recommended.
74
+ mocks.verify_partial_doubles = true
75
+ end
76
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ninety_eight
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-06-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A computer genarated version of the card game 98. Comes with an executable
14
+ with the actual game.
15
+ email: zrp200@gamil.com
16
+ executables:
17
+ - ninety_eight
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - bin/ninety_eight
23
+ - lib/ninety_eight.rb
24
+ - spec/98spec.rb
25
+ - spec/spec_helper.rb
26
+ homepage: https://rubygems.org/gems/ninety_eight
27
+ licenses: []
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.3.0
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: The game of 98
49
+ test_files:
50
+ - ".rspec"
51
+ - spec/spec_helper.rb
52
+ - spec/98spec.rb