From d96310f07daad3e441d6bbeb7f6be43c1bcd9c26 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 12 May 2025 11:49:56 +0300 Subject: [PATCH] examples: support directly loading sokoban level files by path --- examples/sokoban/corners.txt | 6 +++--- examples/sokoban/simple.txt | 6 +++--- examples/sokoban/sokoban.v | 18 +++++++++++++----- examples/sokoban/three_boxes.txt | 6 +++--- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/examples/sokoban/corners.txt b/examples/sokoban/corners.txt index 5a1cb29a75..5f26c0632b 100644 --- a/examples/sokoban/corners.txt +++ b/examples/sokoban/corners.txt @@ -1,12 +1,12 @@ Push the boxes to the corners of the warehouse.@It is a lot of work...@Have fun. ######################### -#@ # @# +#. # .# # # # # ## ### #### #### # ## # # # -# b # b # b # b # +# $ # $ # $ # $ # # # # # # # # # ### #### # # # ### # -#@ # p @# +#. # @ .# ######################### diff --git a/examples/sokoban/simple.txt b/examples/sokoban/simple.txt index 38357eb8fc..fc96f25734 100644 --- a/examples/sokoban/simple.txt +++ b/examples/sokoban/simple.txt @@ -2,8 +2,8 @@ Move your player to the box and push it.@Use the arrows to move your player. ############## # # # # -# b # -# @ # -# p # +# $ # +# . # +# @ # # # ############## diff --git a/examples/sokoban/sokoban.v b/examples/sokoban/sokoban.v index ab4435531f..5357313dab 100644 --- a/examples/sokoban/sokoban.v +++ b/examples/sokoban/sokoban.v @@ -1,3 +1,4 @@ +import os import os.asset import gg import gx @@ -55,17 +56,20 @@ fn (mut g Game) parse_level(lnumber int) ! { mut row := []rune{} for x, c in line { match c { - `#`, ` `, `@` { + `#`, ` ` { row << c } - `b` { // a normal box + `b`, `$` { // a normal box row << ` ` boxes << Pos{x, y} } - `p` { // a normal player + `p`, `@` { // a normal player row << ` ` player = Pos{x, y} } + `.` { // storage + row << `@` + } `B` { // box on storage row << `@` boxes << Pos{x, y} @@ -247,8 +251,12 @@ fn (mut g Game) iid(name string) !int { fn main() { mut g := &Game{} - all_level_names := asset.read_text('/', '_all_levels.txt')!.split_into_lines() - g.levels = all_level_names.map(asset.read_text('/', it)!) + if os.args.len > 1 { + g.levels = os.args[1..].map(os.read_file(it)!) + } else { + all_level_names := asset.read_text('/', '_all_levels.txt')!.split_into_lines() + g.levels = all_level_names.map(asset.read_text('/', it)!) + } g.parse_level(0)! g.ctx = gg.new_context( width: 800 diff --git a/examples/sokoban/three_boxes.txt b/examples/sokoban/three_boxes.txt index de3f739f08..60820305df 100644 --- a/examples/sokoban/three_boxes.txt +++ b/examples/sokoban/three_boxes.txt @@ -1,10 +1,10 @@ It seems tricky, but it is not ...@Be careful to not get stuck. ### # ###### ###### # - # p # # + # @ # # ## ####### -# bbb # # -# @ @ @ # # +# $$$ # # +# . . . # # # # # ### # # # ### # ############ #