Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Needed Level#play to return a boolean #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/ruby_warrior/level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,21 @@ def generate_player_files
def play(turns = 1000)
load_level
turns.times do |n|
return if passed? || failed?
if passed?
return true
elsif failed?
return false
end

UI.puts "- turn #{n+1} -"
UI.print @floor.character
@floor.units.each { |unit| unit.prepare_turn }
@floor.units.each { |unit| unit.perform_turn }
yield if block_given?
@time_bonus -= 1 if @time_bonus > 0
end

return false
end

def tally_points
Expand Down
10 changes: 10 additions & 0 deletions spec/ruby_warrior/level_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@
@level.stubs(:passed?).returns(true)
@level.play(2)
end

it "should return true if the level is passed" do
@level.stubs(:passed?).returns(true)
@level.play(2).should be_true
end

it "should return false if the level is not passed" do
@level.stubs(:failed?).returns(true)
@level.play(2).should be_false
end

it "should yield to block in play method for each turn" do
int = 0
Expand Down