lib/warcards/gameplay.rb in warcards-0.0.3 vs lib/warcards/gameplay.rb in warcards-0.0.5

- old
+ new

@@ -1,9 +1,10 @@ require_relative 'deck' require_relative 'card' require_relative 'ai' require_relative 'player' +require 'ostruct' module Cardgame class Gameplay def initialize(args) @deck = args[:deck] @@ -22,20 +23,22 @@ deck.length.even? ? @player.stack << @deck.pop : @ai.stack << @deck.pop end end def game_over? - [@ai, @player].each_with_index do |participant, index| + end_game = Hash.new + participants = [@player, @ai] + participants.each_with_index do |participant, index| if (participant.stack.length + participant.discard.length) < 1 - participants = [@ai, @player] participants.delete_at index - puts "Game over #{participants.first.name} won!" - exit + end_game[:winner] = participants.first.name + end_game[:over?] = TRUE else - next + end_game[:over?] = FALSE end end + end_game end def rearm? [@ai, @player].each do |participant| if participant.stack.length < 1 @@ -56,14 +59,14 @@ end { :winner => winner, :player_cards => @player_cards, :ai_cards => @ai_cards } end - def war? + def war?(output = STDOUT) while @ai_cards.last.value == @player_cards.last.value rearm? - #TODO make the folling line a flag or something so the view code can decide to show it or not. - puts "WAR!!!" + #TODO make the following line a flag or something so the view code can decide to show it or not. + output.puts "WAR!!!" show_cards end end def show_cards \ No newline at end of file