Configurable map

This commit is contained in:
Anton Vakhrushev 2019-10-18 13:53:30 +03:00
parent c87db2496e
commit 50c7f658e6
2 changed files with 3 additions and 3 deletions

View File

@ -6,7 +6,7 @@ class App
@ts : Game::TimePoint @ts : Game::TimePoint
def initialize def initialize
@map = Game::Generator.make 5, 5 @map = Game::Generator.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

View File

@ -62,10 +62,10 @@ module Game
end end
class Generator class Generator
def self.make(rows, cols) : Map def self.make(rows, cols, deposits = 5) : Map
rnd = Random.new rnd = Random.new
map = Map.new(rows, cols) map = Map.new(rows, cols)
5.times do deposits.times do
point = Point.new(rnd.rand(0...rows), rnd.rand(0...cols)) point = Point.new(rnd.rand(0...rows), rnd.rand(0...cols))
cap = rnd.rand(2...6) cap = rnd.rand(2...6)
deposit = Deposit.new(Resource::Type::Crystals, cap * 50) deposit = Deposit.new(Resource::Type::Crystals, cap * 50)