Skip to content

Commit

Permalink
Merge branch 'abstract_battle'
Browse files Browse the repository at this point in the history
  • Loading branch information
nskins committed Nov 25, 2017
2 parents 322b60c + 92f8b22 commit 50e88f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/goby/entity/fighter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def battle(entity)
if winner.equal?(self)
handle_victory(entity)
entity.die
else
elsif winner.equal?(entity)
entity.handle_victory(self)
die
end
Expand Down
13 changes: 7 additions & 6 deletions spec/goby/entity/player_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
let!(:passable) { Tile::DEFAULT_PASSABLE }
let!(:impassable) { Tile::DEFAULT_IMPASSABLE }

let!(:dude) { Player.new(stats: {attack: 10, agility: 10000, map_hp: 2000},
let!(:dude) { Player.new(stats: {attack: 10, agility: 10000, map_hp: 2000}, gold: 10,
battle_commands: [Attack.new(strength: 20), Escape.new, Use.new],
map: map, location: center) }
let!(:slime) { Monster.new(battle_commands: [Attack.new(success_rate: 0)],
Expand Down Expand Up @@ -179,14 +179,14 @@
it "saves the information from previous maps" do
dude.move_to(C[0, 0], chest_map)
interpret_command("open", dude)
expect(dude.gold).to eq 5
expect(dude.gold).to eq 15
dude.move_to(C[1, 1], Map.new)
dude.move_to(C[0, 0], Map.new(name: "Chest Map"))
interpret_command("open", dude)
expect(dude.gold).to eq 5
expect(dude.gold).to eq 15
dude.move_right
interpret_command("open", dude)
expect(dude.gold).to eq 10
expect(dude.gold).to eq 20
end
end

Expand Down Expand Up @@ -335,6 +335,7 @@
# Could theoretically fail, but with very low probability.
__stdin("escape\nescape\nescape\n") do
dude.battle(slime)
expect(dude.gold).to eq 10
end
end

Expand All @@ -355,7 +356,7 @@
expect(newb.gold).to eq 25
expect(newb.location).to eq C[1, 1]
# Stronger Player should get weaker Players gold
expect(dude.gold).to eq (25)
expect(dude.gold).to eq (35)
end

it "should allow the stronger player to win as the defender" do
Expand All @@ -366,7 +367,7 @@
expect(newb.gold).to eq 25
expect(newb.location).to eq C[1, 1]
# Stronger Player should get weaker Players gold
expect(dude.gold).to eq (25)
expect(dude.gold).to eq (35)
end

end
Expand Down

0 comments on commit 50e88f9

Please sign in to comment.