public void ReadHull(StreamReader fin) { InitHull(); this.hullStrength = ValidationUtil.ParseStringToNumber(fin.ReadLine()); if (!ValidationUtil.ValidNumber(hullStrength)) { throw new Exception("Invalid hull strength"); } }
private int ValidateSeed() { int seed = ValidationUtil.ParseStringToNumber(seedValueTextBox.Text); if (!ValidationUtil.ValidNumber(seed)) { throw new Exception("Invalid seed value entered"); } return(seed); }
private void CreateFleetShips(StreamReader fileReader) { string shipClassName = fileReader.ReadLine(); int numberRequired = ValidationUtil.ParseStringToNumber(fileReader.ReadLine()); if (!ValidationUtil.ValidNumber(numberRequired)) { throw new Exception("Invalid number of ships"); } if (String.IsNullOrEmpty(shipClassName) || !IsValidShipClass(shipClassName)) { throw new Exception(shipClassName + " is not a valid ship class name"); } // create ship CreateShip(shipClassName, numberRequired); }
private static bool ValidInputArguments(string[] arguments, out int seed) { seed = 0; if (arguments == null || arguments.Length != CommandLineArgumentsRequired) { ConsoleUtil.PrintInvalidArguments(); return(false); } seed = ValidationUtil.ParseStringToNumber(arguments[0]); if (ValidationUtil.ValidNumber(seed)) { return(true); } ConsoleUtil.PrintInvalidSeed(); return(false); }
public void ReadWeapon(StreamReader fin) { InitWeapons(); this.weaponBase = ValidationUtil.ParseStringToNumber(fin.ReadLine()); // read in weapon base if (!ValidationUtil.ValidNumber(weaponBase)) { throw new Exception("Invalid weapon base"); } // read in weapon rand this.weaponRand = ValidationUtil.ParseStringToNumber(fin.ReadLine()); if (!ValidationUtil.ValidNumber(weaponRand)) { throw new Exception("Invalid weapon random"); } }
public void ReadShield(StreamReader fin) { InitShield(); this.shieldStrength = ValidationUtil.ParseStringToNumber(fin.ReadLine()); if (!ValidationUtil.ValidNumber(shieldStrength)) { throw new Exception("Invalid shield strength"); } this.regenerationRate = ValidationUtil.ParseStringToNumber(fin.ReadLine()); if (!ValidationUtil.ValidNumber(regenerationRate) || (regenerationRate > shieldStrength)) { throw new Exception("Invalid regen rate"); } }
private void ReadShipsVersionOne(StreamReader fin) { // read number of ships in fleet int numberOfShips = ValidationUtil.ParseStringToNumber(fin.ReadLine()); if (!ValidationUtil.ValidNumber(numberOfShips)) { throw new Exception("Invalid number of ships"); } // create required ships for (int i = 0; i < numberOfShips; i++) { Ship ship = new Ship(rand); ship.ReadShip(fin); ShipsInService.Add(ship); } }