tadonis
初级用户
积分 38
发帖 10
注册 2008-5-20
状态 离线
|
『楼 主』:
猜数字游戏二
@echo off
mode con cols=45 lines=40
color f9
setlocal enabledelayedexpansion
title 猜数字 by tadonis
:begin
cls
echo *********************************************
echo * *
echo * 猜数字(0000-9999)(可重复数字) *
echo * *
echo *********************************************
set/a chance=8
set/a A=0,B=0
::初始化变量
::以下生成四个不同随机数
set/a count=0
:loop
set /a num=%random%%%10
set/a aa%count%=%num%
set/a count+=1
)
if %count% lss 4 goto loop
for /l %%i in (0,1,9) do set/a BBBB%%i=0
for /l %%e in (0,1,9) do (
for /l %%r in (0,1,3) do (
if %%e equ !aa%%r! (set/a BBBB%%e+=1)))
::至此,生成四个随机数aa0~aa3,并计算其中0~9的个数
:start
echo 你还有%chance%次机会
set/p pp= 输入你所猜的数字
if errorlevel=1 goto seterrorlevel
if %pp% gtr 9999 goto error
if %pp% lss 0 goto error
:: 判断输入数值是否在范围内
for /l %%p in (0,1,3) do ( set/a a%%p=!pp:~%%p,1! 1>nul 2>nul)
if errorlevel=1 goto error
::判断是否位数不够
::把pp的各位的值分别赋给a0,a1,a2,a3
for /l %%q in (0,1,3) do (
if !a%%q! equ !aa%%q! ( set/a A+=1 ))
if %A% equ 4 goto succeed ::如果A=4,说明数字猜对
::计算出数值和位置都正确的树的个数 A
set/a BBB=0,BB=0
for /l %%i in (0,1,9) do set/a BBB%%i=0
for /l %%e in (0,1,9) do (
for /l %%r in (0,1,3) do (
if %%e equ !a%%r! (set/a BBB%%e+=1)))
for /l %%u in (0,1,9) do (
if !BBB%%u! lss !BBBB%%u! ( set/a BB+=!BBB%%u! )
if !BBB%%u! geq !BBBB%%u! ( set/a BB+=!BBBB%%u! ))
set /a B=%BB%-%A%
::计算出数字正确但位置不正确的数的个数B
echo %A%A%B%B
set/a A=0,B=0
::再次清0变量
set/a chance-=1
if %chance% lss 1 goto fail
set pp=
goto start
:succeed
set/a c=8-%chance%
echo 你共猜了%c%次
if %c% leq 5 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 正确答案是 %aa0%,%aa1%,%aa2%,%aa3%
ping /n 2 127.0.0.1>nul
goto exit
:error
color d0
ping /n 1 127.0.0.1>nul
echo Are you stupid??
echo wrong number !!
ping /n 1 127.0.0.1>nul
color f9
goto :start
:seterrorlevel
color d0&color f9&echo 请输入数据
goto start
:exit
exit
[ Last edited by tadonis on 2008-5-23 at 01:22 PM ]
|
ping mm
来自mm的回复:我喜欢你 |
|