public void AddSubmarine(Coordinate initialCoordinate, Coordinate finalCoordinate, int length) { Submarines.Add(new Submarine(length, Submarines.Count)); SelfBoard.LocateSubmarine(initialCoordinate, finalCoordinate, length, Submarines[Submarines.Count - 1].Id); Submarines[Submarines.Count - 1].DestructionEvent += DestroyFrameOfSubmarine; //register the event }
public void MakeMove(Coordinate chosenSquare) { SelfBoard.SelectSquare(chosenSquare); Square chosen = SelfBoard.GetSquareByIndex(chosenSquare); if (chosen.Status == SquareStatus.HITTED_BOAT) { Submarines[chosen.Id].HitBoat(); } if (Submarines.All(s => s.IsDestroyed)) { HasLostEvent?.Invoke(); } }
public void AddShipeToFleet(ShipBase ship) { if (ship is Submarine) { Submarines.Push(ship as Submarine); } if (ship is BattleShip) { BattleShips = ship as BattleShip; } if (ship is Carrier) { Carrier.Push(ship as Carrier); } if (ship is Cruiser) { Crusers.Push(ship as Cruiser); } }
internal static void AddSh(object Item, string SType) { using (var db = new DatabaseContext()) { switch (SType) { case "AircraftCarriers": AircraftCarriers tempAC = new AircraftCarriers(); foreach (PropertyInfo x in Item.GetType().GetProperties()) { x.SetValue(tempAC, x.GetValue(Item)); } db.Ships.Add(tempAC); break; case "AmphibiousWarfare": AmphibiousWarfare tempAW = new AmphibiousWarfare(); foreach (PropertyInfo x in Item.GetType().GetProperties()) { x.SetValue(tempAW, x.GetValue(Item)); } db.Ships.Add(tempAW); break; case "Cruisers": Cruisers tempC = new Cruisers(); foreach (PropertyInfo x in Item.GetType().GetProperties()) { x.SetValue(tempC, x.GetValue(Item)); } db.Ships.Add(tempC); break; case "Destroyers": Destroyers tempD = new Destroyers(); foreach (PropertyInfo x in Item.GetType().GetProperties()) { x.SetValue(tempD, x.GetValue(Item)); } db.Ships.Add(tempD); break; case "Frigates": Frigates tempF = new Frigates(); foreach (PropertyInfo x in Item.GetType().GetProperties()) { x.SetValue(tempF, x.GetValue(Item)); } db.Ships.Add(tempF); break; case "Submarines": Submarines tempS = new Submarines(); foreach (PropertyInfo x in Item.GetType().GetProperties()) { x.SetValue(tempS, x.GetValue(Item)); } db.Ships.Add(tempS); break; } db.SaveChanges(); } }