Board logo

标题: 猜数字游戏三 [打印本页]

作者: tadonis     时间: 2008-5-23 16:35    标题: 猜数字游戏三

@echo off&mode con cols=45 lines=40&color f9 setlocal enabledelayedexpansion title 猜数字 by tadonis :begin cls echo ******************************************** echo * * echo * 猜数字(0000-9999)不可重复数字 * echo * * echo ******************************************** echo 规则:^^^^^^^^^^^^^^^^省略&set count=0&set/a chance=8 :loop set /a num=%random%%%10 if not defined num%num% ( set /a num%num%=%num% set /a count+=1 set /a a%count%=%num% ) if %count% lss 4 goto loop :start set/a A=0,BB=0,BBB=0 set pppp= set/p pppp=请输入四位的数字 if "%pppp%"=="" goto error if %pppp% gtr 0 ( if %pppp% lss 9999 ( echo right>nul ) else goto error ) else goto error set aa0=%pppp:~0,1% set aa1=%pppp:~1,1% set aa2=%pppp:~2,1% set aa3=%pppp:~3,1% for /l %%q in (0,1,3) do ( for /l %%w in (0,1,3) do ( if !aa%%q! equ !aa%%w! ( set /a BBB+=1) )) if %BBB% gtr 4 goto error for /l %%e in (0,1,3) do ( if !a%%e! equ !aa%%e! set /a A+=1 ) for /l %%t in (0,1,3) do ( for /l %%r in (0,1,3) do ( if !a%%t! equ !aa%%r! (set /a BB+=1))) set/a B=%BB%-%A%&set/a chance-=1 if %A% equ 4 ( goto succeed ) else ( if %chance% lss 1 ( goto fail ) else ( echo %A%A%B%B&echo.&echo 你还有%chance%次机会&goto start)) :succeed set /a c=8-%chance%&echo 你共猜了%c%次 if %chance% gtr 4 echo you are so clever&echo 再来一次?? :choice set /p choice=[Y/N]? if /i "%choice%"=="Y" ( goto begin ) else ( if /i "%choice%"=="N" (goto exit) else goto choice) :fail echo 你太菜了吧!!&echo 正确答案是 %a0%,%a1%,%a2%,%a3% ping /n 2 127.0.0.1>nul set /p choice=再来一次??[Y/N] if /i "%choice%"=="Y" ( goto begin ) else ( if /i "%choice%"=="N" (goto exit) else goto choice) :error color d0&ping /n 1 127.0.0.1>nul echo wrong number !! ping /n 1 127.0.0.1>nul&color f9 goto :start :exit exit