2013-05-28 2 views
-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 

감사의 사전들에 : 여기 내가 일하고 코드입니다!

답변

2

다행히 FOR /F가 읽을 수있는 ADS :

for /f "usebackq" %%C in ("%~f0:colors") do COLOR %%C 
1

CD에 특정 디렉토리가 있어야하는 것으로 보입니다. 그런 다음 디렉토리 내의 텍스트 파일에 씁니다. 처음에는 텍스트 파일을 읽습니다. 그런 다음 텍스트 파일을 덮어 쓰고 붙인 지점에서 색상을 씁니다.

모든 앱에서 설정을 시작해야하는 경우 항상 저장 파일이 필요합니다. 쓰기는 다음과 같이 할 수있다 :

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

을 그리고 검색 할 때, 맨 처음에 그것을 할. 시작하기 전에. 그것은 당신이 그 변수를 사용하는 가정이

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

처럼 읽습니다. 이게 도움이 되길 바란다.