private string DisplayOptions(Rover r, Devices d) { string result = ""; for (int i = 0; i != r.DevicesByType(d).Count; i++) { result += ("\t" + (i + 1) + ": " + r.DevicesByType(d)[i].Name + "\n"); } return(result); }
private void Operate(Rover r, Devices d) { if (r.DevicesByType(d).Count == 0) { Console.WriteLine(r.Name + "does not have a " + d.ToString().ToLower()); return; } Console.WriteLine("Which " + d.ToString().ToLower() + " would you like to use?"); Console.Write(DisplayOptions(r, d)); switch (Console.ReadKey().Key) { case ConsoleKey.D1: if (r.DevicesByType(d).Count < 1) { Console.WriteLine("Option 1 not given"); } else { Console.WriteLine(r.DevicesByType(d)[0].Operate(r)); } break; case ConsoleKey.D2: if (r.DevicesByType(d).Count < 2) { Console.WriteLine("Option 2 not given"); } else { Console.WriteLine(r.DevicesByType(d)[1].Operate(r)); } break; case ConsoleKey.D3: if (r.DevicesByType(d).Count < 3) { Console.WriteLine("Option 3 not given"); } else { Console.WriteLine(r.DevicesByType(d)[2].Operate(r)); } break; case ConsoleKey.D4: if (r.DevicesByType(d).Count < 4) { Console.WriteLine("Option 4 not given"); } else { Console.WriteLine(r.DevicesByType(d)[3].Operate(r)); } break; case ConsoleKey.D5: if (r.DevicesByType(d).Count < 5) { Console.WriteLine("Option 5 not given"); } else { Console.WriteLine(r.DevicesByType(d)[4].Operate(r)); } break; case ConsoleKey.D6: if (r.DevicesByType(d).Count < 6) { Console.WriteLine("Option 6 not given"); } else { Console.WriteLine(r.DevicesByType(d)[5].Operate(r)); } break; case ConsoleKey.D7: if (r.DevicesByType(d).Count < 7) { Console.WriteLine("Option 7 not given"); } else { Console.WriteLine(r.DevicesByType(d)[6].Operate(r)); } break; case ConsoleKey.D8: if (r.DevicesByType(d).Count < 8) { Console.WriteLine("Option 8 not given"); } else { Console.WriteLine(r.DevicesByType(d)[7].Operate(r)); } break; case ConsoleKey.D9: if (r.DevicesByType(d).Count < 9) { Console.WriteLine("Option 9 not given"); } else { Console.WriteLine(r.DevicesByType(d)[8].Operate(r)); } break; default: Console.WriteLine("Please press one of the correct number keys to continue"); return; } }