First test

This commit is contained in:
Anton Vakhrushev 2019-09-16 17:27:28 +03:00
parent 694167c646
commit 1bec9b987c
5 changed files with 25 additions and 21 deletions

View File

@ -8,8 +8,8 @@ format:
./cr tool format ./src ./spec
.PHONY: spec
spec:
./cr spec --warnings all --error-on-warnings
spec: format
./cr spec --warnings all --error-on-warnings --time
.PHONY: release
release:

View File

@ -1,5 +1,13 @@
require "./spec_helper"
require "spec"
require "./../src/map"
describe Village do
# TODO: Write tests
describe Point do
p1 = Point.new(0, 0)
p2 = 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

View File

@ -25,6 +25,7 @@ end
class GetWoodCommand < Command
BASE_TIME = 10
BASE_WOOD = 80
REST_TIME = 5
def initialize(@point : Point)
@wood = 0
@ -36,7 +37,7 @@ class GetWoodCommand < Command
calc_time(wood_tile.as(Tile))
else
printf " << no wood tile\n"
BASE_TIME
REST_TIME
end
end
@ -86,6 +87,7 @@ end
class GrowWoodCommand < Command
BASE_TIME = 15
BASE_WOOD = 30
REST_TIME = 5
@wood_tile : Tile | Nil
@ -99,8 +101,7 @@ class GrowWoodCommand < Command
calc_time(@wood_tile.as(Tile))
else
printf " >> no wood tile\n"
@wood = 0
BASE_TIME
REST_TIME
end
end

View File

@ -1,17 +1,15 @@
struct Point
property x : Int32
property y : Int32
def initialize(@x : Int32, @y : Int32)
end
def x
@x
end
getter x
getter y
def y
@y
end
def distance(p : Point) : Int32
return (p.x - @x).abs + (p.y - @y).abs
def distance(other) : Int32
return (other.x - @x).abs + (other.y - @y).abs
end
end

View File

@ -4,8 +4,7 @@ require "./map"
require "./queue"
class Resources
def initialize
@wood = 0
def initialize(@wood = 0)
end
def add_wood(x)
@ -60,9 +59,7 @@ end
w = World.new
w.map.print
w.push(BuildWoodMillCommand.new(Point.new(2, 1)))
w.push(BuildWoodMillCommand.new(Point.new(2, 3)))
w.push(BuildForesterHouseCommand.new(Point.new(2, 0)))
w.push(BuildForesterHouseCommand.new(Point.new(1, 2)))
w.push(BuildForesterHouseCommand.new(Point.new(3, 2)))
w.run(120)