public void buildSquad() { firstTimeSquad(); Console.WriteLine("You should type out the full name of the unit, like 'Prospit Conscript' or 'derse con' or 'p c'.\n\tConsripts\n\tBasic Infantry"); bool decided = false; bool prospit; bool good = false; string reply, soldier, type, name, desc; Soldier s = null; while (!decided) { Console.WriteLine("What soldiers would you like to add?\n\tType 'done' when you're finished."); reply = Console.ReadLine(); //break loop if (reply.Equals("exit") || reply.Equals("back") || reply.Equals("done") || reply.Equals("Done")) { break; } type = reply.Substring(0, reply.IndexOf(" ")); soldier = reply.Substring(reply.IndexOf(" "), reply.Length - reply.IndexOf(" ")); soldier = soldier.Substring(1, soldier.Length - 1); // Console.WriteLine("{0} -> {1}", soldier, type); // //make sure to substring reply //Prospit/Derse Determinate if (type.Contains("Prospit") || type.Contains("prospit") || type.Contains("p")) { prospit = true; good = true; } else if (type.Contains("Derse") || type.Contains("derse") || type.Contains("d")) { prospit = false; good = true; } else { Console.WriteLine("Err; didn't specify Prospit or Derse"); good = false; prospit = false; } //prompt s = new Soldier(soldier, prospit); //decide soldier's name and description ONLY IF they are already designed if (good && s.getHP() != 0) { Console.WriteLine("What is the soldier's name? What is the soldier's unique trait?\nExample, 'Name Description', 'Carl He likes cats'"); reply = Console.ReadLine(); //get parts try { name = reply.Substring(0, reply.IndexOf(" ")); } catch (ArgumentOutOfRangeException) { break; } desc = reply.Substring(reply.IndexOf(" ") + 1, reply.Length - reply.IndexOf(" ") - 1); //assign parts s.nameSoldier(name, desc); addSoldier(s); } else { Console.WriteLine("That soldier doesn't exist!"); } if (s != null) { Console.WriteLine(s.ToString()); } } }
public void import() { //Console.WriteLine("Copy your Code Here:"); Console.WriteLine("What is the name of your squad?\n\t'view' - See all squads"); string reply = Console.ReadLine(); if (reply.Equals("view")) { //Console.WriteLine(stringSquads()); //DOES NOT WORK } StreamReader sr = new StreamReader($"C:\\Users\\Nore5515\\Documents\\Visual Studio 2015\\Projects\\ConsoleApplication6\\{reply}.txt"); //reply = Console.ReadLine(); reply = sr.ReadLine(); sr.Close(); string manip; bool importing = true; int count = 0; Soldier s; while (importing) { if (reply.Length < 3) { importing = false; break; } s = new Soldier(); manip = reply.Substring(0, reply.IndexOf("|")); if (manip.Substring(0, 1).Equals("0")) { s.setSpecies("Derse"); } else if (manip.Substring(0, 1).Equals("1")) { s.setSpecies("Prospit"); } else { Console.WriteLine("ERR IN SPECIES SET - IMPORT"); } manip = manip.Substring(1, manip.Length - 1); if (manip.Substring(0, 1).Equals("0")) { s.setType("Conscript"); } else if (manip.Substring(0, 1).Equals("1")) { s.setType("Basic Infantry"); } else if (manip.Substring(0, 1).Equals("2")) { s.setType("Sniper"); } else if (manip.Substring(0, 1).Equals("3")) { s.setType("Engineer"); } else if (manip.Substring(0, 1).Equals("4")) { s.setType("Machine Gunner"); } else if (manip.Substring(0, 1).Equals("5")) { s.setType("AT Specialist"); } else if (manip.Substring(0, 1).Equals("6")) { s.setType("Transport"); } else if (manip.Substring(0, 1).Equals("7")) { s.setType("MRAP"); } else if (manip.Substring(0, 1).Equals("8")) { s.setType("Scout"); } else { Console.WriteLine("ERR IN TYPE SET - IMPORT"); } manip = manip.Substring(2); //Console.WriteLine($"[{manip}]\n\t[{manip.Substring(0, manip.IndexOf("-"))}]"); //Console.WriteLine(int.Parse(manip.Substring(0, manip.IndexOf("-")))); s.setAge(int.Parse(manip.Substring(0, manip.IndexOf("-")))); manip = manip.Substring(1, manip.Length - 1); //Console.WriteLine(manip); //Console.WriteLine($"-{manip.IndexOf("-")}-\t-{manip.Length - manip.IndexOf("-") - 1}-"); manip = manip.Substring(manip.IndexOf("-") + 1, manip.Length - manip.IndexOf("-") - 1); //Console.WriteLine($"Manip: {manip}))"); //Console.WriteLine($"Name: {manip.Substring(0, manip.IndexOf("-"))}))"); s.setName(manip.Substring(0, manip.IndexOf("-"))); //Console.WriteLine(manip); manip = manip.Substring(manip.IndexOf("-") + 1); //Console.WriteLine($"Manip: {manip}))"); s.setDesc(manip); reply = reply.Substring(reply.IndexOf("|") + 1, reply.Length - reply.IndexOf("|") - 1); s.update(); addSoldier(s); count++; } Console.WriteLine("Import Complete!"); }