Show map always
This commit is contained in:
parent
e0b586ea6e
commit
927ca47b04
8
Makefile
8
Makefile
@ -14,14 +14,14 @@ build:
|
||||
mkdir -p build
|
||||
./crystal build $(ENTRY_POINT) --release --no-debug --static -o build/$(APP_NAME)
|
||||
|
||||
.PHONY: run
|
||||
run: format
|
||||
./crystal run $(ENTRY_POINT)
|
||||
|
||||
.PHONY: format
|
||||
format:
|
||||
./crystal tool format ./src ./spec
|
||||
|
||||
.PHONY: run
|
||||
run: format
|
||||
./crystal run $(ENTRY_POINT)
|
||||
|
||||
.PHONY: spec
|
||||
spec: format
|
||||
./crystal spec --no-debug --warnings all --error-on-warnings --error-trace
|
||||
|
@ -10,40 +10,6 @@ world = Game::World.new(ts)
|
||||
|
||||
router = CLI::CommandRouter.new
|
||||
|
||||
router.add "st" do
|
||||
printf "Stat:\n Crystals: %d\n Terraformation: %d\n",
|
||||
world.resources[Game::ResourceType::Crystal],
|
||||
world.resources[Game::ResourceType::Terraformation]
|
||||
end
|
||||
|
||||
router.add "m" do
|
||||
size = world.map.size
|
||||
(0...size).each do |x|
|
||||
if x == 0
|
||||
printf "+"
|
||||
(0...size).each do |y|
|
||||
printf "---+"
|
||||
end
|
||||
print "\n"
|
||||
end
|
||||
printf "|"
|
||||
(0...size).each do |y|
|
||||
printf "%c%d%d|", world.map.get(x, y).letter, x, y
|
||||
end
|
||||
print "\n"
|
||||
printf "|"
|
||||
(0...size).each do |y|
|
||||
printf "%3d|", world.map.get(x, y).cur
|
||||
end
|
||||
print "\n"
|
||||
printf "+"
|
||||
(0...size).each do |y|
|
||||
printf "---+"
|
||||
end
|
||||
print "\n"
|
||||
end
|
||||
end
|
||||
|
||||
router.add "q" do |p|
|
||||
items = world.queue.top(5)
|
||||
items.each do |i|
|
||||
@ -73,12 +39,58 @@ router.add "terr {x} {y}" do |p|
|
||||
world.push(Game::BuildTerraformerCommand.new(point))
|
||||
end
|
||||
|
||||
def render_map(world)
|
||||
size = world.map.size
|
||||
(0...size).each do |x|
|
||||
if x == 0
|
||||
printf "+"
|
||||
(0...size).each do |y|
|
||||
printf "---+"
|
||||
end
|
||||
print "\n"
|
||||
end
|
||||
printf "|"
|
||||
(0...size).each do |y|
|
||||
printf "%c%d%d|", world.map.get(x, y).letter, x, y
|
||||
end
|
||||
print "\n"
|
||||
printf "|"
|
||||
(0...size).each do |y|
|
||||
printf "%3d|", world.map.get(x, y).cur
|
||||
end
|
||||
print "\n"
|
||||
printf "+"
|
||||
(0...size).each do |y|
|
||||
printf "---+"
|
||||
end
|
||||
print "\n"
|
||||
end
|
||||
end
|
||||
|
||||
def render_resources(world)
|
||||
printf "Resources:\n Crystals: %5d\n Terraformation: %5d\n",
|
||||
world.resources[Game::ResourceType::Crystal],
|
||||
world.resources[Game::ResourceType::Terraformation]
|
||||
end
|
||||
|
||||
def render_world(world)
|
||||
printf "Now: %s\n\n", Time.unix(world.ts).to_local.to_s
|
||||
if world.win?
|
||||
printf "YOU WIN!!!\n\n"
|
||||
end
|
||||
render_resources world
|
||||
printf "\n"
|
||||
render_map world
|
||||
printf "\n"
|
||||
end
|
||||
|
||||
def normalize_command(cmd)
|
||||
cmd.downcase.gsub(/\s+/, ' ').strip
|
||||
end
|
||||
|
||||
printf "\u{001b}[2J"
|
||||
loop do
|
||||
render_world world
|
||||
printf "In > "
|
||||
cmd = read_line()
|
||||
norm = normalize_command(cmd)
|
||||
@ -88,10 +100,6 @@ loop do
|
||||
printf "\u{001b}[2J"
|
||||
current_time = Time.local.to_unix
|
||||
world.run current_time
|
||||
printf "Now: %s\n\n", Time.unix(world.ts).to_local.to_s
|
||||
if world.win?
|
||||
printf "YOU WIN!!!\n\n"
|
||||
end
|
||||
router.handle cmd
|
||||
printf "\n"
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user