设置滚动骰子的FOR循环 [英] Set a FOR loop for rolling dice

查看:375
本文介绍了设置滚动骰子的FOR循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我对Yahtzee游戏的另一个问题。我需要设置一个FOR循环运行6次。

 :roll 
cls
暂停
SET / A dice =%RANDOM%%% 6 +1
if%dice%== 1(
echo%dice1a%
echo%dice1b%
echo%dice1c%
echo%dice1d%
echo%dice1e%
echo%dice1f%
echo%dice1g%

if%dice%== 2(
echo%dice2a%
echo%dice2b%
echo%dice2c%
echo%dice2d%
echo%dice2e%
echo%dice2f%
echo%dice2g%

if%dice%== 3(
echo%dice3a%
echo%dice3b%
echo%dice3c%
echo%dice3d%
echo%dice3e %
echo%dice3f%
echo%dice3g%

if%dice%== 4(
echo%dice4a%
echo%dice4b%
echo%dice4c%
echo%dice4d%
echo%dice4e%
echo%dice4f%
echo%dic (
echo%dice5a%
echo%dice5b%
echo%dice5c%
echo%dice5d %
echo%dice5e%
echo%dice5f%
echo%dice5g%

if%dice%== 6(
echo%dice6a%
echo%dice6b%
echo%dice6c%
echo%dice6d%
echo%dice6e%
echo%dice6f%
echo%dice6g%



$ b $ p
$ b

这是我要放在for循环中的代码,我希望它运行6次以回显6个骰子面孔。这只是我所做的代码的一部分。如果你有什么有用的东西可以告诉我(比如说创建一个multistring变量),请评论一个链接,或者告诉我如何去做。

解决方案

而不是使用所有IF使用delayedexpansion引用字体。
通过使用一个伪调用和加倍percentsigns或者使用一个初始的 setlocal enabledelayedexpansion 并且引用var内容和

$ p $ Setlocal EnableDelayedExpansion



$ SET / A dice =%RANDOM%%% 6 +1
echo!dice%dice%a!
回声!骰子%dice%b!
echo!dice%dice%c!
回声!骰子%dice%d!
echo!dice%dice%e!
echo!dice%dice%f!
回声!骰子%骰子%g!



 :roll 
cls
pause
SET / A dice =%RANDOM%%% 6 +1
call echo %% dice%dice%a %%
call echo %% dice%dice%b %%
call echo %% dice%dice%c %%
call echo %% dice%dice%d %%
call echo% %dice%dice%e %%
call echo %% dice%dice%f %%
cALL echo %% dice%dice%g %%


This is another question I have for my Yahtzee game. I need to set a "FOR" loop to run 6 times.

    :roll
    cls
    pause
    SET /A dice=%RANDOM% %%6 +1
      if %dice%==1 (
        echo %dice1a%
        echo %dice1b%
        echo %dice1c%
        echo %dice1d%
        echo %dice1e%
        echo %dice1f%
        echo %dice1g%
      )
      if %dice%==2  (
        echo %dice2a%
        echo %dice2b%
        echo %dice2c%
        echo %dice2d%
        echo %dice2e%
        echo %dice2f%
        echo %dice2g%
      )
      if %dice%==3  (
        echo %dice3a%
        echo %dice3b%
        echo %dice3c%
        echo %dice3d%
        echo %dice3e%
        echo %dice3f%
        echo %dice3g%
      )
      if %dice%==4  (
        echo %dice4a%
        echo %dice4b%
        echo %dice4c%
        echo %dice4d%
        echo %dice4e%
        echo %dice4f%
        echo %dice4g%
      )
      if %dice%==5  (
        echo %dice5a%
        echo %dice5b%
        echo %dice5c%
        echo %dice5d%
        echo %dice5e%
        echo %dice5f%
        echo %dice5g%
      )
      if %dice%==6  (
        echo %dice6a%
        echo %dice6b%
        echo %dice6c%
        echo %dice6d%
        echo %dice6e%
        echo %dice6f%
        echo %dice6g%
        )

This is the code I want to put in a for loop, and I want it to run 6 times to echo 6 dice faces. This is only a part of the code I am making. If you have anything useful to tell me (Like making a multistring variable, for instance), please comment a link, or tell me how to do it.

解决方案

Instead of using all the IFs use delayedexpansion to reference the typefaces. Either by using a pseudo call and doubled percentsigns or with an initial setlocal enabledelayedexpansion and referencing var contents with !

Setlocal EnableDelayedExpansion
:roll
cls
pause
SET /A dice=%RANDOM% %%6 +1
echo !dice%dice%a!
echo !dice%dice%b!
echo !dice%dice%c!
echo !dice%dice%d!
echo !dice%dice%e!
echo !dice%dice%f!
echo !dice%dice%g!

Or

:roll
cls
pause
SET /A dice=%RANDOM% %%6 +1
call echo %%dice%dice%a%%
call echo %%dice%dice%b%%
call echo %%dice%dice%c%%
call echo %%dice%dice%d%%
call echo %%dice%dice%e%%
call echo %%dice%dice%f%%
cALL echo %%dice%dice%g%%

这篇关于设置滚动骰子的FOR循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆