Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#|基于文本的RPG |作战系统&;货币(随机)_C#_Visual Studio_Console Application_Text Based - Fatal编程技术网

C#|基于文本的RPG |作战系统&;货币(随机)

C#|基于文本的RPG |作战系统&;货币(随机),c#,visual-studio,console-application,text-based,C#,Visual Studio,Console Application,Text Based,我目前正在制作我的第一个基于文本的RPG,但我似乎找不到一种制作战斗系统的方法,我目前拥有的是: System.Threading.Thread.Sleep(500); // Stops all code from running for 0.5 second Console.WriteLine("What do you want to do?"); // Fight Screen Console.WriteLine("Attack"); // Attacks enemy Console.Wri

我目前正在制作我的第一个基于文本的RPG,但我似乎找不到一种制作战斗系统的方法,我目前拥有的是:

System.Threading.Thread.Sleep(500); // Stops all code from running for 0.5 second
Console.WriteLine("What do you want to do?"); // Fight Screen
Console.WriteLine("Attack"); // Attacks enemy
Console.WriteLine("Bag"); // Opens your bag - able to use potions and spells (if added)
Console.WriteLine("Block"); // Will block all damage from the next attack but will take away your turn.

string fight = Console.ReadLine(); // If the user types something in the battle screen it will be converted to the "fight" variable used below

if (fight == "Attack") // Attack Code that uses the code above.
{
    enemyHealth[0] = enemyHealth[0] - AtkDmg; // Takes the attack damage from the rat's health giving the rat's health a new value.
    Console.WriteLine("You lunge your sword at the Giant Rat"); // Attack Message
    Console.WriteLine("Giant Rat's Health: " + enemyHealth[0] + " / 10");
    charHealth = charHealth - enemyAtkDmg[0];
    Console.WriteLine("The Giant Rat charges at you, headbutting you, knocking you back.");
    Console.WriteLine("Your Health: " + charHealth + " / 20");
}

if (enemyHealth[0] == 0)
{
    System.Threading.Thread.Sleep(1500);
    Console.WriteLine("You have killed the Giant Rat");
    Console.WriteLine("The Giant Rat Dropped 10 Gold");
    Console.WriteLine("*You pick up the gold and put it in your purse");
}

do{
    gold++;
} while (gold != 10);

Console.Write("You now have " + gold + " Gold Pieces.");
返回OT:

我当前的代码并没有按照我所希望的方式工作,我希望伤害从角色的攻击伤害+1或-1中随机分配,因此如果玩家的攻击伤害为4,他可以造成3、4或5点伤害(5点为暴击)

我还想知道,是否有人知道一种更好的方法,可以将杀死一个怪物所获得的钱从1-10或其他数字随机分配,而不是每次都设置为10

如果你需要任何其他资源,我可能有,请留下一个评论,我会给你任何你需要的,如果它可以帮助你找到一些答案


如果您想办法改进我的代码或使其更整洁,请留下评论。

对于随机化,您可以使用
Random
类。您可以指定一个最小值和一个最大值,并基于此获得一个随机数

        Random randomNumber = new Random();
        int playerDamage = 5;

        var gold = randomNumber.Next( 1, 11 );//For gold
        var damage = randomNumber.Next( playerDamage - 1, playerDamage + 2 );//For damage

“最大值”看起来太高的原因是“最大值”本身不包含在“随机”中,而只包含在该点之前。因此,如果最大可能值应该是10,那么
随机变量中的最大值应该是11。

如果你不喜欢,至少解释一下原因。.你做过任何研究吗?你找到钥匙了吗?你试过用它做什么吗?而且,这显然是重复的。回答问题也是如此。要请求任何评论或批评,您应该将代码发布到@AnthonyP仔细查看我的代码,我使用1个随机变量创建2个随机值。根据怪物的生命值/等级/无论什么,每次都要这样做:)