Permalink
Browse files

adding some raw shitty tests just to exercise some of this hacked code

  • Loading branch information...
1 parent 50ae952 commit c20c9e949ca6e438975dffa384ad76731a556c85 @bgoodspeed committed Nov 5, 2010
@@ -34,8 +34,6 @@ def first_matching_tactic(foes, actor)
end
def take_battle_turn(actor, battle)
- puts "take #{actor}s battle turn in #{battle}"
-
tactic = first_matching_tactic(battle.participants, actor)
if tactic.matches?
tactic.perform
@@ -15,12 +15,14 @@ def map_to_colors(rate)
def draw(menu_layer_config, game, battle)
heroes = battle.heroes
+ hpr = heroes.collect {|h| h.hp_ratio}
+ puts "hprs: #{hpr.join(',')}"
health_rates = heroes.collect {|h| h.hp_ratio * 10}
ready_rates = heroes.collect {|h| h.ready_ratio * 10}
s = Surface.new([500, 50])
s.fill(:green)
-
+ puts "health rates: #{health_rates.join(',')}"
health_rates.each_with_index do |hr, hi|
sub = Surface.new([10, 10])
colors = map_to_colors(hr)
@@ -67,7 +67,7 @@ def battle(m)
@n2 = never
@only_jim = only(:jim)
@battle_strategy = BattleStrategy.new([@n1, @n2, @a1, @a2])
- @only_jim_strategy = BattleStrategy.new([@n1, @n2, @only_jim, @a1])
+ @only_jim_strategy = BattleStrategy.new([@n1, @n2, @only_jim])
end
it "should evaluate the tactics in order" do
@@ -84,6 +84,18 @@ def battle(m)
tactical_match.actor.should == :alice
end
+ def mock_battle_actor
+ m = mock("battle actor")
+ m
+ end
+
+ it "should do a noop if nothing matches" do
+ actor = mock_battle_actor
+ actor.should_receive(:consume_readiness)
+ @only_jim_strategy.take_battle_turn(actor, battle([:bob]))
+
+ end
+
it "should invoke the action" do
@battle_strategy.take_battle_turn(:alice, battle([:bob, :jim]))
@a1.performed.should be_true
@@ -0,0 +1,38 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+require 'spec/rspec_helper'
+
+describe BattleHud do
+ include DomainMocks
+
+ def mock_screen
+ m = mock("screen")
+ m
+ end
+ def mock_text_rendering_helper
+ m = mock("text rendering helper")
+ m
+ end
+
+ before(:each) do
+
+ @screen = Rubygame::Surface.new([100,100])
+ @battle_hud = BattleHud.new(@screen, mock_text_rendering_helper, mock_layer)
+ end
+
+ it "should map to colors" do
+ @battle_hud.map_to_colors(1).should == [:blue, :red, :red, :red, :red, :red, :red, :red, :red, :red]
+ @battle_hud.map_to_colors(5).should == [:blue, :blue, :blue, :blue, :blue, :red, :red, :red, :red, :red]
+ @battle_hud.map_to_colors(8).should == [:blue, :blue, :blue, :blue, :blue, :blue, :blue, :blue, :red, :red]
+ end
+
+ def battle
+ Battle.new(mock_game, MonsterFactory.new.make_monster(mock_player, mock_universe))
+ end
+
+ it "should be able to draw" do
+ @battle_hud.draw(nil, nil, battle)
+ end
+end
+
@@ -66,13 +66,13 @@ def selections_with_hero
it "should be able to get a name for a given path plus current cursor -- inside stat task" do
@task_menu.element_name_at([0],0,nil).should == "person a"
@task_menu.element_name_at([0],1,nil).should == "person b"
- @task_menu.element_name_at([0, 0],0,selections_with_hero).should == "HP: 0/0"
+ @task_menu.element_name_at([0, 0],0,selections_with_hero).should == "HP: 10/10"
end
it "should be able to get a list of elements for a a given path and selections" do
@task_menu.element_names_at([ ], nil).should == [@stat_action.name, @item_action.name]
@task_menu.element_names_at([0 ], nil).should == ["person a", "person b"]
- @task_menu.element_names_at([0, 0 ], selections_with_hero).should == ["HP: 0/0", "MP: 1/1", "EXP: 0", "LVP: 0"]
+ @task_menu.element_names_at([0, 0 ], selections_with_hero).should == ["HP: 10/10", "MP: 1/1", "EXP: 0", "LVP: 0"]
@task_menu.element_names_at([1, 0 ], nil).should == ["item 1"]
@task_menu.element_names_at([1, 0, 0], nil).should == ["person a", "person b"]
end
@@ -57,7 +57,10 @@ def monster(player, universe)
end
def hero(name)
- h = Hero.new(name,nil, 1, 1, CharacterAttribution.new(CharacterState.new(CharacterAttributes.new(0,1,2,3,4,5,6,7)), nil))
+ h = Hero.new(name, nil, 1, 1, CharacterAttribution.new(
+ CharacterState.new(
+ CharacterAttributes.new(10,1,2,3,4,5,6,7)
+ ), nil))
h
end
@@ -89,7 +92,7 @@ def mock_game
def mock_party
m = mock("party")
- m.stub!(:members).and_return [named_mock("ALPHA"), named_mock("BETA")]
+ m.stub!(:members).and_return [hero("ALPHA"), hero("BETA")]
m
end

0 comments on commit c20c9e9

Please sign in to comment.