private void PlaceShips(PlayerDto inDto) { int a = Enum.GetNames(typeof(ShipType)).Length; for (int i = 0; i < a; i++) { bool isPlacementOk = false; while (!isPlacementOk) { string shipType = ((ShipType)i).ToString(); var coordGetter = new CoordGetter(); var shipPointer = new ShipPointer(); PlaceShipRequest request = new PlaceShipRequest() { Coordinate = coordGetter.GetCoord((i + 1).ToString() + ". " + "Enter coordinate for your " + shipType.ToString() + ": "), Direction = shipPointer.PointShip(" Ship direction: (L-left, R-right, U-up, D-down): "), ShipType = (ShipType)i }; var responce = inDto.Board.PlaceShip(request); string r = responce.ToString(); if (r == ShipPlacement.Ok.ToString()) { isPlacementOk = true; Console.WriteLine(" Ship placement status: {0}", r); } else { Console.WriteLine(" Ship NOT PLACED! : {0}", r); } } } }
private void Shoot(PlayerDto inDto) { bool isShotValid = false; while (!isShotValid) { var coordGetter = new CoordGetter(); //Console.Clear(); DisplayShotHistory(inDto); var coord = coordGetter.GetCoord("> Enter Shot Coord (Ex: a1, b6) : "); var response = inDto.Board.FireShot(coord); Console.Clear(); Console.WriteLine("\n Shot result: "); DisplayShotHistory(inDto); if (response.ShotStatus == ShotStatus.Duplicate || response.ShotStatus == ShotStatus.Invalid) { Console.WriteLine("\nThat was not a valid shot, ({0}), Take another shot!", response.ShotStatus.ToString()); Console.WriteLine("\n Press Enter to re-take shot..."); Console.ReadLine(); Console.Clear(); Console.WriteLine("\n Shot result: "); //mt //Console.ReadLine(); //Console.Clear(); } else if (response.ShotStatus == ShotStatus.Miss) { Console.Write("\nSplash! - You MISSED..."); isShotValid = true; } else if (response.ShotStatus == ShotStatus.Hit) { Console.Write("\nBOOM! *** You hit something!"); isShotValid = true; } else if (response.ShotStatus == ShotStatus.HitAndSunk) { Console.Write("\nBAAM! *** You hit and SUNK a {0}", response.ShipImpacted.ToString()); isShotValid = true; } else { Console.WriteLine("\nVICTORY! - you just WON!!!"); _isVictory = true; break; } } }
// ctor public BattleshipGame() { _p1Dto = new PlayerDto(); _p2Dto = new PlayerDto(); _quit = 2; }