以下是一个实现石头剪刀布文字游戏的BAT文件代码:

@echo off
setlocal enabledelayedexpansion

set /a wins=0
set /a losses=0
set /a ties=0

echo 欢迎来到石头剪刀布游戏!

:game
echo.
echo 请选择你的手势:
echo 1. 石头
echo 2. 剪刀
echo 3. 布
echo 4. 退出游戏

set /p choice=输入选择的数字: 

if '%choice%'=='1' (
    set player=石头
) else if '%choice%'=='2' (
    set player=剪刀
) else if '%choice%'=='3' (
    set player=布
) else if '%choice%'=='4' (
    goto end
) else (
    echo 无效的选择,请重新输入。
    goto game
)

set /a computer=%random% %% 3 + 1

if '%computer%'=='1' (
    set computer_gesture=石头
) else if '%computer%'=='2' (
    set computer_gesture=剪刀
) else (
    set computer_gesture=布
)

echo.
echo 你选择了:%player%
echo 电脑选择了:%computer_gesture%
echo.

if '%player%'=='%computer_gesture%' (
    echo 结果:平局!
    set /a ties+=1
) else if '%player%'=='石头' (
    if '%computer_gesture%'=='剪刀' (
        echo 结果:你赢了!
        set /a wins+=1
    ) else (
        echo 结果:你输了!
        set /a losses+=1
    )
) else if '%player%'=='剪刀' (
    if '%computer_gesture%'=='布' (
        echo 结果:你赢了!
        set /a wins+=1
    ) else (
        echo 结果:你输了!
        set /a losses+=1
    )
) else (
    if '%computer_gesture%'=='石头' (
        echo 结果:你赢了!
        set /a wins+=1
    ) else (
        echo 结果:你输了!
        set /a losses+=1
    )
)

echo.
echo 当前战绩:
echo 胜利:%wins%
echo 失败:%losses%
echo 平局:%ties%
echo.

goto game

:end
echo 游戏结束。谢谢参与!
endlocal

这个BAT文件会显示一个菜单,让你选择石头、剪刀、布或退出游戏。然后,它会比较你的选择和电脑的选择,并显示结果。游戏将继续进行,直到你选择退出游戏为止。最后,它会显示你的胜利、失败和平局的统计结果。


原文地址: https://www.cveoy.top/t/topic/pLmX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录