public ShellViewModel() { Boats.Add(new Boat("Carrier", new Dictionary <string, bool>() { { "A1", false }, { "A2", false }, { "A3", false }, { "A4", false }, { "A5", false } })); Boats.Add(new Boat("Battleship", new Dictionary <string, bool>() { { "B1", false }, { "B2", false }, { "B3", false }, { "B4", false } })); Boats.Add(new Boat("Destroyer", new Dictionary <string, bool>() { { "C1", false }, { "C2", false }, { "C3", false } })); Boats.Add(new Boat("Submarine", new Dictionary <string, bool>() { { "D1", false }, { "D2", false }, { "D3", false } })); Boats.Add(new Boat("Patrol Boat", new Dictionary <string, bool>() { { "E1", false }, { "E2", false } })); CarrierRow = 1; CarrierColumn = 1; CarrierHorizontal = true; }
public void AddBoat(Boat boat) { var exists = Boats.Any(x => x.Id == boat.Id); if (!exists) { // Nya båten får senaste båtens id + 1. boat.Id = Boats.Select(x => x.Id).DefaultIfEmpty(0).Max() + 1; Boats.Add(boat); } // TODO : Kasta felmeddelande? }
/// <summary> /// Registers a boat on this member; filling the appropriate details for the boat /// </summary> /// <param name="boat"></param> public void RegisterBoat(BoatData boat) { if (boat.Owner == this) { return; } if (boat.Owner != this) { boat.Owner?.Boats.Remove(boat); } boat.Owner = this; Boats.Add(boat); }
public override void CreateNewMoveableObjects() { if (Boats.Count == 0) { var receivedBoat = BoatWarehouse.CreateNewMovableObject(); Boats.Add(receivedBoat); } else { foreach (var boat in Boats) { if (!boat.isFull) { return; } } var receivedBoat = BoatWarehouse.CreateNewMovableObject(); Boats.Add(receivedBoat); } }
public void AddBoat(Boat boat) { Boats.Add(boat); }
public void GenerateBoat(int amount) { for (int boat = 0; boat < amount; boat++) { int avaliableSpace = 0; switch (Rand.Next(1, 5 + 1)) { case 1: SailBoat s = new SailBoat(); for (int i = 0; i < DockTwo.Length; i += 2) { if (DockTwo[i] == null) { avaliableSpace += 2; if (avaliableSpace == s.Slots) { Array.Fill(DockTwo, s, i + 2 - s.Slots, s.Slots); Boats.Add(s); s.Docked = true; break; } } else { avaliableSpace = 0; } } avaliableSpace = 0; if (s.Docked == false) { for (int i = 0; i < DockOne.Length; i += 2) { if (DockOne[i] == null) { avaliableSpace += 2; if (avaliableSpace == s.Slots) { Array.Fill(DockOne, s, i + 2 - s.Slots, s.Slots); Boats.Add(s); s.Docked = true; break; } } else { avaliableSpace = 0; } } } _ = Boats.Contains(s) ? AddedBoats++ : RejectedBoats++; break; case 2: RowingBoat r = new RowingBoat(); for (int i = 0; i < DockOne.Length; i++) { if (DockOne[i] == null) { Array.Fill(DockOne, r, i, r.Slots); Boats.Add(r); r.Docked = true; break; } else { avaliableSpace = 0; } } avaliableSpace = 0; if (r.Docked == false) { for (int i = 0; i < DockTwo.Length; i++) { if (DockTwo[i] == null) { Array.Fill(DockTwo, r, i, r.Slots); Boats.Add(r); r.Docked = true; break; } else { avaliableSpace = 0; } } } _ = Boats.Contains(r) ? AddedBoats++ : RejectedBoats++; break; case 3: PowerBoat p = new PowerBoat(); for (int i = 0; i < DockOne.Length; i += 2) { if (DockOne[i] == null) { avaliableSpace += 2; if (avaliableSpace > p.Slots) { Array.Fill(DockOne, p, i - p.Slots, p.Slots); Boats.Add(p); p.Docked = true; break; } } else { avaliableSpace = 0; } } avaliableSpace = 0; if (p.Docked == false) { for (int i = 0; i < DockTwo.Length; i += 2) { if (DockTwo[i] == null) { avaliableSpace += 2; if (avaliableSpace > p.Slots) { Array.Fill(DockTwo, p, i - p.Slots, p.Slots); Boats.Add(p); p.Docked = true; break; } } else { avaliableSpace = 0; } } } _ = Boats.Contains(p) ? AddedBoats++ : RejectedBoats++; break; case 4: Catamaran k = new Catamaran(); for (int i = 0; i < DockOne.Length; i += 2) { if (DockOne[i] == null) { avaliableSpace += 2; if (avaliableSpace == k.Slots) { Array.Fill(DockOne, k, i + 2 - k.Slots, k.Slots); Boats.Add(k); k.Docked = true; break; } } else { avaliableSpace = 0; } } if (k.Docked == false) { avaliableSpace = 0; for (int i = 0; i < DockTwo.Length; i += 2) { if (DockTwo[i] == null) { avaliableSpace += 2; if (avaliableSpace == k.Slots) { Array.Fill(DockTwo, k, i + 2 - k.Slots, k.Slots); Boats.Add(k); k.Docked = true; break; } } else { avaliableSpace = 0; } } } _ = Boats.Contains(k) ? AddedBoats++ : RejectedBoats++; break; case 5: CargoShip c = new CargoShip(); for (int i = DockTwo.Length - 1; i > 0; i -= 2) { if (DockTwo[i] == null) { avaliableSpace += 2; if (avaliableSpace == c.Slots) { Array.Fill(DockTwo, c, i - 2 + 1, c.Slots); Boats.Add(c); c.Docked = true; break; } } else { avaliableSpace = 0; } } if (c.Docked == false) { avaliableSpace = 0; for (int i = DockOne.Length - 1; i > 0; i -= 2) { if (DockOne[i] == null) { avaliableSpace += 2; if (avaliableSpace == c.Slots) { Array.Fill(DockOne, c, i - 2 + 1, c.Slots); Boats.Add(c); c.Docked = true; break; } } else { avaliableSpace = 0; } } } _ = Boats.Contains(c) ? AddedBoats++ : RejectedBoats++; break; } } }
public void ReadDockData() { string data = File.ReadAllText(DataPath); if (data == "") { //empty harbour } else { string[] dockSplit = data.Split('_'); string[] dockOne = dockSplit[0].Split('\n', StringSplitOptions.RemoveEmptyEntries); string[] removeShit = dockSplit[1].Split('\n', StringSplitOptions.RemoveEmptyEntries); string[] dockTwo = removeShit.Skip(1) .ToArray(); foreach (var item in dockOne) { if (item == dockOne[0]) { string[] counters = item.Split('-'); Day = int.Parse(counters[0]); RejectedBoats = int.Parse(counters[1]); AddedBoats = int.Parse(counters[2]); } else { string[] boats = item.Split(','); if (boats[0].ToLower() == "sailboat" && !Array.Exists(DockOne, b => b != null && b.ID == boats[1])) { SailBoat sail = new SailBoat() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), LengthInFeet = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; sail.Docked = true; Array.Fill(DockOne, sail, Counter, sail.Slots); Boats.Add(sail); } if (boats[0].ToLower() == "rowingboat" && !Array.Exists(DockOne, b => b != null && b.ID == boats[1])) { RowingBoat row = new RowingBoat() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), MaxPassenger = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; row.Docked = true; Array.Fill(DockOne, row, Counter, row.Slots); Boats.Add(row); } if (boats[0].ToLower() == "powerboat" && !Array.Exists(DockOne, b => b != null && b.ID == boats[1])) { PowerBoat power = new PowerBoat() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), NumberOfHorsepower = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; power.Docked = true; Array.Fill(DockOne, power, Counter, power.Slots); Boats.Add(power); } if (boats[0].ToLower() == "catamaran" && !Array.Exists(DockOne, b => b != null && b.ID == boats[1])) { Catamaran catamaran = new Catamaran() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), Beds = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; catamaran.Docked = true; Array.Fill(DockOne, catamaran, Counter, catamaran.Slots); Boats.Add(catamaran); } if (boats[0].ToLower() == "cargoship" && !Array.Exists(DockOne, b => b != null && b.ID == boats[1])) { CargoShip cargo = new CargoShip() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), CargoContainers = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; cargo.Docked = true; Array.Fill(DockOne, cargo, Counter, cargo.Slots); Boats.Add(cargo); } Counter++; } } Counter = 0; foreach (var item in dockTwo) { string[] boats = item.Split(','); if (boats[0].ToLower() == "sailboat" && !Array.Exists(DockTwo, b => b != null && b.ID == boats[1])) { SailBoat sail = new SailBoat() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), LengthInFeet = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; sail.Docked = true; Array.Fill(DockTwo, sail, Counter, sail.Slots); Boats.Add(sail); } if (boats[0].ToLower() == "rowingboat" && !Array.Exists(DockTwo, b => b != null && b.ID == boats[1])) { RowingBoat row = new RowingBoat() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), MaxPassenger = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; row.Docked = true; Array.Fill(DockTwo, row, Counter, row.Slots); Boats.Add(row); } if (boats[0].ToLower() == "powerboat" && !Array.Exists(DockTwo, b => b != null && b.ID == boats[1])) { PowerBoat power = new PowerBoat() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), NumberOfHorsepower = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; power.Docked = true; Array.Fill(DockTwo, power, Counter, power.Slots); Boats.Add(power); } if (boats[0].ToLower() == "catamaran" && !Array.Exists(DockTwo, b => b != null && b.ID == boats[1])) { Catamaran catamaran = new Catamaran() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), Beds = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; catamaran.Docked = true; Array.Fill(DockTwo, catamaran, Counter, catamaran.Slots); Boats.Add(catamaran); } if (boats[0].ToLower() == "cargoship" && !Array.Exists(DockTwo, b => b != null && b.ID == boats[1])) { CargoShip cargo = new CargoShip() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), CargoContainers = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; cargo.Docked = true; Array.Fill(DockTwo, cargo, Counter, cargo.Slots); Boats.Add(cargo); } Counter++; } } Counter = 0; }
public void ReadDockData() { if (File.Exists(DataPath)) { Data = File.ReadAllText(DataPath); } else { File.Create(DataPath); } if (Data == "") { Console.WriteLine("Harbour hasn't been opened yet..."); } else { string[] split = Data.Split('\n'); foreach (var item in split) { if (item == split[0]) { string[] counters = item.Split('-'); Day = int.Parse(counters[0]); RejectedBoats = int.Parse(counters[1]); AddedBoats = int.Parse(counters[2]); } else { string[] boats = item.Split(','); if (boats[0].ToLower() == "sailboat" && !Array.Exists(Docks, b => b != null && b.ID == boats[1])) { SailBoat sail = new SailBoat() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), LengthInFeet = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; sail.Docked = true; Array.Fill(Docks, sail, Counter, sail.Slots); Boats.Add(sail); } if (boats[0].ToLower() == "rowingboat" && !Array.Exists(Docks, b => b != null && b.ID == boats[1])) { RowingBoat row = new RowingBoat() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), MaxPassenger = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; row.Docked = true; Array.Fill(Docks, row, Counter, row.Slots); Boats.Add(row); } if (boats[0].ToLower() == "powerboat" && !Array.Exists(Docks, b => b != null && b.ID == boats[1])) { PowerBoat power = new PowerBoat() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), NumberOfHorsepower = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; power.Docked = true; Array.Fill(Docks, power, Counter, power.Slots); Boats.Add(power); } if (boats[0].ToLower() == "catamaran" && !Array.Exists(Docks, b => b != null && b.ID == boats[1])) { Catamaran catamaran = new Catamaran() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), Beds = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; catamaran.Docked = true; Array.Fill(Docks, catamaran, Counter, catamaran.Slots); Boats.Add(catamaran); } if (boats[0].ToLower() == "cargoship" && !Array.Exists(Docks, b => b != null && b.ID == boats[1])) { CargoShip cargo = new CargoShip() { ID = boats[1], Weight = int.Parse(boats[2]), MaxSpeed = int.Parse(boats[3]), CargoContainers = int.Parse(boats[4]), DaysDocked = int.Parse(boats[5]) }; cargo.Docked = true; Array.Fill(Docks, cargo, Counter, cargo.Slots); Boats.Add(cargo); } Counter++; } } Counter = 0; } }
public void GenerateBoat(int amount) { for (int boat = 0; boat < amount; boat++) { int avaliableSpace = 0; switch (Rand.Next(1, 5 + 1)) { case 1: SailBoat s = new SailBoat(); for (int i = 0; i < Docks.Length; i += 2) { if (Docks[i] == null) { avaliableSpace += 2; if (avaliableSpace > s.Slots) { TempInterval = i - s.Slots; Array.Fill(Docks, s, TempInterval, s.Slots); Boats.Add(s); s.Docked = true; break; } } else { avaliableSpace = 0; } } _ = Boats.Contains(s) ? AddedBoats++ : RejectedBoats++; break; case 2: RowingBoat r = new RowingBoat(); for (int i = 0; i < Docks.Length; i++) { if (Docks[i] == null) { Array.Fill(Docks, r, i, r.Slots); Boats.Add(r); r.Docked = true; break; } else { avaliableSpace = 0; } } _ = Boats.Contains(r) ? AddedBoats++ : RejectedBoats++; break; case 3: PowerBoat p = new PowerBoat(); for (int i = 0; i < Docks.Length; i += 2) { if (Docks[i] == null) { avaliableSpace += 2; if (avaliableSpace > p.Slots) { TempInterval = i - p.Slots; Array.Fill(Docks, p, TempInterval, p.Slots); Boats.Add(p); p.Docked = true; break; } } else { avaliableSpace = 0; } } _ = Boats.Contains(p) ? AddedBoats++ : RejectedBoats++; break; case 4: Catamaran k = new Catamaran(); for (int i = 0; i < Docks.Length; i += 2) { if (Docks[i] == null) { avaliableSpace += 2; if (avaliableSpace > k.Slots) { TempInterval = i - k.Slots; Array.Fill(Docks, k, TempInterval, k.Slots); Boats.Add(k); k.Docked = true; break; } } else { avaliableSpace = 0; } } _ = Boats.Contains(k) ? AddedBoats++ : RejectedBoats++; break; case 5: CargoShip c = new CargoShip(); for (int i = Docks.Length - 1; i > 0; i -= 2) { if (Docks[i] == null) { avaliableSpace += 2; if (avaliableSpace > c.Slots) { TempInterval = i + 1; Array.Fill(Docks, c, TempInterval, c.Slots); Boats.Add(c); c.Docked = true; break; } } else { avaliableSpace = 0; } } _ = Boats.Contains(c) ? AddedBoats++ : RejectedBoats++; break; } } }