Use points for map
This commit is contained in:
parent
7652adebc4
commit
40c8e0640f
12
src/map.cr
12
src/map.cr
@ -33,6 +33,12 @@ class WoodTile < Tile
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class WoodMillTile < Tile
|
||||||
|
def letter : Char
|
||||||
|
'm'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
struct Point
|
struct Point
|
||||||
def initialize(@x : Int32, @y : Int32)
|
def initialize(@x : Int32, @y : Int32)
|
||||||
end
|
end
|
||||||
@ -59,10 +65,14 @@ class Map
|
|||||||
@data[key(Point.new(2, 2))] = WoodTile.new(100)
|
@data[key(Point.new(2, 2))] = WoodTile.new(100)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(x : Int32, y : Int32) : Tile
|
def get(point : Point) : Tile
|
||||||
@data[key(Point.new(x, y))]
|
@data[key(Point.new(x, y))]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set(point : Point, tile : Tile)
|
||||||
|
@data[key(point)] = tile
|
||||||
|
end
|
||||||
|
|
||||||
def print
|
def print
|
||||||
(0...4).each do |x|
|
(0...4).each do |x|
|
||||||
(0...4).each do |y|
|
(0...4).each do |y|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require "./queue"
|
require "./queue"
|
||||||
|
require "./map"
|
||||||
|
|
||||||
class Resources
|
class Resources
|
||||||
def initialize
|
def initialize
|
||||||
@ -19,14 +20,18 @@ abstract class Command
|
|||||||
abstract def run(ts : Int32, world : World)
|
abstract def run(ts : Int32, world : World)
|
||||||
end
|
end
|
||||||
|
|
||||||
class BuildMillCommand < Command
|
class BuildWoodMillCommand < Command
|
||||||
|
def initialize(@point : Point)
|
||||||
|
end
|
||||||
|
|
||||||
def supports?(world : World) : Bool
|
def supports?(world : World) : Bool
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(ts : Int32, world : World)
|
def run(ts : Int32, world : World)
|
||||||
puts "build mill"
|
printf "build mill at [%d,%d]\n", @point.x, @point.y
|
||||||
c = GetWoodCommand.new
|
c = GetWoodCommand.new
|
||||||
|
world.map.set(@point, WoodMillTile.new)
|
||||||
world.push(ts + 5, c)
|
world.push(ts + 5, c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -89,7 +94,7 @@ class World
|
|||||||
if !command.supports?(self)
|
if !command.supports?(self)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
printf "push command %d\n", ts
|
printf "push command %s, %d\n", typeof(command), ts
|
||||||
@queue.push(ts, command)
|
@queue.push(ts, command)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
@ -109,6 +114,7 @@ end
|
|||||||
|
|
||||||
w = World.new
|
w = World.new
|
||||||
w.map.print
|
w.map.print
|
||||||
w.push(0, BuildMillCommand.new)
|
w.push(0, BuildWoodMillCommand.new(Point.new(0, 0)))
|
||||||
w.push(1, BuildForesterHouseCommand.new)
|
w.push(1, BuildForesterHouseCommand.new)
|
||||||
w.run(20)
|
w.run(20)
|
||||||
|
w.map.print
|
||||||
|
Loading…
Reference in New Issue
Block a user