-1

我几乎完成了我的游戏,并使用了“备用数据流”来在 ADS 中保存一些高分。现在我尝试对颜色选项做同样的事情,以使游戏与您每次打开它时设置的颜色方案相同,直到您想要更改它。这是我正在处理的代码:

echo.
echo Color Options - background/text
echo ------------------
echo 0) Black
echo 1) Blue
echo 2) green
echo 3) Aqua
echo 4) Red
echo 5) Purple
echo 6) Yellow
echo 7) White
echo 8) Grey
echo ------------------
set /p BcolorSetting=Background:
set /p TcolorSetting=Text:
echo %BcolorSetting%%TcolorSetting% >>"%~f0:colors"
color <"%~f0:colors"
pause

如果你想看到整个事情,那就是......

@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 4) Options
echo ------------------
set /p pick=^>
if %pick%==1 goto one
if %pick%==2 goto two
if %pick%==3 goto three
if %pick%==4 goto four 
if %pick%==99 goto test 
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
:four
cls
echo.
echo Settings/Options
echo ------------------
echo 1) color
echo ------------------
set /p pickSetting=^>
if %pickSetting%==1 goto oneSetting
goto four
:oneSetting
cls
echo.
echo Color Options - background/text
echo ------------------
echo 0) Black
echo 1) Blue
echo 2) green
echo 3) Aqua
echo 4) Red
echo 5) Purple
echo 6) Yellow
echo 7) White
echo 8) Grey
echo ------------------
set /p BcolorSetting=Background:
set /p TcolorSetting=Text:
echo %BcolorSetting%%TcolorSetting% >>"%~f0:colors"
color <"%~f0:colors"
pause
goto begin

提前谢谢你们!

4

2 回答 2

2

幸运的是,FOR /F可以阅读 ADS:

for /f "usebackq" %%C in ("%~f0:colors") do COLOR %%C
于 2013-05-28T06:54:21.240 回答
1

看来您必须 CD 某个目录。然后,写入目录中的文本文件。首先,阅读文本文件。然后,覆盖文本文件并在您卡住的地方写入颜色。

如果您需要从任何应用程序中的设置开始,您总是需要一个保存文件。写作可以是这样的:

echo %BcolorSetting%%TcolorSetting% >>"colorsetting.txt"

检索时,请从一开始就进行。在开始之前。是这样读的

set /p %~f0:colors= <colorsetting.txt

假设您使用这些变量。我希望这有帮助。

于 2013-05-28T02:33:27.847 回答