1

这是我可怕的代码。如您所知,我对此很陌生。它应该使在旧游戏中写下基于图片的密码更容易,并且具有可自定义的代码,但它占用了太多空间。

@echo off
SET code1=dog        
SET code2=cat        
SET code3=hamster    
SET code4=chicken    
SET code5=cow        
SET code6=horse      
SET code7=lizard     
SET code8=snake      
SET code9=frog       
SET code10=llama      
SET code11=sheep      
SET code12=rabbit     
SET code13=chinchilla 
SET code14=monkey     
SET code15=human      
SET code16=alien      
:CODE
SET /a n+=1
ECHO 1:%code1%2:%code2%3:%code3%4:%code4%5:%code5%6:%code6%7:%code7%8:%code8%
ECHO Q:%code9%W:%code10%E:%code11%R:%code12%T:%code13%Y:%code14%U:%code15%I:%code16%
CHOICE /c 12345678QWERTYUI /n
set thing=%errorlevel%
if %thing%==1 echo %code1%>passwords.txt
if %thing%==2 echo %code2%>passwords.txt
if %thing%==3 echo %code3%>passwords.txt
if %thing%==4 echo %code4%>passwords.txt
if %thing%==5 echo %code5%>passwords.txt
if %thing%==6 echo %code6%>passwords.txt
if %thing%==7 echo %code7%>passwords.txt
if %thing%==8 echo %code8%>passwords.txt
if %thing%==9 echo %code9%>passwords.txt
if %thing%==10 echo %code10%>passwords.txt
if %thing%==11 echo %code11%>passwords.txt
if %thing%==12 echo %code12%>passwords.txt
if %thing%==13 echo %code13%>passwords.txt
if %thing%==14 echo %code14%>passwords.txt
if %thing%==15 echo %code15%>passwords.txt
if %thing%==16 echo %code16%>passwords.txt
if n lss 8 goto CODE
rem change this number for length of password
echo done

它应该做的是将8个单词输出到文本文件的一行,即按“1q2w3e4r”将输出“dog frog cat llama hamster Sheep chicken rabbit”到文本文件。

4

2 回答 2

1

这是:

@echo off & Setlocal Enabledelayedexpansion

:: Set the codes
Set "Codes=dog cat hamster chicken cow horse lizard snake frog llama sheep rabbit chinchilla monkey human alien"
:: Set the Choice Options
Set "Opts=1 2 3 4 5 6 7 8 Q W E R T Y U I"

:: Set up the Code Variables
For %%C in (%Codes%) Do (
    Set /A "CodeIndex+=1"
    Set "Code!CodeIndex!=%%C"
)

:: Set up the Choice Letter Variables
For %%O in (%Opts%) Do (
    Set /A "OptIndex+=1"
    Set "Opt!OptIndex!=%%O"
)

:Menu
:: Display the menu
For /L %%N in (1, 1, 8) Do (<nul Set /P "=!Opt%%N!:!Code%%N! ")
Echo+
For /L %%N in (9, 1, 16) Do (<nul Set /P "=!Opt%%N!:!Code%%N! ")
Echo+

CHOICE /C "%Opts: =%" /n

:: Return
:: If %ERRORLEVEL% lss 9 (goto :MENU)

:: Write the selected code
Echo !Code%ERRORLEVEL%!>".\Passwords.txt"

:END
Exit /B 0

在此处输入图像描述

于 2013-10-17T19:42:08.080 回答
0

你的计数循环坏了,我不知道它应该如何工作,所以我完全删除了它。我还删除了对密码文件的重定向,以便轻松查看正在发生的事情 - 它可以很容易地添加回来。

下面的代码很容易适应代码字列表的加法或减法。该列表只需在一处更新。我添加了更多条目以显示它是多么容易,并表明它不必是 8 的倍数。

我假设您希望去除代码字的尾随空格 - 它们仅用于适当的菜单间距。

@echo off
setlocal enableDelayedExpansion
set "n=0"
set "keys="
for /f "delims==" %%A in ('set $prompt 2^>nul') do set "%%A="
for %%A in (
  "1:dog        "
  "2:cat        "
  "3:hamster    "
  "4:chicken    "
  "5:cow        "
  "6:horse      "
  "7:lizard     "
  "8:snake      "
  "Q:frog       "
  "W:llama      "
  "E:sheep      "
  "R:rabbit     "
  "T:chinchilla "
  "Y:monkey     "
  "U:human      "
  "I:alien      "
  "A:godzilla   "
  "S:orc        "
  "D:medussa    "
) do (
  set /a "p=n/8,n+=1"
  for %%P in (!p!) do set "$prompt%%P=!$prompt%%P!%%~A"
  for /f "tokens=1,2 delims=: " %%B in (%%A) do (
    set "keys=!keys!%%B"
    set "code!n!=%%C"
  )
)
for /f "delims== tokens=1,2" %%A in ('set $prompt') do echo %%B
choice /c !keys! /n
for %%N in (%errorlevel%) do echo !code%%N!
于 2013-10-17T20:56:21.913 回答