我倾向于自己解决大多数事情,但对于我的生活,尽管进行了相当多的搜索,但我无法找到一种专业的方式来做到这一点。
这是我的基本程序:
namespace ConsoleApplication1
{
class MonsterAttackRolls
{
public int GoblinAttack()
{
int AttackNumber = 0;
Random rnd = new Random();
AttackNumber = rnd.Next(1, 21);
return(AttackNumber);
}
public int OrcAttack()
{
int AttackNumber = 0;
Random rnd = new Random();
AttackNumber = rnd.Next(11, 31);
return (AttackNumber);
}
public int OgreAttack()
{
int AttackNumber = 0;
Random rnd = new Random();
AttackNumber = rnd.Next(21, 41);
return (AttackNumber);
}
}
class ApplicationObject
{
static void Main()
{
MonsterAttackRolls Goblin1 = new MonsterAttackRolls();
MonsterAttackRolls Orc1 = new MonsterAttackRolls();
MonsterAttackRolls Ogre1 = new MonsterAttackRolls();
Console.WriteLine("These are the attack numbers for the Goblin and the Orc! {0} {1}", Goblin1.GoblinAttack(), Orc1.OrcAttack());
Console.ReadLine();
Console.WriteLine("This is the Ogre's attack number! {0}", Ogre1.OgreAttack());
Console.ReadLine();
}
}
}
现在我想回到我的 Main() 程序并直接进入 Ogre 的攻击。我怎么做?带goto?大声笑,我不知道。