C# 如何修复返回错误I';我从这个生成器代码中得到了什么?
尝试使用以下代码在游戏项目的列表中随机生成并保存村庄场景,但我不断收到“'village.standardlavillage()':并非所有代码路径都返回值”错误。我尝试了几种不同的方法来修复它,但最终还是出现了其他错误。到目前为止,这就是我所拥有的:C# 如何修复返回错误I';我从这个生成器代码中得到了什么?,c#,random,C#,Random,尝试使用以下代码在游戏项目的列表中随机生成并保存村庄场景,但我不断收到“'village.standardlavillage()':并非所有代码路径都返回值”错误。我尝试了几种不同的方法来修复它,但最终还是出现了其他错误。到目前为止,这就是我所拥有的: public class Village { public string name; public int setLandscape; public int setTool1; public int setTool
public class Village
{
public string name;
public int setLandscape;
public int setTool1;
public int setTool2;
public Village(string name, int setLandscape, int setTool1, int setTool2)
{
this.name = name;
this.setLandscape = setLandscape;
this.setTool1 = setTool1;
this.setTool2 = setTool2;
}
private static List<Village> VisitedVillages = new List<Village>();
public static Village StandardVillage()
{
var randVillage = new Random();
string name = GenerateCoolVillageName();
var village = new Village( //make random village
name: name,
setLandscape: randVillage.Next(1, 5),
setTool1: randVillage.Next(1, 3),
setTool2: randVillage.Next(1, 3)
);
VisitedVillages.Add(village); //store village in ram so it can be revisited later
VisitVillage(
village.setLandscape,
village.setTool1,
village.setTool2
);
}
internal static string GenerateCoolVillageName()
=> $"Village {VisitedVillages.Count + 1}";
private static void VisitVillage(int setLandscape, int setTool1, int setTool2)
{
string villageOptions;
do
{
if (setLandscape == 1)
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(" (________________)");
Console.WriteLine(" | |");
Console.WriteLine(" | [] [] [] |");
Console.WriteLine(" _______|____ |");
Console.WriteLine(" | | [] [] | ");
Console.WriteLine(" | { } { } | | _I_____");
Console.WriteLine(" | | [] [] | /_______\\");
Console.WriteLine(" | { } { } | | | [] [] |");
Console.WriteLine("_| | [] [] |___| [] [] |_");
Console.WriteLine("-----------------------------------------");
}
if (setLandscape == 2)
{
Console.WriteLine();
Console.WriteLine(" xXxXxXxXxXxXx ");
Console.WriteLine(" | | ");
Console.WriteLine(" | |}{| |}{| | ");
Console.WriteLine(" ____________ | | ");
Console.WriteLine(" | | | |}{| |}{| | _I_____");
Console.WriteLine(" | [] [] | | | /_______\\");
Console.WriteLine(" | | | |}{| |}{| | _ | [] [] |");
Console.WriteLine("_| [] [] |__| |__|_| [] [] |_");
Console.WriteLine("----------------------------------------------");
}
if (setLandscape == 3)
{
Console.WriteLine();
Console.WriteLine(" {_{_{_{_}_}_}_}");
Console.WriteLine(" / \\");
Console.WriteLine(" /_______________\\");
Console.WriteLine(" _I_____ | |");
Console.WriteLine(" /_______\\ | {} {} {} {} |");
Console.WriteLine(" | [] [] | | | (__)");
Console.WriteLine("xX| [] [] |Xx__| {} {} {} {} |___()_");
Console.WriteLine("------------------------------------------");
}
if (setLandscape == 4)
{
Console.WriteLine();
Console.WriteLine(" {____________}");
Console.WriteLine(" | |");
Console.WriteLine(" __________________ | [}{] [}{] |");
Console.WriteLine(" | | | |");
Console.WriteLine(" | [] [] [] [] [] | | [}{] [}{] | ____");
Console.WriteLine(" | | | | |__|");
Console.WriteLine("_| [] [] [] [] [] |__| [}{] [}{] |_| |");
Console.WriteLine("--------------------------------------------");
}
if (setTool1 == 1)
{
Console.WriteLine("1) Speak to someone in charge");
}
if (setTool1 == 2)
{
Console.WriteLine("1) Ask about local rumors");
}
if (setTool2 == 1)
{
Console.WriteLine("2) Go to the local guild hall");
}
if (setTool2 == 2)
{
Console.WriteLine("2) Go to the local tavern");
}
Console.WriteLine("0) Exit to map");
villageOptions = Console.ReadLine();
Console.Clear();
if (villageOptions == "1" && setTool1 == 1)
{
Console.WriteLine("The elderman of the village greets you cheerily.");
}
if (villageOptions == "1" && setTool1 == 2)
{
Console.WriteLine("A local indulges you.");
Console.WriteLine("\"I hear the local tavern cooks a mean birdpie.\"");
}
if (villageOptions == "2" && setTool2 == 1)
{
Console.WriteLine("You approach the local guild hall. The sign on the building reads:");
Console.WriteLine("\"Jiu-jitsu Guild\"");
}
if (villageOptions == "2" && setTool2 == 2)
{
Console.WriteLine("You approach the local tavern, the taste of whiskey already on ");
Console.WriteLine("your lips.");
}
if (villageOptions == "0")
{
Console.Clear();
return;
}
Console.ReadLine();
Console.Clear();
}
while (villageOptions != "0");
}
internal static void RevisitAVillage()
{
int count = VisitedVillages.Count;
if (count == 0)
{
Console.WriteLine("You currently haven't visited any villages");
Console.WriteLine("Press any key to return to map");
Console.ReadLine();
Console.Clear();
return;
}
Console.WriteLine("Which village do you wanna revisit?");
Console.WriteLine();
for (int i = 0; i < VisitedVillages.Count; i++)
{
Console.Write(i + 1);
Console.Write(") ");
Console.WriteLine(VisitedVillages[i].name);
}
string picked_village_input = Console.ReadLine();
int input_as_int = int.Parse(picked_village_input) - 1;
var village = VisitedVillages[input_as_int];
Console.Clear();
VisitVillage(
village.setLandscape,
village.setTool1,
village.setTool2
);
bool exitMap = true;
while (exitMap == false)
{
Console.WriteLine("This is your map");
Console.WriteLine();
Console.WriteLine("0) Revisit a town");
Console.WriteLine("1) Search for a new location");
string newLocation = Console.ReadLine();
Console.Clear();
if (newLocation == "0")
{
Village.RevisitAVillage();
}
if (newLocation == "1")
{
Village.StandardVillage();
}
if (newLocation == "2")
{
exitMap = true;
}
}
}
}
公营村
{
公共字符串名称;
公共景观;
公共int setTool1;
公共int setTool2;
公共村庄(字符串名称、int-setscape、int-setTool1、int-setTool2)
{
this.name=名称;
this.set横向=set横向;
this.setTool1=setTool1;
this.setTool2=setTool2;
}
私有静态列表VisitedVillages=新列表();
公共静态村庄标准村庄()
{
var randVillage=新随机数();
字符串名称=generateColvillagename();
var village=新村庄(//随机创建村庄
姓名:姓名,,
场景:兰德村。下一个(1,5),
setTool1:randVillage.Next(1,3),
setTool2:randVillage.Next(1,3)
);
VisitedVillages.Add(village);//将村庄存储在ram中,以便以后可以再次访问
参观农场(
乡村景观,
村庄1,
村庄2.setTool2
);
}
内部静态字符串GenerateColvillagename()
=>$“村庄{VisitedVillages.Count+1}”;
私有静态void VisitVillage(int-setscape、int-setTool1、int-setTool2)
{
串别墅;
做
{
如果(设置横向==1)
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(“(_____________________;
Console.WriteLine(“| |”);
Console.WriteLine(“|[]]|”);
Console.WriteLine(“___|u__|u__|u_;u|”);
Console.WriteLine(“| |[][]]|”);
Console.WriteLine(“|{}{}|||||iUUUUUUUUUU”);
Console.WriteLine(“| |[]]./| | | | | | | | | | | | | | | | 124;
Console.WriteLine(“|{}{}| | |【】【】【】】”;
Console.WriteLine(“| |【】【】【】【】【】【】【】【】【】【】【】【】【】】);
Console.WriteLine(“-------------------------------------------------”;
}
如果(设置横向==2)
{
Console.WriteLine();
控制台写入线(“XXXXXXXXXXXX”);
Console.WriteLine(“| |”);
Console.WriteLine(“| |}{| |}{| |”);
Console.WriteLine(“uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;
Console.WriteLine(“| | | | |}{| |}{| | | | | | I | |”);
Console.WriteLine(“|[][]| | | |/uuuuuuuuuuuuu\\”);
Console.WriteLine(“| | | | |}{| |}{| | | |[][]|”);
Console.WriteLine(“124;【】【】【】【】【】【】【】【】【】【】【】【】【】【】【】【】【】】;
Console.WriteLine(“-------------------------------------------------------------”;
}
如果(设置横向==3)
{
Console.WriteLine();
Console.WriteLine(“{{{{{{}}}}}”);
Console.WriteLine(“/\ \”);
Console.WriteLine(“/\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;
Console.WriteLine(“_I_____|||”);
Console.WriteLine(“/\ \ \ \ \ \{{}{}{}}}{}}{124;”;
Console.WriteLine(“|[]][| | | |(uuuu)”);
Console.WriteLine(“xX |[]]| xX |{{}{}{}}{}}|}());
Console.WriteLine(“------------------------------------------------”);
}
如果(设置横向==4)
{
Console.WriteLine();
Console.WriteLine(“{uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu}”);
Console.WriteLine(“| |”);
Console.WriteLine(“uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu124;[}{][}{]}}{][]};”;
Console.WriteLine(“| | | | |”);
Console.WriteLine(“|[…][…]| |[}{][}{][}{]| uuuuuuuuu”);
Console.WriteLine(“| | | | | | | |”);
Console.WriteLine(“124;【】【】【】【】【】【】【】【】【】【】【】【】【】【】【】【】【】【】【】【】【】【】】;
Console.WriteLine(“--------------------------------------------------”);
}
if(setTool1==1)
{
Console.WriteLine(“1)与负责人交谈”);
}
如果(setTool1==2)
{
Console.WriteLine(“1)询问当地谣言”);
}
如果(setTool2==1)
{
Console.WriteLine(“2)前往当地会馆”);
}
if(setTool2==2)
{
Console.WriteLine(“2)去当地的酒馆”);
}
Console.WriteLine(“0)退出映射”);
villageOptions=Console.ReadLine();
Console.Clear();
如果(villageOptions==“1”&&setTool1==1)
{
控制台。WriteLine(“村里的老人高兴地向你打招呼。”);
}
如果(villageOptions==“1”&&setTool1==2)
{
WriteLine(“一个本地人纵容你”);
Console.WriteLine(“\”我听说当地的酒馆煮了一只卑鄙的鸟。\”);
}
如果(villageOptions==“2”&&setTool2==1)
{
控制台。WriteLine(“你走近当地的会馆。建筑上的标志写着:”);
Console.WriteLine(“柔术协会”);
}
如果(villageOptions==“2”&&setTool2==2)
public static Village StandardVillage()
{
var randVillage = new Random();
string name = GenerateCoolVillageName();
var village = new Village( //make random village
name: name,
setLandscape: randVillage.Next(1, 5),
setTool1: randVillage.Next(1, 3),
setTool2: randVillage.Next(1, 3)
);
VisitedVillages.Add(village); //store village in ram so it can be revisited later
VisitVillage(
village.setLandscape,
village.setTool1,
village.setTool2
);
return village;
}
public static void StandardVillage()
{
var randVillage = new Random();
string name = GenerateCoolVillageName();
var village = new Village( //make random village
name: name,
setLandscape: randVillage.Next(1, 5),
setTool1: randVillage.Next(1, 3),
setTool2: randVillage.Next(1, 3)
);
VisitedVillages.Add(village); //store village in ram so it can be revisited later
VisitVillage(
village.setLandscape,
village.setTool1,
village.setTool2
);
}