Trying to randomly generate and save village scenarios in a list for a game project with the following code but I keep getting "'Village.StandardVillage()': not all code paths return a value" error. I've tried fixing it a couple of different ways but end up with other errors. So far this is what I have:
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;
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire