public static void Load(List <Thing> LivingThings, List <Thing> BathThings, List <string> Invent, UserInteractions interactions) { List <LoadedData> LivingThingsL = new List <LoadedData>(); List <LoadedData> BathThingsL = new List <LoadedData>(); List <string> InvL = new List <string>(); // DataRetun Recive = new DataRetun(bath: BathThings, living: LivingThings, inv: Invent); string Filename = interactions.Item1; try { if (File.Exists(Filename) == true) { string[] content = File.ReadAllLines(Filename.ToString()); char[] splitting = { ' ', ';' }; foreach (var sor in content) { string[] temp = sor.Split(splitting); if (sor != null) { if (temp.Length == 4 && temp[3] == "nappali") { LivingThingsL.Add(new LoadedData(temp[0], bool.Parse(temp[1]), bool.Parse(temp[2]))); } else if (temp.Length == 4 && temp[3] == "Fürdő") { BathThingsL.Add(new LoadedData(temp[0], bool.Parse(temp[1]), bool.Parse(temp[2]))); } else if (temp.Length == 2 && temp[0] == "Invertory") { InvL.Add(temp[1]); } } } if (!(LivingThingsL.Count == 0 || BathThingsL.Count == 0)) { foreach (var thing in LivingThings) { foreach (var thingL in LivingThingsL) { if (thing.Name == thingL.Name) { thing.IsChecked = thingL.IsChecked; thing.IsOpen = thingL.IsOpen; } } } foreach (var thing in BathThings) { foreach (var thingL in BathThingsL) { if (thing.Name == thingL.Name) { thing.IsChecked = thingL.IsChecked; thing.IsOpen = thingL.IsOpen; } } } if (InvL.Count != 0) { for (int i = 0; i < InvL.Count; i++) { if (Invent.Count != 0) { for (int j = 0; j < Invent.Count; j++) { if (!Invent.Contains(InvL[i])) { Invent.Add(InvL[i]); } else if (!InvL.Contains(Invent[j])) { Invent.Remove(Invent[j]); } } } else { Invent.Add(InvL[i]); } } } interactions.Response = "A(z)" + interactions.Item1 + "fájl betöltése sikeres volt."; } } else if (!File.Exists(Filename)) { interactions.Response = "A megadott file nem létezik."; } } catch (Exception ex) { interactions.Response = ex.Message.ToString(); } }
public static void Save(List <string> Invertory, List <Thing> LivingRoomThings, List <Thing> BathroomThings, UserInteractions interactions) { string Filename = interactions.Item1; try { using (StreamWriter writer = new StreamWriter(Filename)) { foreach (var thing in LivingRoomThings) { writer.WriteLine(thing.Name + " " + thing.IsOpen + " " + thing.IsChecked + " " + "nappali"); } foreach (var thing in BathroomThings) { writer.WriteLine(thing.Name + " " + thing.IsOpen + " " + thing.IsChecked + " " + "Fürdő"); } foreach (var item in Invertory) { writer.WriteLine("Invertory" + " " + item); } } interactions.Response = "Sikeres mentés"; } catch (Exception e) { interactions.Response = e.Message.ToString(); } }
public static string LivingOnGame(UserInteractions interactions, List <string> Invertory, List <Thing> LivingRoomThings) { switch (interactions.Command) { case "nézd": switch (interactions.Item1) { case "": return(interactions.Response = "A nappaliban vagy. Északra található egy szekrény és Keletre egy Ágy. Nyugatra látsz egy ajtót."); case "ablak": foreach (var thing in LivingRoomThings) { foreach (var func in thing.Functions) { if (interactions.Command == func.Key && thing.Name == "ablak") { foreach (var Container in LivingRoomThings) { if (Container.Name == thing.Container && Container.IsChecked == true) { return(interactions.Response = func.Value); } } } } } if (interactions.Response == "") { return(interactions.Response = "A(z) " + interactions.Item1 + " tárgyat nem látom."); } break; default: foreach (var thing in LivingRoomThings) { if (interactions.Item1 == thing.Name) { foreach (var func in thing.Functions) { if (interactions.Command == func.Key) { if (thing.IsInSomething) { foreach (var Container in LivingRoomThings) { if (Container.Name == thing.Container && Container.IsOpen == true) { return(interactions.Response = func.Value); } } } else { return(interactions.Response = func.Value); } } } } } if (interactions.Response == "") { return(interactions.Response = "A(z) " + interactions.Item1 + " tárgyat nem látom"); } break; } break; case "menj": switch (interactions.Item1) { case "észak": return(interactions.Response = "Elötted van egy szekrény."); case "dél": return(interactions.Response = "Délnek nem tudsz menni arra nincs kijárat."); case "kelet": return(interactions.Response = "Eöltted van egy ágy."); case "nyugat": var ajtó = (from x in LivingRoomThings where (x.Name == "ajtó")select(x)).FirstOrDefault(); if (ajtó.IsOpen == true) { interactions.Room = "fürdő"; return(interactions.Response = "A fürdő szobában vagy itt található egy kád."); } else { return(interactions.Response = "Az utadat egy zárt ajtó állja."); } default: return(interactions.Response = "Ismeretlen irány!"); } case "nyisd": foreach (var thing in LivingRoomThings) { foreach (var func in thing.Functions) { if (interactions.Item1 == thing.Name && interactions.Command == func.Key && thing.IsOpenable == true && !(interactions.Item1 == "ajtó" || interactions.Item2 == "kulcs")) { thing.IsOpen = true; return(interactions.Response = func.Value); } } } if (interactions.Response == "") { if (interactions.Item1 == "ajtó" && interactions.Item2 == "kulcs" && Invertory.Contains("kulcs")) { foreach (var thing in LivingRoomThings) { foreach (var func in thing.Functions) { if (interactions.Command == func.Key && interactions.Item1 == thing.Name && thing.IsOpenable == true) { thing.IsOpen = true; return(interactions.Response = func.Value); } } } } if (interactions.Response == "" && interactions.Item1 == "ajtó" && interactions.Item2 == "kulcs") { return(interactions.Response = "Az ajtó kinyitásához fel kell vegyél egy kulcsot."); } else if (interactions.Response == "") { if (interactions.Item1 != "") { if (interactions.Item1 != "" && interactions.Item2 != "") { return(interactions.Response = "A(z) " + interactions.Item1 + " tárgyat a(z) " + interactions.Item2 + " tárggyal nem tudom kinyitni."); } else { return(interactions.Response = "A(z) " + interactions.Item1 + " tárgyat nem tudom kinyitni."); } } else { return(interactions.Response = "A parancs használatához addj meg egy tárgyat amit ki akarsz nyitni."); } } } break; case "veddfel": foreach (var thing in LivingRoomThings) { foreach (var func in thing.Functions) { if (interactions.Item1 == thing.Name && interactions.Command == func.Key && thing.IsMooveable) { Invertory.Add(thing.Name.ToString()); return(interactions.Response = func.Value); } } } if (interactions.Response == "") { return(interactions.Response = "A(z) " + interactions.Item1 + " tárgyat nem tudom felvenni."); } break; case "teddle": foreach (var thing in LivingRoomThings) { foreach (var func in thing.Functions) { if (thing.Name == interactions.Item1 && interactions.Command == func.Key && Invertory.Contains(thing.Name)) { Invertory.Remove(thing.Name); return(interactions.Response = func.Value); } } } if (interactions.Response == "") { return(interactions.Response = "A(z) " + interactions.Item1 + " tárgya nincs a birtokodban."); } break; case "húzd": foreach (var thing in LivingRoomThings) { foreach (var func in thing.Functions) { if (thing.Name == interactions.Item1 && interactions.Command == func.Key && thing.IsPulleable) { thing.IsChecked = true; return(interactions.Response = func.Value); } } } if (interactions.Response == "") { return(interactions.Response = "A(z) " + interactions.Item1 + " tárgyat nem tudom elhúzni."); } break; case "törd": if ((interactions.Item1 == "ablak" && interactions.Item2 == "feszítővas" && Invertory.Contains("feszítővas")) || (interactions.Item1 == "feszítővas" && interactions.Item2 == "ablak" && Invertory.Contains("feszítővas"))) { foreach (var thing in LivingRoomThings) { foreach (var func in thing.Functions) { if (interactions.Command == func.Key && thing.Breakable == true) { foreach (var Container in LivingRoomThings) { if (Container.Name == thing.Container && Container.IsChecked) { return(interactions.Response = func.Value); } } } } } } if (interactions.Response == "" && interactions.Item1 == "ablak" && interactions.Item2 == "feszítővas" && !Invertory.Contains("feszítővas") || interactions.Item2 == "feszítővas" && interactions.Item1 == "ablak" && !Invertory.Contains("feszítővas")) { return(interactions.Response = "A feszítővas nincs a birtokodban."); } else if (interactions.Response == "" && interactions.Item1 == "ablak" || interactions.Item2 == "ablak") { var szekrenyElvaneHuzva = (from x in LivingRoomThings where (x.Name == "szekrény")select(x)).FirstOrDefault(); if (szekrenyElvaneHuzva.IsChecked == true) { return(interactions.Response = "Az ablakot nem tudom kézzel betörni, mert megsérülök "); } else if (interactions.Response == "") { return(interactions.Response = "Az " + interactions.Item1 + " tárgyat nem találom az összetöréshez"); } } else if (interactions.Response == "") { return(interactions.Response = "A(z) " + interactions.Item1 + " tárgyat nem tudom betörni."); } break; default: if (interactions.Command == "") { return(interactions.Response = "Kérlek adj meg egy parancsot!"); } else if (interactions.Response == "") { return(interactions.Response = "Ismeretlen parancs, kérlek próbálkozz egy érvényes paranccsal!"); } break; } return(interactions.Response = "Váratlan hiba lépett fel!"); }
public static string BathOnGame(UserInteractions interactions, List <string> Invertory, List <Thing> BathroomThings) { switch (interactions.Command) { case "nézd": switch (interactions.Item1) { case "": interactions.Response = "A fürdőben vagy. Délre található egy kád, valamint Keletre egy ajtó amin átjöttél."; break; default: foreach (var thing in BathroomThings) { if (interactions.Item1 == thing.Name) { foreach (var func in thing.Functions) { if (interactions.Command == func.Key) { if (thing.IsInSomething) { foreach (var Container in BathroomThings) { if (Container.Name == thing.Container && Container.IsChecked == true) { interactions.Response = func.Value; thing.IsChecked = true; break; } } } else { interactions.Response = func.Value; thing.IsChecked = true; } } } } } if (interactions.Response == "") { interactions.Response = "A(z) " + interactions.Item1 + " tárgyat nem látom."; } break; } break; case "menj": switch (interactions.Item1) { case "észak": interactions.Response = "Északra nem tudsz menni, arra nincs kijárat."; break; case "dél": interactions.Response = "Eöltted van egy Kád."; break; case "kelet": interactions.Response = "A nappaliban vagy"; interactions.Room = "nappali"; break; case "nyugat": interactions.Response = "Nyugatnak nem tudsz menni, arra nincs kijárat."; break; default: break; } break; case "nyisd": foreach (var thing in BathroomThings) { foreach (var func in thing.Functions) { if (thing.Name == interactions.Item1 && interactions.Command == func.Key && thing.IsOpenable == true && (interactions.Item1 != "ajtó" || interactions.Item2 != "ajtó")) { thing.IsOpen = true; interactions.Response = func.Value; break; } } } if (interactions.Response == "") { if (interactions.Item1 == "ajtó" && interactions.Item2 == "kulcs" && Invertory.Contains("kulcs") || interactions.Item1 == "kulcs" && interactions.Item2 == "ajtó" && Invertory.Contains("kulcs")) { interactions.Response = "Az ajtó nyitva van"; } else { interactions.Response = "A(z) " + interactions.Item1 + " tárgyat nem tudom kinyitni."; } } break; case "veddfel": foreach (var thing in BathroomThings) { foreach (var func in thing.Functions) { if (interactions.Command == func.Key) { if (thing.IsInSomething) { foreach (var Container in BathroomThings) { if (Container.Name == thing.Container && Container.IsChecked == true) { interactions.Response = func.Value; Invertory.Add(thing.Name.ToString()); break; } } } } } } if (interactions.Response == "") { interactions.Response = "A(z) " + interactions.Item1 + " tárgyat nem tudom felvenni"; } break; case "teddle": foreach (var thing in BathroomThings) { foreach (var func in thing.Functions) { if (thing.Name == interactions.Item1 && interactions.Command == func.Key && Invertory.Contains(thing.Name)) { interactions.Response = func.Value; Invertory.Remove(thing.Name); break; } } } if (interactions.Response == "") { interactions.Response = "A(z) " + interactions.Item1 + " tárgya nincs a birtokodban."; } break; case "húzd": foreach (var thing in BathroomThings) { foreach (var func in thing.Functions) { if (thing.Name == interactions.Item1 && interactions.Command == func.Key && thing.IsMooveable) { interactions.Response = func.Value; } } } if (interactions.Response == "") { interactions.Response = "A(z) " + interactions.Item1 + " tárgyat nem tudom elhúzni."; } break; case "törd": return(interactions.Response = "Ez a parancs itt nem elérhető"); default: if (interactions.Command == "") { interactions.Response = "Kérlek adj meg egy parancsot!"; } else if (interactions.Response == "") { interactions.Response = "Ismeretlen parancs, kérlek próbálkozz egy érvényes paranccsal!"; } break; } return(interactions.Response); }
static void Main(string[] args) { try { UserInteractions interactions = new UserInteractions(response: "", command: "", item1: "", item2: "", room: "nappali", Invertory); Living.Init(LivingRoomThings); Bath.Init(BathroomThings); string[] parancsok = { "menj", "nézd", "veddfel", "teddle", "nyisd", "húzd", "törd", "leltár", "mentés", "betöltés" }; string read = ""; Console.WriteLine("Üdvözöllek a szabaduló szoba játékban!"); Console.WriteLine(); Console.WriteLine("A helyszín egy lakás a cél hogy kijuss. "); Console.WriteLine("A játék során a parancsok a következők:"); foreach (var item in parancsok) { Console.WriteLine(item); } Console.WriteLine(); Console.WriteLine("A menj parancs a észak, dél, kelet, nyugat használatával működik "); Console.WriteLine("A nézd parancs tárgy megadásával a tárgyról ad részletes leírást,"); Console.WriteLine("Önmagában viszont az adott helyszínről ahol tartózkodsz"); Console.WriteLine("Fontos, hogy egy parancsnál minding tegyél szóközt a szavak közé ezalól csak az összetett szavak képeznek kivételt pl:"); Console.WriteLine("vedd fel / tedd le. => helyesen teddle, veddfel. "); Console.WriteLine("Fontos hogy a parancsok megadásánál a mit mivel szepontot kövessd!"); Console.WriteLine("Pl: Az ajtót a kulccsal tudod kinyitni, és nem a kulcsot az ajtóval."); Console.WriteLine("A tovább lépéshez nyomj egy ENTER-t!"); Console.ReadLine(); Console.Clear(); while (interactions.Response != "Betörted az ablakot.") { read = Console.ReadLine().ToLower(); if (read.Length > 1) { interactions.Command = read.Split(' ')[0]; if (read.Split(' ').Length > 1) { interactions.Item1 = read.Split(' ')[1]; } if (read.Split(' ').Length > 2) { interactions.Item2 = read.Split(' ')[2]; } } if (interactions.Command == "leltár") { if (interactions.Item1 == "" && interactions.Item2 == "") { if (Invertory.Count != 0) { Console.WriteLine("Nálad van :"); Console.WriteLine(); foreach (var item in Invertory) { Console.WriteLine(item); } Console.WriteLine(); } else { Console.WriteLine("Nincs nálad semmi."); } } else if (interactions.Response == "") { interactions.Response = "A leltár parancshoz nem kell megadj semmilyen paramétert."; } } if (interactions.Command == "mentés") { if (interactions.Item1 != "" && interactions.Item2 == "") { SaveLoad.Save(Invertory, LivingRoomThings, BathroomThings, interactions); } else if (interactions.Response == "") { interactions.Response = "A mentés parancshoz meg kell add a file nevét."; } } if (interactions.Command == "betöltés") { if (interactions.Item1 != "" && interactions.Item2 == "") { SaveLoad.Load(LivingRoomThings, BathroomThings, Invertory, interactions); } else if (interactions.Response == "" && interactions.Item1 == "") { interactions.Response = "A betöltés parancshoz meg kell add a fájl nevét amit beszeretnél tölteni!"; } } if (!(interactions.Command == "leltár" || interactions.Command == "mentés" || interactions.Command == "betöltés")) { switch (interactions.Room) { case "fürdő": interactions.Response = Bath.BathOnGame(interactions, Invertory, BathroomThings); break; default: interactions.Response = Living.LivingOnGame(interactions, Invertory, LivingRoomThings); break; } } Console.WriteLine(interactions.Response); if (interactions.Response != "Betörted az ablakot.") { interactions.Response = ""; interactions.Command = ""; interactions.Item1 = ""; interactions.Item2 = ""; } else { interactions.Command = ""; interactions.Item1 = ""; interactions.Item2 = ""; } } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Kijutottál!"); Console.WriteLine("A játék végetért!"); Console.WriteLine("A kilépéshez nyom egy ENTER-t !"); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex + " hiba lépett fel a játék futása közben!"); } }