骰子滚动游戏 [英] Dice roll game
问题描述
嗨!
我正在尝试创建一个骰子滚动模拟器。
I am trying to create a dice roll simulator.
使用下面的代码我如何:
With the code below how do I:
1。如果用户掷出6,则该数字不会被添加到总和中,但允许它们滚动两次,将这些骰子的总和加到总和中。
1. If the user rolls a 6 that number is not added to the sum but they are allowed to roll twice, adding the sum of those die to the total sum.
2。最后,打印卷数和所有卷的总和
2. At the end, print the number of rolls and total sum of all the rolls
使用 系统 ;
名称空间 EnLoop
{
class MainClass
{
public 静态 void 主要 ( string [] args )
{
Console < span style ="color:#222222">。 WriteLine ( "如果
你想投掷多少?" );
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的串跨度>&NBSP;的 numberofThrowsstring 跨度>&NBSP;的 = 跨度>&NBSP;的控制台跨度> <跨度style ="color:#222222">。 ReadLine ();
控制台 。 WriteLine ( "很好,
使得< + numberofThrowsstring 跨度>&NBSP;&NBSP;的的 + 跨度>的 " throws。" );
控制台 。 ReadKey ();
int numberofThrows&NBSP; 跨度>的 =&NBSP; 跨度>的 INT 跨度>的。 Parse ( numberofThrowsstring); 跨度>&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&N BSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&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BSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的 < span style ="color:#222222">);
随机 < span style ="color:#222222"> rnd = new 随机 ();
int sum = < span style ="color:#db7100"> 0 ;
while ( numberofThrows > 0 )
{
int randomRoll = rnd 。 下一步 ( 1 , 7 );
if ( randomRoll == 6 )
using System;
namespace EnLoop
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("How
many die would you like to throw?");
string numberofThrowsstring = Console.ReadLine();
Console.WriteLine("Nice, that
makes " + numberofThrowsstring +" throws.");
Console.ReadKey();
int numberofThrows = int.Parse(numberofThrowsstring); );
Random rnd = newRandom();
int sum=0;
while(numberofThrows > 0)
{
int randomRoll = rnd.Next(1,7);
if (randomRoll == 6)
{
控制台 。 WriteLine ( "您&NBSP;热轧&NBSP; A&NBSP; 6,&NBSP;你&NBSP;获得&NBSP;至&NBSP;辊&NBSP;所述&NBSP;模具&NBSP;二&NBSP;倍" 跨度>的);
}
{
Console.WriteLine("You rolled a 6, you get to roll the die two times.");
}
else
{
sum = sum + randomRoll ;
控制台 。 WriteLine ( "你已经滚动" + randomRoll + " 和
总和是现在: " + sum );
}
numberofThrows = numberofThrows - 1 ;
}
控制台 。 WriteLine ( numberofThrows );
}
}
}
else
{
sum = sum + randomRoll;
Console.WriteLine("You have rolled "+randomRoll+" and
the sum is now: "+sum);
}
numberofThrows = numberofThrows - 1;
}
Console.WriteLine(numberofThrows);
}
}
}
推荐答案
除非我在这里忽略了这一点,否则滚动6的净效果是你得到2次额外的投掷。 所以,只是在numberofThrows中添加2。
Unless I'm missing the point here, the net effect of rolling a 6 is that you get 2 extra throws. So, just add 2 to numberofThrows.
这篇关于骰子滚动游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!