diff --git a/spec/expansion_spec.cr b/spec/expansion_spec.cr index 090320b..c2827e0 100644 --- a/spec/expansion_spec.cr +++ b/spec/expansion_spec.cr @@ -3,9 +3,11 @@ require "./spec_helper" describe Game::Point do p1 = Game::Point.new(0, 0) p2 = Game::Point.new(5, 5) + it "can calc distance" do p1.distance(p2).should eq 10 end + it "can calc reverse destance" do p2.distance(p1).should eq 10 end diff --git a/spec/point_spec.cr b/spec/point_spec.cr new file mode 100644 index 0000000..090320b --- /dev/null +++ b/spec/point_spec.cr @@ -0,0 +1,12 @@ +require "./spec_helper" + +describe Game::Point do + p1 = Game::Point.new(0, 0) + p2 = Game::Point.new(5, 5) + it "can calc distance" do + p1.distance(p2).should eq 10 + end + it "can calc reverse destance" do + p2.distance(p1).should eq 10 + end +end diff --git a/src/game/map.cr b/src/game/map.cr index cc5c292..1d45865 100644 --- a/src/game/map.cr +++ b/src/game/map.cr @@ -1,19 +1,4 @@ module Game - struct Point - property x : Int32 - property y : Int32 - - def initialize(@x : Int32, @y : Int32) - end - - getter x - getter y - - def distance(other) : Int32 - return (other.x - @x).abs + (other.y - @y).abs - end - end - class Map alias TileRow = Array(Tile) alias DataArray = Array(TileRow) diff --git a/src/game/point.cr b/src/game/point.cr new file mode 100644 index 0000000..d5ab1db --- /dev/null +++ b/src/game/point.cr @@ -0,0 +1,14 @@ +struct Game::Point + property x : Int32 + property y : Int32 + + def initialize(@x : Int32, @y : Int32) + end + + getter x + getter y + + def distance(other) : Int32 + return (other.x - @x).abs + (other.y - @y).abs + end +end