Extract map generator

This commit is contained in:
Anton Vakhrushev 2019-10-18 13:57:49 +03:00
parent 50c7f658e6
commit 9b057bdc9f
4 changed files with 19 additions and 19 deletions

View File

@ -23,10 +23,11 @@ format:
run: format
crystal run $(ENTRY_POINT)
.PHONY: spec
spec: format
crystal spec --warnings all --error-on-warnings --error-trace
.PHONY: ameba
ameba:
ameba src/ || true
.PHONY: spec
spec: format ameba
crystal spec --warnings all --error-on-warnings --error-trace

View File

@ -6,7 +6,7 @@ class App
@ts : Game::TimePoint
def initialize
@map = Game::Generator.make 6, 8, 10
@map = Game::MapGenerator.make 6, 8, 10
@ts = Time.local.to_unix
@world = Game::World.new @map, @ts
@buildings = Game::BuildingFactory.new

View File

@ -60,18 +60,4 @@ module Game
seek_tile
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

13
src/game/map_generator.cr Normal file
View 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