Random map generation
This commit is contained in:
parent
5292bc612c
commit
e6f4e5ee29
@ -33,7 +33,7 @@
|
||||
|
||||
### Карта
|
||||
|
||||
- [ ] Генерация карты
|
||||
- [x] Генерация карты
|
||||
- [x] Скалы
|
||||
- [ ] Вода
|
||||
- [ ] Расчет пути с учетом препятствий
|
||||
|
@ -2,7 +2,7 @@ require "colorize"
|
||||
require "./game/**"
|
||||
require "./cli/**"
|
||||
|
||||
map = Game::Generator.make 5, 10
|
||||
map = Game::Generator.make 5, 5
|
||||
ts = Time.local.to_unix
|
||||
world = Game::World.new map, ts
|
||||
|
||||
@ -69,7 +69,7 @@ def render_map(world)
|
||||
printf "|"
|
||||
(0...cols).each do |y|
|
||||
tile = world.map.get(x, y)
|
||||
if tile.letter == 'f'
|
||||
if tile.letter == 'v'
|
||||
printf "%6d|", world.map.get(x, y).cur
|
||||
else
|
||||
printf " |", world.map.get(x, y).cur
|
||||
|
@ -78,11 +78,14 @@ module Game
|
||||
|
||||
class Generator
|
||||
def self.make(rows, cols) : Map
|
||||
rnd = Random.new
|
||||
map = Map.new(rows, cols)
|
||||
5.times do
|
||||
pnt = Point.new(rnd.rand(0...rows), rnd.rand(0...cols))
|
||||
cap = rnd.rand(2...6)
|
||||
map.set(CrystalTile.new(pnt, cap * 50))
|
||||
end
|
||||
map.set(MainBaseTile.new(Point.new(0, 0)))
|
||||
map.set(CrystalTile.new(Point.new(1, 2), 100))
|
||||
map.set(CrystalTile.new(Point.new(4, 2), 200))
|
||||
map.set(CrystalTile.new(Point.new(3, 3), 100))
|
||||
map
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user