ninety_eight 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c6f9007d908551b692189485674a0b124ef0278
4
- data.tar.gz: d5e6cbb6c364d78bd53f47d86238dff27d8c6c19
3
+ metadata.gz: 244fd5391666b738719f06ef1484be4bbae5e349
4
+ data.tar.gz: 4311766aa962fb41940ff7c7ba069e8727dd1469
5
5
  SHA512:
6
- metadata.gz: 5fbf263b6ef95b906606dc0845664a1abb8eb10bbd14ac06b75e7bc36f3a94189a29f844f2acdb5021bb7f0f793e7472b8ee23345af81a1be632a764ec0cacaa
7
- data.tar.gz: a977aabfd13c8a48156235af62ad397e98463c744e99da9aba82a7be711e77431d33bf7e7cbca137381135224decce57f693711b5855f04af874e094891b02eb
6
+ metadata.gz: 123dd4cd1d045b5c3e4dc904a4f22d48fc695d2ddd091bb074d0ee86a6fd5bb19b3f4ef7eb7ceec08c9c882fcbb4c0c2bcf65934f32fc30d749292d2551d87a7
7
+ data.tar.gz: 432c65eaeaffb3cf17a018655788f98d658f6a1fb6f58692989a43a1b1709bcbed57a93f50a4c8b23ed5b6ebf030b71e131a9f4439cb10f973f1455742823f59
data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ [![Code Climate](https://codeclimate.com/github/Zrp200/ninety_eight.png)](https://codeclimate.com/github/Zrp200/ninety_eight)
2
+ [![Inline docs](http://inch-ci.org/github/Zrp200/ninety_eight.png?branch=master)](http://inch-ci.org/github/Zrp200/ninety_eight)
3
+ [![Gem Version](https://badge.fury.io/rb/ninety_eight.svg)](http://badge.fury.io/rb/ninety_eight)
4
+ [![Coverage](https://codeclimate.com/github/Zrp200/ninety_eight/coverage.png)
5
+ ninety_eight
6
+ ============
7
+
8
+ The game of 98
data/bin/ninety_eight CHANGED
@@ -1,49 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'ninety_eight'
3
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
4
+ ARGV[0] = "-h" if ARGV[0] == "--help"
5
+ case ARGV[0]
6
+ when "-h"
7
+ puts "\u00b7 Rules"
8
+ puts "\t\u00b7 The point of the game is to get your opponent to raise the value above 98 by putting down one of four cards that either increase or decrease the value."
9
+ puts "\u00b7 Values"
10
+ puts "\t\u00B7 Aces are worth 1"
11
+ puts "\t\u00B7 2 through 9 are worth themselves; example: 2 is worth 2"
12
+ puts "\t\u00B7 10s are worth -10"
13
+ puts "\t\u00B7 Jacks and Queens are worth nothing"
14
+ puts "\t\u00B7 Kings set the value to 98"
15
+ exit
32
16
  end
33
- puts
34
- puts
35
- puts
36
17
  }
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
18
+
47
19
  END {
48
20
  puts
49
21
  sleep(2.5)
data/lib/ninety_eight.rb CHANGED
@@ -1,8 +1,21 @@
1
+ # Errors that happen in the game. If you get this error, everything is working fine.
1
2
  class CardError < StandardError; end
2
- class Card
3
+ def test(value, card) # Tests value of cards. Used by CPU.
4
+ if card.num == "King"; value = 98
5
+ else; value = $value + card.value
6
+ end
7
+ value = -100 if value > 98
8
+ end
9
+ def pause(p) # Shortcut for sleep and a newline.
10
+ sleep(p)
11
+ puts
12
+ end
13
+ class Card # The objects that are used in gameplay. Found in $deck.
14
+ # The number on the card
3
15
  attr_reader :num
16
+ # Creates a new card.
4
17
  def initialize(card); @num = card; end
5
- def value
18
+ def value # Returns the Card's value based on its :num attribute.
6
19
  case self.num
7
20
  when "Ace" then return 1
8
21
  when 2..9 then return self.num
@@ -12,22 +25,26 @@ class Card
12
25
  end
13
26
  end
14
27
  end
28
+ # A subclass of Card that can imitate its superclass. Used to make user input Card-like.
15
29
  class UserCard < Card
30
+ # Abbrevations
16
31
  @@num = {King: "King", K: "King", Queen: "Queen", Q: "Queen", Ace: "Ace", A: "Ace", Jack: "Jack", J: "Jack"}
17
- def initialize(card)
32
+ def initialize(card) # Creates a new UserCard. Looks at abbrevations and modifies user input so it is Card-like.
18
33
  @@num.default = card.to_i
19
34
  @num = @@num[card.capitalize.to_sym]
20
35
  end
21
36
  end
22
- class Hand
37
+ class Hand # The gameplay happens here. Holds four cards and interacts with $deck.
38
+ # The player's actual hand
23
39
  attr_reader :hand
24
- def initialize
40
+ def initialize # Creates a new Hand. Takes four cards from $deck and shuffles $deck.
25
41
  $deck.shuffle!
26
42
  @hand = [$deck.shift, $deck.shift, $deck.shift, $deck.shift]
27
43
  $deck.shuffle!
28
44
  end
45
+ # Lists the cards in attribute :hand.
29
46
  def list; @hand.each {|card| print "\t#{card.num}"}; end
30
- def play(card)
47
+ def play(card) # Gameplay method
31
48
  $legal, i, done = false, 0, false
32
49
  for cards in @hand
33
50
  if cards.num == card.num and done == false
@@ -36,10 +53,10 @@ class Hand
36
53
  $deck.shuffle!
37
54
  draw = $deck.shift
38
55
  discard = @hand[i]
39
- @hand.delete_at(i)
40
- $deck.push(discard)
56
+ @hand.delete_at i
57
+ $deck.push discard
41
58
  $deck.shuffle!
42
- @hand.push(draw)
59
+ @hand << draw
43
60
  end
44
61
  i += 1
45
62
  end
@@ -78,4 +95,4 @@ $deck = Array.new
78
95
  $deck.shuffle!
79
96
  $deck.push(Card.new(2))
80
97
  $deck.shuffle!
81
- end
98
+ end
data/spec/98spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require_relative "spec_helper"
2
2
  require "ninety_eight"
3
- describe "Card" do
4
- cards
5
- end
3
+ describe Card do
4
+
5
+ end
metadata CHANGED
@@ -1,24 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ninety_eight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Perlmutter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-25 00:00:00.000000000 Z
11
+ date: 2014-06-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A computer genarated version of the card game 98. Comes with an executable
14
14
  with the actual game.
15
- email: zrp200@gamil.com
15
+ email: zrp200@gmail.com
16
16
  executables:
17
17
  - ninety_eight
18
18
  extensions: []
19
- extra_rdoc_files: []
19
+ extra_rdoc_files:
20
+ - README.md
20
21
  files:
21
22
  - ".rspec"
23
+ - README.md
22
24
  - bin/ninety_eight
23
25
  - lib/ninety_eight.rb
24
26
  - spec/98spec.rb