2017-07-05 11 views
0

私はバッチでグリッドを作成するプロジェクトで作業していましたが、バッチゲームなどでより良いグラフィックスにアクセスしたり変更したりすることができます。複数行のバッチファイル印刷で奇妙なエラーが発生しました

@echo off 
setlocal ENABLEDELAYEDEXPANSION 

!x! 
::::::::::: 
:: ALIAS :: 
::::::::::: 
:@alias 
    set x=exit/b 
    goto:@main 
    !x! 
::::::::::: 
:: MAIN :: 
::::::::::: 
:@main 
call:$Canvas _canvas 16 16 . 
set px=%~1 
set py=%~2 
set _canvas_point[!px!][!py!]=# 
!_canvas#draw! 

!x! 
::::::::::: 
::OBJECTS:: 
::::::::::: 
:@objects 
!x! 
:$Canvas 
    set this=%~1 
    set /a !this!_width=%~2 
    set /a !this!_height=%~3 
    set !this!_default_char=%~4 
    set !this!#draw=call:#$canvas_proto_draw !this! 
    for /L %%i in (1, 1, !%this%_height!) do (
     for /L %%j in (1, 1, !%this%_width!) do (
      set !this!_point[%%j][%%i]=!%this%_default_char! 
      set !this!_row[%%i]=!%this%_row[%%i]!!%this%_point[%%j][%%i]! 
      ) 
     ) 
    !x! 
    :#$Canvas_proto_draw 
     set this=%~1 
     for /L %%i in (1, 1, !%this%_height!) do (
     for /L %%j in (1, 1, !%this%_width!) do (
      set !this!_row[%%i]=!%this%_row[%%i]!!%this%_point[%%j][%%i]! 
      ) 
     ) 
     for /L %%i in (1, 1, !%this%_height!) do (
      echo !%this%_row[%%i]! 
      ) 
    !x! 

私の問題は、最終的な出力で発生します。それを与えること1, 1点は概ね半頂列に亘るアップ示すことになります。なぜこのようなことが起こるのか分かりませんし、助けが必要です。エコーをオンにしてすべての出力をコーディングした結果、_canvas_point[1][1]の値は#という値になりました。ここで

が出力されます。

C:\Home>canvas 1 1 
................#............... 
................................ 
................................ 
................................ 
................................ 
................................ 
................................ 
................................ 
................................ 
................................ 
................................ 
................................ 
................................ 
................................ 
................................ 
................................ 

C:\Home> 

Hereは出力が@echo on

クイック物事持つペーストビンリンクです: をはい、これはバッチ・ファイル内でのオブジェクト指向プログラミングで弱々しい試みである はい、私は他の言語がこの種のものの方が良いことを知っています、私はバッチファイルでそれをやりたいだけです。 はい、私は奇妙な文章の選択肢があります。それは私がそれを読むことができるように、ラベルがgotoの場所と関数ラベルの両方に使われるのを見ているからです。

答えて

0

おそらく以下の例では、(オブジェクト指向.batファイルのアプローチ)を達成しようとしているものに近づく:で

@echo off 
setlocal ENABLEDELAYEDEXPANSION 

rem Initialize object "_canvas" (index numbers are row then column) 
call :#$proto_init _canvas 16 16 . 

rem Set a few "_canvas" array characters to non-default values 
call :#$proto_set _canvas 1 1 ? 
call :#$proto_set _canvas 8 8 # 
call :#$proto_set _canvas 16 16 $ 

rem Display "_canvas" 
call :#$proto_draw _canvas 
endlocal 
exit/b 


:#$proto_init 
set /a %1_height=%2, %1_width=%3, %1_len=%2 * %3 
set %1_default_char=%4 
set %1_data=X 
for /l %%i in (1, 1, !%1_len!) do set %1_data=!%1_data!!%1_default_char! 
exit /b 


:#$proto_set 
for /f %%i in ('set /a ^(%2 - 1^) * !%1_height! + %3') do (
    for /f %%j in ('set /a %%i + 1') do (
    set %1_data=!%1_data:~0,%%i!%4!%1_data:~%%j! 
) 
) 
exit/b 


:#$proto_draw 
for /l %%w in (!%1_width!, 1, !%1_width!) do (
    for /l %%h in (1, %%w, !%1_len!) do echo !%1_data:~%%h,%%w! 
) 
exit /b 
+0

ありがとうございました。私はアプローチがあまり意味がないことを理解するが、助けてくれてありがとう:) – Bmofa

0

:#$ Canvas_proto_draw

:#$Canvas_proto_draw 
set this=%~1 
for /L %%i in (1, 1, !%this%_height!) do (
SET "!this!_row[%%i]=" 
for /L %%j in (1, 1, !%this%_width!) do (
... 

あなたはそれを観察することができます表示されるデータは32列×16行です。これは、値を追加する前に各行をクリアしないために発生します。

関連する問題