Tile with points
This commit is contained in:
parent
101c4179df
commit
05801dd983
47
src/map.cr
47
src/map.cr
@ -1,4 +1,24 @@
|
|||||||
|
struct Point
|
||||||
|
def initialize(@x : Int32, @y : Int32)
|
||||||
|
end
|
||||||
|
|
||||||
|
def x
|
||||||
|
@x
|
||||||
|
end
|
||||||
|
|
||||||
|
def y
|
||||||
|
@y
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
abstract class Tile
|
abstract class Tile
|
||||||
|
def initialize(@point : Point)
|
||||||
|
end
|
||||||
|
|
||||||
|
def point
|
||||||
|
@point
|
||||||
|
end
|
||||||
|
|
||||||
abstract def letter : Char
|
abstract def letter : Char
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -9,7 +29,7 @@ class GrassTile < Tile
|
|||||||
end
|
end
|
||||||
|
|
||||||
class WoodTile < Tile
|
class WoodTile < Tile
|
||||||
def initialize(cap : Int32)
|
def initialize(@point : Point, cap : Int32)
|
||||||
@cap = cap
|
@cap = cap
|
||||||
@cur = cap
|
@cur = cap
|
||||||
end
|
end
|
||||||
@ -45,36 +65,27 @@ class ForesterHouseTile < Tile
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
struct Point
|
|
||||||
def initialize(@x : Int32, @y : Int32)
|
|
||||||
end
|
|
||||||
|
|
||||||
def x
|
|
||||||
@x
|
|
||||||
end
|
|
||||||
|
|
||||||
def y
|
|
||||||
@y
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class Map
|
class Map
|
||||||
def initialize
|
def initialize
|
||||||
@data = {} of String => Tile
|
@data = {} of String => Tile
|
||||||
(0...4).each do |x|
|
(0...4).each do |x|
|
||||||
(0...4).each do |y|
|
(0...4).each do |y|
|
||||||
@data[key(Point.new(x, y))] = GrassTile.new
|
self.set(GrassTile.new(Point.new(x, y)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@data[key(Point.new(1, 1))] = WoodTile.new(100)
|
self.set(WoodTile.new(Point.new(1, 1), 100))
|
||||||
@data[key(Point.new(3, 1))] = WoodTile.new(200)
|
self.set(WoodTile.new(Point.new(3, 1), 200))
|
||||||
@data[key(Point.new(2, 2))] = WoodTile.new(100)
|
self.set(WoodTile.new(Point.new(2, 2), 100))
|
||||||
end
|
end
|
||||||
|
|
||||||
def get(point : Point) : Tile
|
def get(point : Point) : Tile
|
||||||
@data[key(Point.new(x, y))]
|
@data[key(Point.new(x, y))]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set(tile : Tile)
|
||||||
|
@data[key(tile.point)] = tile
|
||||||
|
end
|
||||||
|
|
||||||
def set(point : Point, tile : Tile)
|
def set(point : Point, tile : Tile)
|
||||||
@data[key(point)] = tile
|
@data[key(point)] = tile
|
||||||
end
|
end
|
||||||
|
@ -30,7 +30,7 @@ class BuildWoodMillCommand < Command
|
|||||||
|
|
||||||
def run(ts : Int32, world : World)
|
def run(ts : Int32, world : World)
|
||||||
printf "build mill at [%d,%d]\n", @point.x, @point.y
|
printf "build mill at [%d,%d]\n", @point.x, @point.y
|
||||||
world.map.set(@point, WoodMillTile.new)
|
world.map.set(WoodMillTile.new(@point))
|
||||||
world.push(ts + 5, GetWoodCommand.new)
|
world.push(ts + 5, GetWoodCommand.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -45,7 +45,7 @@ class BuildForesterHouseCommand < Command
|
|||||||
|
|
||||||
def run(ts : Int32, world : World)
|
def run(ts : Int32, world : World)
|
||||||
printf "build forester house at [%d,%d]\n", @point.x, @point.y
|
printf "build forester house at [%d,%d]\n", @point.x, @point.y
|
||||||
world.map.set(@point, ForesterHouseTile.new)
|
world.map.set(ForesterHouseTile.new(@point))
|
||||||
world.push(ts + 10, GrowWoodCommand.new)
|
world.push(ts + 10, GrowWoodCommand.new)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -72,8 +72,7 @@ class GrowWoodCommand < Command
|
|||||||
def run(ts : Int32, world : World)
|
def run(ts : Int32, world : World)
|
||||||
res = world.resources
|
res = world.resources
|
||||||
puts "grow wood"
|
puts "grow wood"
|
||||||
c = GetWoodCommand.new
|
world.push(ts + 5, GetWoodCommand.new)
|
||||||
world.push(ts + 5, c)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user