bat简单游戏代码
时间: 2023-07-03 09:13:24 浏览: 166
以下是一个简单的扑克牌游戏的BAT代码示例:
```
@echo off
setlocal enabledelayedexpansion
set suits=♠ ♥ ♣ ♦
set values=2 3 4 5 6 7 8 9 10 J Q K A
set /a count=0
for %%s in (%suits%) do (
for %%v in (%values%) do (
set /a count+=1
set "card[!count!]=%%v%%s"
)
)
set /a decksize=count
echo There are %decksize% cards in the deck.
:shuffle
for /l %%n in (%decksize%,-1,2) do (
set /a "k=!random! %% %%n + 1"
set "temp=!card[%%n]!"
set "card[%%n]=!card[%%k]!"
set "card[%%k]=!temp!"
)
echo The deck has been shuffled.
:deal
set /a handsize=5
for /l %%n in (1,1,%handsize%) do (
set /a "cardnum=%%n - 1"
set "hand[%%n]=!card[!cardnum!]!"
)
echo Your hand is: %hand%
pause
```
这个代码会生成一副扑克牌,然后洗牌并发给你 5 张牌。你可以根据需要对代码进行修改以适应你的游戏规则。
阅读全文