Extract map generator
This commit is contained in:
parent
50c7f658e6
commit
9b057bdc9f
9
Makefile
9
Makefile
@ -23,10 +23,11 @@ format:
|
|||||||
run: format
|
run: format
|
||||||
crystal run $(ENTRY_POINT)
|
crystal run $(ENTRY_POINT)
|
||||||
|
|
||||||
.PHONY: spec
|
|
||||||
spec: format
|
|
||||||
crystal spec --warnings all --error-on-warnings --error-trace
|
|
||||||
|
|
||||||
.PHONY: ameba
|
.PHONY: ameba
|
||||||
ameba:
|
ameba:
|
||||||
ameba src/ || true
|
ameba src/ || true
|
||||||
|
|
||||||
|
.PHONY: spec
|
||||||
|
spec: format ameba
|
||||||
|
crystal spec --warnings all --error-on-warnings --error-trace
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ class App
|
|||||||
@ts : Game::TimePoint
|
@ts : Game::TimePoint
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@map = Game::Generator.make 6, 8, 10
|
@map = Game::MapGenerator.make 6, 8, 10
|
||||||
@ts = Time.local.to_unix
|
@ts = Time.local.to_unix
|
||||||
@world = Game::World.new @map, @ts
|
@world = Game::World.new @map, @ts
|
||||||
@buildings = Game::BuildingFactory.new
|
@buildings = Game::BuildingFactory.new
|
||||||
|
@ -60,18 +60,4 @@ module Game
|
|||||||
seek_tile
|
seek_tile
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Generator
|
|
||||||
def self.make(rows, cols, deposits = 5) : Map
|
|
||||||
rnd = Random.new
|
|
||||||
map = Map.new(rows, cols)
|
|
||||||
deposits.times do
|
|
||||||
point = Point.new(rnd.rand(0...rows), rnd.rand(0...cols))
|
|
||||||
cap = rnd.rand(2...6)
|
|
||||||
deposit = Deposit.new(Resource::Type::Crystals, cap * 50)
|
|
||||||
map.set DepositTile.new(point, deposit)
|
|
||||||
end
|
|
||||||
map
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
13
src/game/map_generator.cr
Normal file
13
src/game/map_generator.cr
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
class Game::MapGenerator
|
||||||
|
def self.make(rows, cols, deposits = 5) : Map
|
||||||
|
rnd = Random.new
|
||||||
|
map = Map.new(rows, cols)
|
||||||
|
deposits.times do
|
||||||
|
point = Point.new(rnd.rand(0...rows), rnd.rand(0...cols))
|
||||||
|
cap = rnd.rand(2...6)
|
||||||
|
deposit = Deposit.new(Resource::Type::Crystals, cap * 50)
|
||||||
|
map.set DepositTile.new(point, deposit)
|
||||||
|
end
|
||||||
|
map
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user