warcards 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  .idea/
2
2
  .bundle/
3
+ coverage
3
4
 
4
5
  # Compiled source #
5
6
  ###################
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- warcards (0.0.3)
4
+ warcards (0.0.5)
5
5
  bundler (~> 1.1)
6
6
  querinator
7
7
  rake (~> 0.9.2)
@@ -25,6 +25,9 @@ GEM
25
25
  rb-fsevent (~> 0.9.1)
26
26
  rb-inotify (~> 0.8.8)
27
27
  minitest (3.3.0)
28
+ minitest-growl (0.0.3)
29
+ growl
30
+ minitest
28
31
  minitest-reporters (0.9.0)
29
32
  ansi
30
33
  builder
@@ -32,6 +35,7 @@ GEM
32
35
  powerbar
33
36
  minitest-spec (0.0.2.1)
34
37
  minitest (>= 3.0)
38
+ multi_json (1.3.6)
35
39
  powerbar (1.0.8)
36
40
  ansi (~> 1.4.0)
37
41
  hashie (>= 1.1.0)
@@ -43,6 +47,10 @@ GEM
43
47
  rb-fsevent (0.9.1)
44
48
  rb-inotify (0.8.8)
45
49
  ffi (>= 0.5.0)
50
+ simplecov (0.6.4)
51
+ multi_json (~> 1.0)
52
+ simplecov-html (~> 0.5.3)
53
+ simplecov-html (0.5.3)
46
54
  thor (0.15.4)
47
55
  turn (0.9.6)
48
56
  ansi
@@ -55,8 +63,10 @@ DEPENDENCIES
55
63
  growl (~> 1.0.3)
56
64
  guard (~> 1.2.3)
57
65
  guard-minitest (~> 0.5.0)
66
+ minitest-growl
58
67
  minitest-reporters (~> 0.9.0)
59
68
  minitest-spec (~> 0.0.2)
60
69
  rb-fsevent (~> 0.9.1)
70
+ simplecov (~> 0.6)
61
71
  turn (~> 0.9.6)
62
72
  warcards!
@@ -4,51 +4,22 @@ require 'querinator'
4
4
  module Cardgame
5
5
  class Game
6
6
  def initialize
7
- @deck = Deck.new
8
- @player = Player.new
9
- @ai = Ai.new
10
- @gameplay = Gameplay.new(:deck => @deck, :player => @player, :ai => @ai)
7
+ @deck = Deck.new
8
+ @player = Player.new
9
+ @ai = Ai.new
10
+ @gameplay = gameplay(:deck => @deck, :player => @player, :ai => @ai)
11
11
  @gameplay.shuffle
12
12
  @gameplay.deal
13
13
  @output = Struct.new(:winner, :player_feedback, :ai_feedback, :posed)
14
-
14
+ @slow = TRUE
15
15
  end
16
16
 
17
- ##def output
18
- ## @output
19
- ##end
20
- ##
21
- ##def rearm?
22
- ## @gameplay.rearm?
23
- ##end
24
- ##
25
- ##def show_cards
26
- ## @gameplay.show_cards
27
- ##end
28
- ##
29
- ##def war?
30
- ## @gameplay.contest
31
- ##end
32
- ##
33
- ##def contest
34
- ## @gameplay.contest
35
- ##end
36
- ##
37
- ##def discard(result)
38
- ## @gameplay.discard(result)
39
- ##end
40
- ##
41
- ##def game_over?
42
- ## @gameplay.game_over?
43
- ##end
44
- #
45
- #def player
46
- # @player
47
- #end
48
- #
49
- #def ai
50
- # @ai
51
- #end
17
+ def gameplay(args)
18
+ deck = args[:deck]
19
+ player = args[:player]
20
+ ai = args[:ai]
21
+ Gameplay.new(:deck => deck, :player => player, :ai => ai)
22
+ end
52
23
 
53
24
  def run
54
25
  filename = get_filename
@@ -57,87 +28,120 @@ module Cardgame
57
28
  end
58
29
  @questions = Querinator::Game.new.get_questions(filename)
59
30
  loop do
60
- @gameplay.game_over?
61
- @gameplay.rearm?
62
- @gameplay.show_cards
63
- @gameplay.war?
64
- result = @gameplay.contest
65
-
66
- output_cli(result)
67
-
68
- continue?
69
- @gameplay.discard(result)
31
+ begin
32
+ end_game = @gameplay.game_over?
33
+
34
+ if end_game[:over?]
35
+ puts "Game over #{end_game[:winner]} won!"
36
+ exit
37
+ else
38
+ @gameplay.rearm?
39
+ @gameplay.show_cards
40
+ @gameplay.war?
41
+ result = @gameplay.contest
42
+ output_cli(result)
43
+ challenge_participants(result)
44
+ #continue?
45
+ @gameplay.discard(result)
46
+ end
47
+ rescue SignalException => e
48
+ puts "\n\nThanks for playing!"
49
+ exit(status=1)
50
+ end
70
51
  end
71
52
  end
72
53
 
73
- def get_filename
74
- puts "What question file?\nfilename: "
75
- filename = gets.chomp
76
- file = File.expand_path(filename)
77
- p file
78
- file
54
+ def get_filename(input = STDIN, output = STDOUT)
55
+ output.puts(Dir.glob "**/*.txt")
56
+ sample_questions = "spec/test_question_file.txt"
57
+ output.puts "What question file?\n(Just hit enter to use the sample questions.)\nfilename: "
58
+ filename = input.gets.chomp
59
+ if File.file?(File.expand_path(filename))
60
+ File.expand_path(filename)
61
+ else
62
+ sample_questions
63
+ end
79
64
  end
80
65
 
81
- def continue?
82
- puts "go again?\n"
83
- next_round = gets
84
- if next_round.downcase.chomp.include? "n"
85
- puts "You ended the game"
86
- exit
87
- end
66
+ #def continue?(input = STDIN, output = STDOUT, really_end = :yes)
67
+ # output.puts("go again?\n")
68
+ # next_round = input.gets
69
+ # if next_round.downcase.chomp.include? "n"
70
+ # output.puts "You ended the game"
71
+ # if really_end == :yes
72
+ # exit
73
+ # end
74
+ # end
75
+ #end
76
+
77
+ def output_cli(result, output = STDOUT)
78
+ graph = build_graph(player_holdings, ai_holdings)
79
+ output.puts "\n#{result[:winner].name} has the high card."
80
+ output.puts "Player has #{player_holdings} cards.\tAI has #{ai_holdings} cards."
81
+ output.puts graph
82
+ #challenge_participants(result)
83
+ # TODO get challenge_participants out of here. No longer belongs. Causing hard tests.
88
84
  end
89
85
 
90
- def output_cli(result)
91
- puts "#{result[:winner].name} won"
92
- puts "Player has #{player_holdings} cards.\tAI has #{ai_holdings} cards."
93
- challenge_participants(result)
86
+ def build_graph(player_holdings, ai_holdings)
87
+ graph = ""
88
+ player_holdings.times { graph << "p" }
89
+ graph << "|"
90
+ ai_holdings.times { graph << "a" }
91
+ graph
94
92
  end
95
93
 
96
94
  def player_holdings
95
+ # When this is run there is one card from each participant in play.
96
+ # That is what the +1 compensates for and why the test looks wack.
97
97
  (@gameplay.player.stack.length + @gameplay.player.discard.length + 1)
98
98
  end
99
99
 
100
100
  def ai_holdings
101
- @gameplay.ai.stack.length + @gameplay.ai.discard.length + 1
101
+ # When this is run there is one card from each participant in play.
102
+ # That is what the +1 compensates for and why the test looks wack.
103
+ (@gameplay.ai.stack.length + @gameplay.ai.discard.length + 1)
102
104
  end
103
105
 
104
- def challenge_participants(result)
105
- if result[:winner] == @gameplay.player
106
- challenge_player(result)
106
+ def challenge_participants(result, question = @questions.sample, input = STDIN, output = STDOUT, rnd_src = rand)
107
+ if result[:winner].class == Player
108
+ challenge_player(result, question, input, output)
107
109
  else
108
- challenge_ai(result)
110
+ challenge_ai(result, output, rnd_src)
109
111
  end
110
112
  end
111
113
 
112
- def challenge_ai(result)
113
- if test_ai
114
- puts "Ai was correct."
114
+ def challenge_ai(result, output = STDOUT, rnd_src = rand)
115
+ if test_ai(rnd_src)
116
+ output.puts "Ai was correct. Ai wins the round."
115
117
  else
116
- puts "Ai was wrong. #{@gameplay.player.name} became the winner!"
118
+ output.puts "Ai was wrong. #{@gameplay.player.name} became the winner!"
117
119
  result[:winner] = @gameplay.player
120
+ if @slow
121
+ sleep 0.75
122
+ end
118
123
  end
119
124
  end
120
125
 
121
- def challenge_player(result)
122
- if test_player
123
- puts "Correct! Yay!"
126
+ def challenge_player(result, question = @questions.sample, input = STDIN, output = STDOUT)
127
+ #question = @questions.sample
128
+ if test_player(question, input, output)
129
+ output.puts "Correct! Yay!"
124
130
  else
125
- puts "Oooh. I'm sorry. The correct answer was 'TODO'. #{@gameplay.ai.name} became the winner."
131
+ output.puts %Q{Oooh. I'm sorry. The correct answer was "#{question.answer}". #{@gameplay.ai.name} became the winner.}
126
132
  result[:winner] = @gameplay.ai
127
133
  end
134
+ #continue?(input, output)
128
135
  end
129
136
 
130
-
131
- def test_player
132
- question = @questions.sample
133
- puts question.pose
134
- answer = gets
137
+ def test_player(question, input = STDIN, output = STDOUT)
138
+ output.puts question.pose
139
+ answer = input.gets
135
140
  question.is_correct?(answer.chomp)
136
141
  end
137
142
 
138
- def test_ai(difficulty)
139
- difficulty ||= 0.4
140
- @ai.difficulty_check?(rand, difficulty)
143
+ def test_ai(rand_src = rand, difficulty = 0.4)
144
+ @ai.difficulty_check?(rand_src, difficulty)
141
145
  end
142
146
 
143
147
  end
@@ -5,8 +5,6 @@ module Cardgame
5
5
  @discard = Array.new
6
6
  #attr_accessor :name
7
7
  @ai_name = "H.E.L.P.E.R."
8
- # Set the game difficulty manually for now. Pick a number < 1. Higher is harder. TODO: make this a switch
9
-
10
8
  end
11
9
 
12
10
  def stack
@@ -0,0 +1,43 @@
1
+ #module Cardgame
2
+ =begin
3
+ def challenge_participants(result)
4
+ if result[:winner] == @gameplay.player
5
+ challenge_player(result)
6
+ else
7
+ challenge_ai(result)
8
+ end
9
+ end
10
+
11
+ def challenge_ai(result)
12
+ if test_ai
13
+ puts "Ai was correct."
14
+ else
15
+ puts "Ai was wrong. #{@gameplay.player.name} became the winner!"
16
+ result[:winner] = @gameplay.player
17
+ end
18
+ end
19
+
20
+ def challenge_player(result)
21
+ if test_player
22
+ puts "Correct! Yay!"
23
+ else
24
+ puts "Oooh. I'm sorry. The correct answer was 'TODO'. #{@gameplay.ai.name} became the winner."
25
+ result[:winner] = @gameplay.ai
26
+ end
27
+ end
28
+
29
+
30
+ def test_player
31
+ question = @questions.sample
32
+ puts question.pose
33
+ answer = gets
34
+ question.is_correct?(answer.chomp)
35
+ end
36
+
37
+ def test_ai(difficulty)
38
+ difficulty ||= 0.4
39
+ @ai.difficulty_check?(rand, difficulty)
40
+ end
41
+
42
+ end
43
+ =end
@@ -2,6 +2,7 @@ require_relative 'deck'
2
2
  require_relative 'card'
3
3
  require_relative 'ai'
4
4
  require_relative 'player'
5
+ require 'ostruct'
5
6
 
6
7
  module Cardgame
7
8
  class Gameplay
@@ -24,16 +25,18 @@ module Cardgame
24
25
  end
25
26
 
26
27
  def game_over?
27
- [@ai, @player].each_with_index do |participant, index|
28
+ end_game = Hash.new
29
+ participants = [@player, @ai]
30
+ participants.each_with_index do |participant, index|
28
31
  if (participant.stack.length + participant.discard.length) < 1
29
- participants = [@ai, @player]
30
32
  participants.delete_at index
31
- puts "Game over #{participants.first.name} won!"
32
- exit
33
+ end_game[:winner] = participants.first.name
34
+ end_game[:over?] = TRUE
33
35
  else
34
- next
36
+ end_game[:over?] = FALSE
35
37
  end
36
38
  end
39
+ end_game
37
40
  end
38
41
 
39
42
  def rearm?
@@ -58,11 +61,11 @@ module Cardgame
58
61
  { :winner => winner, :player_cards => @player_cards, :ai_cards => @ai_cards }
59
62
  end
60
63
 
61
- def war?
64
+ def war?(output = STDOUT)
62
65
  while @ai_cards.last.value == @player_cards.last.value
63
66
  rearm?
64
- #TODO make the folling line a flag or something so the view code can decide to show it or not.
65
- puts "WAR!!!"
67
+ #TODO make the following line a flag or something so the view code can decide to show it or not.
68
+ output.puts "WAR!!!"
66
69
  show_cards
67
70
  end
68
71
  end
@@ -1,5 +1,5 @@
1
1
  module Cardgame
2
2
 
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.5"
4
4
 
5
5
  end
@@ -1,6 +1,10 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  require 'minitest/spec'
2
5
  require "minitest/autorun"
3
6
  require 'minitest/reporters'
7
+ require 'minitest/growl_notify'
4
8
  require 'turn'
5
9
  require 'growl'
6
10
 
@@ -3,9 +3,9 @@ require_relative '../spec_helper'
3
3
  module Cardgame
4
4
  describe Gameplay do
5
5
  def setup
6
- @deck = Deck.new
7
- @player = Player.new
8
- @ai = Ai.new
6
+ @deck = Deck.new
7
+ @player = Player.new
8
+ @ai = Ai.new
9
9
  @gameplay = Gameplay.new(:deck => @deck, :player => @player, :ai => @ai)
10
10
  end
11
11
 
@@ -35,9 +35,9 @@ module Cardgame
35
35
 
36
36
  describe "dealt deck" do
37
37
  def setup
38
- @deck = Deck.new
39
- player = Player.new
40
- ai = Ai.new
38
+ @deck = Deck.new
39
+ player = Player.new
40
+ ai = Ai.new
41
41
  @gameplay = Gameplay.new(:deck => @deck, :player => player, :ai => ai)
42
42
  @gameplay.shuffle
43
43
  @gameplay.deal
@@ -102,9 +102,10 @@ module Cardgame
102
102
 
103
103
  describe "#war" do
104
104
  it "must play war when there is a draw" do
105
- card_ai_1 = (Card.new(:suit => :clubs, :value => 5))
106
- card_ai_2 = (Card.new(:suit => :spades, :value => 4))
107
- card_ai_3 = (Card.new(:suit => :clubs, :value => 4))
105
+ output = StringIO.new("")
106
+ card_ai_1 = (Card.new(:suit => :clubs, :value => 5))
107
+ card_ai_2 = (Card.new(:suit => :spades, :value => 4))
108
+ card_ai_3 = (Card.new(:suit => :clubs, :value => 4))
108
109
  card_player_1 = (Card.new(:suit => :hearts, :value => 4))
109
110
  card_player_2 = (Card.new(:suit => :diamonds, :value => 4))
110
111
  card_player_3 = (Card.new(:suit => :hearts, :value => 4))
@@ -116,7 +117,7 @@ module Cardgame
116
117
  @gameplay.player.stack << card_player_3
117
118
 
118
119
  @gameplay.show_cards
119
- @gameplay.war?
120
+ @gameplay.war?(output)
120
121
  result = @gameplay.contest
121
122
 
122
123
  result[:ai_cards].must_be_instance_of Array
@@ -160,9 +161,9 @@ module Cardgame
160
161
 
161
162
  describe "#game_over?" do
162
163
  def setup
163
- @deck = Deck.new
164
- player = Player.new
165
- ai = Ai.new
164
+ @deck = Deck.new
165
+ player = Player.new
166
+ ai = Ai.new
166
167
  @gameplay = Gameplay.new(:deck => @deck, :player => player, :ai => ai)
167
168
  @gameplay.ai.stack.clear << (Card.new(:suit => :clubs, :value => 2))
168
169
  @gameplay.ai.stack << (Card.new(:suit => :hearts, :value => 1))
@@ -171,15 +172,15 @@ module Cardgame
171
172
  end
172
173
 
173
174
  it "must end the game when a participant is out of cards" do
174
- skip "you'll need to mock stdout and stderr first. Of course you'll have to learn how before doing that."
175
175
  2.times do
176
+ @gameplay.game_over?
176
177
  @gameplay.show_cards
177
178
  @gameplay.discard(@gameplay.contest)
178
179
  end
179
- lambda do
180
- @gameplay.game_over?
181
- end.must_output(STDOUT, STDERR) {"Game Over"; exit}
180
+ @gameplay.game_over?
181
+ @gameplay.game_over?[:over?].must_equal true
182
182
  end
183
183
  end
184
+
184
185
  end
185
186
  end
@@ -24,10 +24,241 @@ module Cardgame
24
24
  end
25
25
  end
26
26
  game = Game.new
27
- 50.times do
27
+ 5.times do
28
28
  game.excercise
29
29
  game.sum_cards.must_equal 52
30
30
  end
31
31
  end
32
+
33
+
34
+ describe "#player_holdings" do
35
+ def setup
36
+ @game = Game.new
37
+ end
38
+
39
+ it "shows how many cards the player has between stack and discard" do
40
+ @game.player_holdings.must_equal 27
41
+ end
42
+ end
43
+
44
+ describe "#ai_holdings" do
45
+ def setup
46
+ @game = Game.new
47
+ end
48
+
49
+ it "shows how many cards the AI has between the stack and discard" do
50
+ @game.ai_holdings.must_equal 27
51
+ end
52
+ end
53
+
54
+ #describe "#continue?" do
55
+ # def setup
56
+ # @game = Game.new
57
+ # end
58
+ #
59
+ # it "asks if I want to continue" do
60
+ # input = StringIO.new("\n")
61
+ # output = StringIO.new("")
62
+ # @game.continue?(input, output)
63
+ # output.string.must_equal "go again?\n"
64
+ # end
65
+ #
66
+ # it "tells me I ended the game if I say 'n'" do
67
+ # input = StringIO.new("n")
68
+ # output = StringIO.new("")
69
+ # @game.continue?(input, output, :no)
70
+ # output.string.must_match /.*You ended the game.*/
71
+ # end
72
+ #end
73
+
74
+ describe "#output_cli" do
75
+ def setup
76
+ @game = Game.new
77
+ @gameplay = @game.gameplay(deck: Deck.new, player: Player.new, ai: Ai.new)
78
+ @gameplay.ai_cards.clear << (Card.new(:suit => :clubs, :value => 2))
79
+ @gameplay.player_cards.clear << (Card.new(:suit => :clubs, :value => 13))
80
+ @result = @gameplay.contest
81
+ @output = StringIO.new("")
82
+ end
83
+
84
+ it "displays the comparison winner" do
85
+ @game.output_cli(@result, @output)
86
+ @output.string.must_match /^Player has the high card\./
87
+ end
88
+
89
+ it "displays the number of cards each participant has" do
90
+ @game.output_cli(@result, @output)
91
+ @output.string.must_match /Player has 27 cards.*AI has 27 cards/
92
+ end
93
+
94
+ it "shows a graph representation of the deck" do
95
+ @game.output_cli(@result, @output)
96
+ @output.string.must_match /pppppppppppppppppppppppppp|aaaaaaaaaaaaaaaaaaaaaaaaaa/
97
+ end
98
+ end
99
+
100
+ describe "#build_graph" do
101
+ def setup
102
+ @game = Game.new
103
+ @gameplay = @game.gameplay(deck: Deck.new, player: Player.new, ai: Ai.new)
104
+ @gameplay.ai_cards.clear << (Card.new(:suit => :clubs, :value => 2))
105
+ @gameplay.player_cards.clear << (Card.new(:suit => :clubs, :value => 13))
106
+ @result = @gameplay.contest
107
+ @output = StringIO.new("")
108
+ end
109
+
110
+ it "shows a graph representation of the deck" do
111
+ res = @game.build_graph((@game.player_holdings - 1), (@game.ai_holdings - 1))
112
+ res.must_equal "pppppppppppppppppppppppppp|aaaaaaaaaaaaaaaaaaaaaaaaaa"
113
+ end
114
+ end
115
+
116
+ describe "#test_ai" do
117
+ def setup
118
+ @game = Game.new
119
+ end
120
+
121
+ it "is true if difficulty is lower than random" do
122
+ @game.test_ai(0.1).must_equal TRUE
123
+ end
124
+
125
+ it "if false if difficulty is higher than random" do
126
+ @game.test_ai(0.3, 0.2).must_equal FALSE
127
+ end
128
+ end
129
+
130
+ describe "#test_player" do
131
+ def setup
132
+ @questions = Querinator::Game.new.get_questions("spec/test_question_file.txt")
133
+ @input = StringIO.new("\n")
134
+ @output = StringIO.new("")
135
+ @game = Game.new
136
+ end
137
+
138
+ it "asks the player a question" do
139
+ @game.test_player(@questions.first, @input, @output)
140
+ @output.string.must_equal "Do you get Tom Servo?\n"
141
+ end
142
+
143
+ it "tells me the given answer is incorrect" do
144
+ input = StringIO.new("no I do not")
145
+ @game.test_player(@questions.first, input, @output).must_equal FALSE
146
+ end
147
+
148
+ it "tells me the given answer is correct" do
149
+ input = StringIO.new("Nobody does. I'm the wind baby.")
150
+ @game.test_player(@questions.first, input, @output).must_equal TRUE
151
+ end
152
+ end
153
+
154
+ describe "#challenge_player" do
155
+ def setup
156
+ @game = Game.new
157
+ @questions = Querinator::Game.new.get_questions("spec/test_question_file.txt")
158
+ @gameplay = @game.gameplay(deck: Deck.new, player: Player.new, ai: Ai.new)
159
+ @gameplay.ai_cards.clear << (Card.new(:suit => :clubs, :value => 2))
160
+ @gameplay.player_cards.clear << (Card.new(:suit => :clubs, :value => 13))
161
+ @result = @gameplay.contest
162
+ @output = StringIO.new("")
163
+ end
164
+
165
+ it "congratulates me when I get it correct" do
166
+ input = StringIO.new("Nobody does. I'm the wind baby.\n")
167
+ @game.challenge_player(@result, @questions.first, input, @output)
168
+ @output.string.split("\n").last.must_equal "Correct! Yay!"
169
+ end
170
+
171
+ it "consoles me when I get it wrong" do
172
+ input = StringIO.new("Who's Tom Servo?\n")
173
+ @game.challenge_player(@result, @questions.first, input, @output)
174
+ @output.string.split("\n").last.must_match /^Oooh\. I'm sorry/
175
+ end
176
+
177
+ #it "asks me if I want to continue" do
178
+ # input = StringIO.new("Who's Tom Servo?\n\n")
179
+ # @game.challenge_player(@result, @questions.first, input, @output)
180
+ # @output.string.split("\n").last.must_match /go again\?/
181
+ #end
182
+ end
183
+
184
+ describe "#challenge_ai" do
185
+ def setup
186
+ @game = Game.new
187
+ @gameplay = @game.gameplay(deck: Deck.new, player: Player.new, ai: Ai.new)
188
+ @gameplay.ai_cards.clear << (Card.new(:suit => :clubs, :value => 12))
189
+ @gameplay.player_cards.clear << (Card.new(:suit => :clubs, :value => 3))
190
+ @result = @gameplay.contest
191
+ @output = StringIO.new("")
192
+ end
193
+
194
+ it "tells me the ai lost" do
195
+ @game.challenge_ai(@result, @output, 0.9)
196
+ @output.string.must_equal "Ai was wrong. Player became the winner!\n"
197
+ end
198
+
199
+ it "tells me the ai won" do
200
+ @game.challenge_ai(@result, @output, 0.1)
201
+ @output.string.must_equal "Ai was correct. Ai wins the round.\n"
202
+ end
203
+ end
204
+
205
+ def challenge_partic_setup(args)
206
+ @game = Game.new
207
+ @questions = Querinator::Game.new.get_questions("spec/test_question_file.txt")
208
+ @gameplay = @game.gameplay(deck: Deck.new, player: Player.new, ai: Ai.new)
209
+ @gameplay.ai_cards.clear << (args[:ai_card])
210
+ @gameplay.player_cards.clear << (args[:player_card])
211
+ @result = @gameplay.contest
212
+ @output = StringIO.new("")
213
+ @input = StringIO.new("incorrect answer\n")
214
+ end
215
+
216
+ describe "#challenge_participants player" do
217
+ def setup
218
+ challenge_partic_setup(:ai_card => Card.new(:suit => :clubs, :value => 2), :player_card => Card.new(:suit => :clubs, :value => 11))
219
+ end
220
+
221
+ it "calls #challenge_player if player has high card" do
222
+ @game.challenge_participants(@result, @questions.first, @input, @output, 0.1)
223
+ @output.string.must_match /#{@questions.first.pose}/
224
+ end
225
+ end
226
+
227
+ describe "#challenge_participants ai" do
228
+ def setup
229
+ challenge_partic_setup(:ai_card => Card.new(:suit => :clubs, :value => 12), :player_card => Card.new(:suit => :clubs, :value => 1))
230
+ end
231
+
232
+ it "calls #challenge_ai if ai has high card" do
233
+ result = @gameplay.contest
234
+ @game.challenge_participants(result, @questions.first, @input, @output, 0.1)
235
+ @output.string.must_match /Ai was correct\. Ai wins the round\.\n/
236
+ end
237
+ end
238
+
239
+ describe "#get_filename" do
240
+ def setup
241
+ @output = StringIO.new("")
242
+ @input = StringIO.new("incorrect answer\n")
243
+ @game = Game.new
244
+ end
245
+
246
+ it "displays the path of the sample question file" do
247
+ @game.get_filename(@input, @output)
248
+ @output.string.must_match "spec/test_question_file.txt"
249
+ end
250
+
251
+ it "returns an absolute path if a path is passed in" do
252
+ input = StringIO.new("~/.bash_history\n")
253
+ @game.get_filename(input, @output).must_match ".bash_history"
254
+ end
255
+
256
+ it "returns the path to the sample question if the user hits enter" do
257
+ input = StringIO.new("\n")
258
+ @game.get_filename(input, @output).must_equal "spec/test_question_file.txt"
259
+ end
260
+ end
32
261
  end
262
+
263
+
33
264
  end
@@ -19,10 +19,12 @@ Gem::Specification.new do |gem|
19
19
  gem.add_development_dependency 'rb-fsevent', '~>0.9.1'
20
20
  gem.add_development_dependency 'minitest-spec', '~>0.0.2'
21
21
  gem.add_development_dependency 'minitest-reporters', '~>0.9.0'
22
+ gem.add_development_dependency 'minitest-growl'
22
23
  gem.add_development_dependency 'guard', '~>1.2.3'
23
24
  gem.add_development_dependency 'guard-minitest', '~>0.5.0'
24
25
  gem.add_development_dependency 'growl', '~>1.0.3'
25
26
  gem.add_development_dependency 'turn', '~>0.9.6'
27
+ gem.add_development_dependency 'simplecov', '~>0.6'
26
28
 
27
29
  # specify run dependencies here
28
30
  gem.add_dependency 'bundler', "~>1.1"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warcards
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-11 00:00:00.000000000 Z
12
+ date: 2012-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rb-fsevent
16
- requirement: &70233000726620 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 0.9.1
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70233000726620
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.1
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: minitest-spec
27
- requirement: &70233000724600 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 0.0.2
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70233000724600
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.0.2
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: minitest-reporters
38
- requirement: &70233000720920 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,31 @@ dependencies:
43
53
  version: 0.9.0
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70233000720920
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest-growl
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
47
78
  - !ruby/object:Gem::Dependency
48
79
  name: guard
49
- requirement: &70233000719520 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
50
81
  none: false
51
82
  requirements:
52
83
  - - ~>
@@ -54,10 +85,15 @@ dependencies:
54
85
  version: 1.2.3
55
86
  type: :development
56
87
  prerelease: false
57
- version_requirements: *70233000719520
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.2.3
58
94
  - !ruby/object:Gem::Dependency
59
95
  name: guard-minitest
60
- requirement: &70233000716640 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
61
97
  none: false
62
98
  requirements:
63
99
  - - ~>
@@ -65,10 +101,15 @@ dependencies:
65
101
  version: 0.5.0
66
102
  type: :development
67
103
  prerelease: false
68
- version_requirements: *70233000716640
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.5.0
69
110
  - !ruby/object:Gem::Dependency
70
111
  name: growl
71
- requirement: &70233000716040 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
72
113
  none: false
73
114
  requirements:
74
115
  - - ~>
@@ -76,10 +117,15 @@ dependencies:
76
117
  version: 1.0.3
77
118
  type: :development
78
119
  prerelease: false
79
- version_requirements: *70233000716040
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.0.3
80
126
  - !ruby/object:Gem::Dependency
81
127
  name: turn
82
- requirement: &70233000715340 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
83
129
  none: false
84
130
  requirements:
85
131
  - - ~>
@@ -87,10 +133,31 @@ dependencies:
87
133
  version: 0.9.6
88
134
  type: :development
89
135
  prerelease: false
90
- version_requirements: *70233000715340
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 0.9.6
142
+ - !ruby/object:Gem::Dependency
143
+ name: simplecov
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: '0.6'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: '0.6'
91
158
  - !ruby/object:Gem::Dependency
92
159
  name: bundler
93
- requirement: &70233000713160 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
94
161
  none: false
95
162
  requirements:
96
163
  - - ~>
@@ -98,10 +165,15 @@ dependencies:
98
165
  version: '1.1'
99
166
  type: :runtime
100
167
  prerelease: false
101
- version_requirements: *70233000713160
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: '1.1'
102
174
  - !ruby/object:Gem::Dependency
103
175
  name: querinator
104
- requirement: &70233000711940 !ruby/object:Gem::Requirement
176
+ requirement: !ruby/object:Gem::Requirement
105
177
  none: false
106
178
  requirements:
107
179
  - - ! '>='
@@ -109,10 +181,15 @@ dependencies:
109
181
  version: '0'
110
182
  type: :runtime
111
183
  prerelease: false
112
- version_requirements: *70233000711940
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
113
190
  - !ruby/object:Gem::Dependency
114
191
  name: rake
115
- requirement: &70233000709640 !ruby/object:Gem::Requirement
192
+ requirement: !ruby/object:Gem::Requirement
116
193
  none: false
117
194
  requirements:
118
195
  - - ~>
@@ -120,7 +197,12 @@ dependencies:
120
197
  version: 0.9.2
121
198
  type: :runtime
122
199
  prerelease: false
123
- version_requirements: *70233000709640
200
+ version_requirements: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ~>
204
+ - !ruby/object:Gem::Version
205
+ version: 0.9.2
124
206
  description: An addictive game of War! to help slog through flash-card memorization
125
207
  email:
126
208
  - robie1373@gmail.com
@@ -142,6 +224,7 @@ files:
142
224
  - lib/warcards.rb
143
225
  - lib/warcards/ai.rb
144
226
  - lib/warcards/card.rb
227
+ - lib/warcards/cardgame.rb
145
228
  - lib/warcards/deck.rb
146
229
  - lib/warcards/gameplay.rb
147
230
  - lib/warcards/player.rb
@@ -168,15 +251,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
251
  - - ! '>='
169
252
  - !ruby/object:Gem::Version
170
253
  version: '0'
254
+ segments:
255
+ - 0
256
+ hash: -569622757642697416
171
257
  required_rubygems_version: !ruby/object:Gem::Requirement
172
258
  none: false
173
259
  requirements:
174
260
  - - ! '>='
175
261
  - !ruby/object:Gem::Version
176
262
  version: '0'
263
+ segments:
264
+ - 0
265
+ hash: -569622757642697416
177
266
  requirements: []
178
267
  rubyforge_project:
179
- rubygems_version: 1.8.10
268
+ rubygems_version: 1.8.24
180
269
  signing_key:
181
270
  specification_version: 3
182
271
  summary: Play a game of War! against the computer. If your card is higher, you get