Move point tests
This commit is contained in:
parent
0aaab2e131
commit
bccff5461d
@ -3,9 +3,11 @@ require "./spec_helper"
|
|||||||
describe Game::Point do
|
describe Game::Point do
|
||||||
p1 = Game::Point.new(0, 0)
|
p1 = Game::Point.new(0, 0)
|
||||||
p2 = Game::Point.new(5, 5)
|
p2 = Game::Point.new(5, 5)
|
||||||
|
|
||||||
it "can calc distance" do
|
it "can calc distance" do
|
||||||
p1.distance(p2).should eq 10
|
p1.distance(p2).should eq 10
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can calc reverse destance" do
|
it "can calc reverse destance" do
|
||||||
p2.distance(p1).should eq 10
|
p2.distance(p1).should eq 10
|
||||||
end
|
end
|
||||||
|
12
spec/point_spec.cr
Normal file
12
spec/point_spec.cr
Normal file
@ -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
|
@ -1,19 +1,4 @@
|
|||||||
module Game
|
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
|
class Map
|
||||||
alias TileRow = Array(Tile)
|
alias TileRow = Array(Tile)
|
||||||
alias DataArray = Array(TileRow)
|
alias DataArray = Array(TileRow)
|
||||||
|
14
src/game/point.cr
Normal file
14
src/game/point.cr
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user