private List <Boat> CreateRandomBoats(int boats) { List <Boat> incoming = new List <Boat>(); // List to return. for (int i = 0; i < boats; i++) { // 0-RowBoat, 1-MotorBoat, 2-SailsBoat, 3-CargoBoat, 4-Katamaran TypeBoat t = (TypeBoat)Enum.GetValues(typeof(TypeBoat)) // This returns an array of the values in TypeBoat .GetValue((new Random()).Next(0, 5)); // GetValue(i) retrieves by an index (much like [i]). // In this case "Random". switch (t) { case TypeBoat.Rowboat: { RowBoat r = new RowBoat(true); r.Type = TypeBoat.Rowboat; incoming.Add(r); break; } case TypeBoat.Motorboat: { MotorBoat m = new MotorBoat(true); m.Type = TypeBoat.Motorboat; incoming.Add(m); break; } case TypeBoat.Sailsboat: { SailsBoat s = new SailsBoat(true); s.Type = TypeBoat.Sailsboat; incoming.Add(s); break; } case TypeBoat.Cargoboat: { CargoBoat c = new CargoBoat(true); c.Type = TypeBoat.Cargoboat; incoming.Add(c); break; } case TypeBoat.Katamaran: { Katamaran k = new Katamaran(true); k.Type = TypeBoat.Katamaran; incoming.Add(k); break; } } } return(incoming); }
public Boat(int length, TypeBoat type, string groupId) { Length = length; Type = type; //GroupId = groupId; }