![](/img/trans.png)
[英]method must have a return type pointing to NewCall Handler class in my code. What am i missing
[英]Why am I getting "Method must have a return type"?
所以,我今天下午开始尝试学习 C#。 我一直在玩 Fallout Shelter 并且很想制作我自己的 Dwellers Wasteland Exploration 部分的 Carbon 副本,然后我可以最终调整和扩展。
我有 Program.cs、Speech.cs 和 Events.cs
program.cs 调用 Speech.cs 来显示每个“回合”的随机句子。 然后它意味着调用 events.cs 来确定每个“回合”的事件类型。
问题是我似乎无法让事件方法起作用。 它一直说 Method 必须有一个返回类型。
Speech 方法似乎工作得很好,但回想起来,我认为我并没有真正理解我所做的。
任何帮助,将不胜感激。
代码如下。
程序.cs
using System;
namespace Roaming
{
class MainClass
{
public static void Main (string[] args)
{
//Declare Variables
int milliseconds = 1000;
int currenthp = 100;
int maxhp = 100;
string eventGet;
do {
Console.WriteLine("Your HP is at {0}/{1} \n", currenthp, maxhp);
Random random = new Random();
int randomNumber = random.Next(0,100);//Random roll do determine event
if(randomNumber > 50)
{
Roaming.typeOfEvent();
}
else
{
Console.WriteLine ( Speech.GetRandom() );//Random Speech
}
System.Threading.Thread.Sleep (milliseconds);//Timer Delay
Console.Clear();
} while(currenthp > 0);
}
}
}
Speech.cs
using System;
using System.Collections.Generic;
namespace Roaming
{
public class Speech
{
private static readonly List<string> sentences = new List<string>()
{
"It's so cold out here.",
"I don't know where to go.",
"Is that a finger?",
"I have a pain in my Stomach.",
"I'm sure I saw something move.",
"Saw a Guard Dog, watching the area.",
"I'm bleeding a little.",
"I feel a little faint.",
"I should have brought a book.",
"How are things back at base I wonder.",
"I wonder what's over there.",
"I want to head back soon.",
"Theres a lot of noise coming from over there.",
"I think there's the remnants of what was once a village over there.",
"Are Feral Ghouls real?",
"Theres something wirtten in the wall ehre but I can't make it out.",
"I can see a RadScorpion",
"I think I'm lost.",
"I wonder if the radiation has created Zombies.",
"I am so hungry.",
"Anyone nearby could probably hear my stomach rumbling.",
"Ooh, that was a good fart.",
"Could really do with some water.",
"There's something strange moving in the sky."
};
private static readonly Random rangomGenerator = new Random();
public static string GetRandom()
{
int max = sentences.Count-1;
int randomNumber = rangomGenerator.Next(max);
return sentences[randomNumber];
}
}
}
事件.cs
using System;
using System.Collections.Generic;
namespace Roaming
{
public class eventType
{
public static typeOfEvent(string eventGet)
{
//Determining the type of event
Random random = new Random();
int randomNumber = random.Next(0,100);//Random roll do determine event
if(randomNumber > 95)
{
Console.WriteLine("Find Weapon.");
}
else if(randomNumber > 90)
{
Console.WriteLine("You found a stimpak");
}
else if(randomNumber > 70)
{
Console.WriteLine("You were attacked");
}
else
{
Console.WriteLine("You continue to explore");
}
}
}
}
正如所述,您需要一个返回类型,如果您不返回任何内容,它应该是void
。
public static void typeOfEvent(string eventGet)
修改签名如下
public static void typeOfEvent(string eventGet)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.