First test
This commit is contained in:
parent
694167c646
commit
1bec9b987c
4
Makefile
4
Makefile
@ -8,8 +8,8 @@ format:
|
|||||||
./cr tool format ./src ./spec
|
./cr tool format ./src ./spec
|
||||||
|
|
||||||
.PHONY: spec
|
.PHONY: spec
|
||||||
spec:
|
spec: format
|
||||||
./cr spec --warnings all --error-on-warnings
|
./cr spec --warnings all --error-on-warnings --time
|
||||||
|
|
||||||
.PHONY: release
|
.PHONY: release
|
||||||
release:
|
release:
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
require "./spec_helper"
|
require "spec"
|
||||||
|
require "./../src/map"
|
||||||
|
|
||||||
describe Village do
|
describe Point do
|
||||||
# TODO: Write tests
|
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
|
end
|
||||||
|
@ -25,6 +25,7 @@ end
|
|||||||
class GetWoodCommand < Command
|
class GetWoodCommand < Command
|
||||||
BASE_TIME = 10
|
BASE_TIME = 10
|
||||||
BASE_WOOD = 80
|
BASE_WOOD = 80
|
||||||
|
REST_TIME = 5
|
||||||
|
|
||||||
def initialize(@point : Point)
|
def initialize(@point : Point)
|
||||||
@wood = 0
|
@wood = 0
|
||||||
@ -36,7 +37,7 @@ class GetWoodCommand < Command
|
|||||||
calc_time(wood_tile.as(Tile))
|
calc_time(wood_tile.as(Tile))
|
||||||
else
|
else
|
||||||
printf " << no wood tile\n"
|
printf " << no wood tile\n"
|
||||||
BASE_TIME
|
REST_TIME
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -86,6 +87,7 @@ end
|
|||||||
class GrowWoodCommand < Command
|
class GrowWoodCommand < Command
|
||||||
BASE_TIME = 15
|
BASE_TIME = 15
|
||||||
BASE_WOOD = 30
|
BASE_WOOD = 30
|
||||||
|
REST_TIME = 5
|
||||||
|
|
||||||
@wood_tile : Tile | Nil
|
@wood_tile : Tile | Nil
|
||||||
|
|
||||||
@ -99,8 +101,7 @@ class GrowWoodCommand < Command
|
|||||||
calc_time(@wood_tile.as(Tile))
|
calc_time(@wood_tile.as(Tile))
|
||||||
else
|
else
|
||||||
printf " >> no wood tile\n"
|
printf " >> no wood tile\n"
|
||||||
@wood = 0
|
REST_TIME
|
||||||
BASE_TIME
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
16
src/map.cr
16
src/map.cr
@ -1,17 +1,15 @@
|
|||||||
struct Point
|
struct Point
|
||||||
|
property x : Int32
|
||||||
|
property y : Int32
|
||||||
|
|
||||||
def initialize(@x : Int32, @y : Int32)
|
def initialize(@x : Int32, @y : Int32)
|
||||||
end
|
end
|
||||||
|
|
||||||
def x
|
getter x
|
||||||
@x
|
getter y
|
||||||
end
|
|
||||||
|
|
||||||
def y
|
def distance(other) : Int32
|
||||||
@y
|
return (other.x - @x).abs + (other.y - @y).abs
|
||||||
end
|
|
||||||
|
|
||||||
def distance(p : Point) : Int32
|
|
||||||
return (p.x - @x).abs + (p.y - @y).abs
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,8 +4,7 @@ require "./map"
|
|||||||
require "./queue"
|
require "./queue"
|
||||||
|
|
||||||
class Resources
|
class Resources
|
||||||
def initialize
|
def initialize(@wood = 0)
|
||||||
@wood = 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_wood(x)
|
def add_wood(x)
|
||||||
@ -60,9 +59,7 @@ end
|
|||||||
|
|
||||||
w = World.new
|
w = World.new
|
||||||
w.map.print
|
w.map.print
|
||||||
w.push(BuildWoodMillCommand.new(Point.new(2, 1)))
|
|
||||||
w.push(BuildWoodMillCommand.new(Point.new(2, 3)))
|
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(1, 2)))
|
||||||
w.push(BuildForesterHouseCommand.new(Point.new(3, 2)))
|
w.push(BuildForesterHouseCommand.new(Point.new(3, 2)))
|
||||||
w.run(120)
|
w.run(120)
|
||||||
|
Loading…
Reference in New Issue
Block a user