【问题标题】:Batch file internal data批处理文件内部数据
【发布时间】:2013-05-27 19:45:41
【问题描述】:

我正在尝试为我的记忆游戏提供一个高分选项,它会自行保存您的分数,并在您访问程序的“高分”部分时调用所有保存的分数。我到目前为止的代码在这里:

@echo off
REM Produced by Calder Hutchins
REM This is a game
title Memory Game
:begin
set point=0
cls
echo.
echo Memeory Game
echo ------------------
echo 1) Play
echo 2) Instructions
echo 3) High Scores
echo ------------------
set /p pick=^>
if %pick%==1 goto one
if %pick%==2 goto two
if %pick%==3 goto three
goto begin
:one
cls
REM Determines the number
if %point% LSS 6  set /a rand=%random% %% (100 - 1 + 1)+ 1
if %point% LSS 12 if %point% GTR 5 set /a rand=%random% %% (500 - 100 + 1)+ 100
if %point% LSS 18 if %point% GTR 11 set /a rand=%random% %% (1000 - 500 + 1)+ 500
if %point% LSS 24 if %point% GTR 17 set /a rand=%random% %% (2000 - 1000 + 1)+ 1000
if %point% LSS 30 if %point% GTR 23 set /a rand=%random% %% (9000 - 1500 + 1)+ 1500
if %point% LSS 36 if %point% GTR 29 set /a rand=%random% %% (19000 - 5000 + 1)+ 5000
if %point% LSS 42 if %point% GTR 35 set /a rand=%random% %% (32000 - 10000 + 1)+ 10000
if %point% LSS 48 if %point% GTR 41 set /a rand=%random% %% (999 - 100 + 1)+ 100
if %point% LSS 48 if %point% GTR 41 set /a randtwo=%random% %% (999 - 100 + 1)+ 100
if %point% GTR 47 set /a rand=%random% %% (9999 - 1000 + 1)+ 1000
if %point% GTR 47 set /a randtwo=%random% %% (9999 - 1000 + 1)+ 1000
echo.
REM  Prints the number  
if %point% LSS 42 echo %rand% 
if %point% GTR 41 set rand=%rand%%randtwo%
if %point% GTR 41 echo %rand%
echo.
ping localhost -n 3 >nul
cls
echo.
echo.
echo.
set /p yourOption=Guess:
REM Determines correct or wrong
if %youroption%==%rand% set /a point=%point% +1 & goto one
cls
echo.
echo You scored: %point%
echo.
set /p name=Type name:
echo %name%  -  %point% >> E:\Scripts\Batch\memoryGame\score.txt
goto begin
:two
cls
echo. 
echo The objective of the game is to get as many points as possible.  To get points you must correctly retype the numbers that appear on the screen.  The numbers show for a short period of time.  As you get more points the numbers get longer!  When you have lost you will be prompted to enter your name.  You can view the highscores too!  
echo. 
pause
goto begin
:three
cls
echo.
sort E:\Scripts\Batch\memoryGame\score.txt
echo.
pause
goto begin

上面的只是保存到一个文件,但如果可能的话,我希望它在内部保存。我收到了一个我已经修改但无法在我的游戏中实现的脚本。脚本代码为:

@echo off
for /f "tokens=1 delims=:" %%D in ('findstr /R /N "storedData" "%~f0"' ) do set end_batch=%%D
echo Make data

echo echo data entry 4^>^>"%~f0"
echo(>>"%~f0"
echo data entry ^4>>"%~f0"

echo Print Data
type "%~f0" | more +%end_batch%
exit /b 0


:storedData

关于如何让它工作的任何建议?

【问题讨论】:

  • sort E:\Scripts\Batch\memoryGame\score.txt你想对批处理文件进行排序?
  • 我使用了它,所以它会将条目名称从 A 到 Z 排序。每行包含一个名称,而不是它们旁边的点。
  • 如果你sort批处理代码你觉得会发生什么?
  • 什么?我没有对批处理代码进行排序。我正在独立于批处理文件对文本文件进行排序。
  • 好的,你想在批处理文件中存储什么?

标签: batch-file system internal


【解决方案1】:

嗯.. 我有一个比我之前的答案更好的主意 - 备用数据流(仅适用于 NTFS):

    echo You scored: %point%
    echo.
    set /p name=Type name:
    echo %name%  -  %point% >>"%~f0:scores"
    goto begin
    :two
    cls
    echo. 
    echo The objective of the game is to get as many points as possible.  To get points you must correctly retype the numbers that appear on the screen.  The numbers show for a short period of time.  As you get more points the numbers get longer!  When you have lost you will be prompted to enter your name.  You can view the highscores too!  
    echo. 
    pause
    goto begin
    :three
   cls
   echo.
   more<"%~f0:scores" | sort
   echo.
   pause
   goto begin

但这将是文字排序...

编辑:

@echo off
REM Produced by Calder Hutchins
REM This is a game
title Memory Game
:begin
set point=0
cls
echo.
echo Memeory Game
echo ------------------
echo 1) Play
echo 2) Instructions
echo 3) High Scores
echo ------------------
set /p pick=^>
if %pick%==1 goto one
if %pick%==2 goto two
if %pick%==3 goto three
goto begin
:one
cls
REM Determines the number
if %point% LSS 6  set /a rand=%random% %% (100 - 1 + 1)+ 1
if %point% LSS 12 if %point% GTR 5 set /a rand=%random% %% (500 - 100 + 1)+ 100
if %point% LSS 18 if %point% GTR 11 set /a rand=%random% %% (1000 - 500 + 1)+ 500
if %point% LSS 24 if %point% GTR 17 set /a rand=%random% %% (2000 - 1000 + 1)+ 1000
if %point% LSS 30 if %point% GTR 23 set /a rand=%random% %% (9000 - 1500 + 1)+ 1500
if %point% LSS 36 if %point% GTR 29 set /a rand=%random% %% (19000 - 5000 + 1)+ 5000
if %point% LSS 42 if %point% GTR 35 set /a rand=%random% %% (32000 - 10000 + 1)+ 10000
if %point% LSS 48 if %point% GTR 41 set /a rand=%random% %% (999 - 100 + 1)+ 100
if %point% LSS 48 if %point% GTR 41 set /a randtwo=%random% %% (999 - 100 + 1)+ 100
if %point% GTR 47 set /a rand=%random% %% (9999 - 1000 + 1)+ 1000
if %point% GTR 47 set /a randtwo=%random% %% (9999 - 1000 + 1)+ 1000
echo.
REM  Prints the number  
if %point% LSS 42 echo %rand% 
if %point% GTR 41 set rand=%rand%%randtwo%
if %point% GTR 41 echo %rand%
echo.
ping localhost -n 3 >nul
cls
echo.
echo.
echo.
set /p yourOption=Guess:
REM Determines correct or wrong
if %youroption%==%rand% set /a point=%point% +1 & goto one
cls
echo.
echo You scored: %point%
echo.
set /p name=Type name:
echo %name%  -  %point% >>"%~f0:scores"
goto begin
:two
cls
echo. 
echo The objective of the game is to get as many points as possible.  To get points you must correctly retype the numbers that appear on the screen.  The numbers show for a short period of time.  As you get more points the numbers get longer!  When you have lost you will be prompted to enter your name.  You can view the highscores too!  
echo. 
pause
goto begin
:three
cls
echo.
more<"%~f0:scores" | sort
echo.
pause
goto begin

【讨论】:

  • 您应该添加两件事 echo %name% - %point% &gt;&gt;"%~f0:scoresmore&lt;"%~f0:scores" | sort 。您确定两者都存在吗?
  • 使用此命令(需要管理员权限)可以检查您的文件系统是否为NTFS : fsutil fsinfo volumeinfo c:
  • 你能不能试试看。我不确定 USB 是否支持 ADS。特别是如果 USB 是用 FAT32 格式化的。这取决于 .bat 所在的文件系统
  • 保存蝙蝠确实会删除其 ADS(此处)。
  • @Calder Hutchins 它被保存在不可见的文件的替代版本中。MORE 命令可以读取替代数据流,但例如TYPE 或记事本不能。这里有更多信息:en.wikipedia.org/wiki/Fork_(file_system)
【解决方案2】:

下面的批处理文件完全按照您的要求执行,即它会自己保存您的分数,并在您访问程序的“高分”部分时调用所有保存的分数。

echo You scored: %point%
echo.
set /p name=Type name:
echo %name%  -  %point% >> "%~F0"
goto begin
:two
cls
echo. 
echo The objective of the game is to get as many points as possible.  To get points you must correctly retype the numbers that appear on the screen.  The numbers show for a short period of time.  As you get more points the numbers get longer!  When you have lost you will be prompted to enter your name.  You can view the highscores too!  
echo. 
pause
goto begin
:three
cls
echo.
for /F "delims=:" %%n in ('findstr /N "^:savedScores" "%~F0"') do set n=%%n
more +%n% "%~F0" | sort
echo.
pause
goto begin
:savedScores

【讨论】:

    猜你喜欢
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 2013-05-22
    • 2012-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-05
    相关资源
    最近更新 更多