public static void ShipSetup(Player p1, Player p2) { int x = 0; int y = 0; Coordinate xy = new Coordinate(x, y); ShipDirection direction = ShipDirection.Down; bool IsValid = true; string DirResponse = ""; PlaceShipRequest psr = new PlaceShipRequest(); ShipPlacement response; for (int k = 0; k < 2; k++) { if (k == 1) { Console.Clear(); Console.WriteLine($"{p1.Name}, you're all set up!"); Console.WriteLine($"\nNow let's have {p2.Name} set up his ships."); Console.ReadLine(); } foreach (ShipType stype in Enum.GetValues(typeof(ShipType))) { do { do { if (k == 0) { Console.Clear(); VisualBoard.HitBoard(p1); Console.WriteLine($"{p1.Name}, choose a coordinate for your {stype}:"); } else { Console.Clear(); VisualBoard.HitBoard(p1); Console.WriteLine($"{p2.Name}, choose a coordinate for your {stype}:"); } string cord = Console.ReadLine(); xy = ConsoleInput.ConvertToCord(cord); IsValid = ConsoleInput.ValidateCord(xy); Console.Clear(); } while (IsValid == false); if (IsValid == true) { do { Console.WriteLine( $"Now choose a direction for your {stype}\n1 - Up, 2 - Down, 3 - Right, 4 - Left"); DirResponse = Console.ReadLine(); switch (DirResponse) { case "1": direction = ShipDirection.Up; IsValid = true; break; case "2": direction = ShipDirection.Down; IsValid = true; break; case "3": direction = ShipDirection.Right; IsValid = true; break; case "4": direction = ShipDirection.Left; IsValid = true; break; default: Console.Clear(); Console.WriteLine("That was not a valid direction response. Try Again"); Console.ReadLine(); Console.Clear(); IsValid = false; break; } } while (IsValid == false); Console.Clear(); psr.Coordinate = xy; psr.Direction = direction; psr.ShipType = stype; } if (k == 0) { response = p1.pBoard.PlaceShip(psr); } else { response = p2.pBoard.PlaceShip(psr); } if (response == ShipPlacement.NotEnoughSpace) { ConsoleOutput.DisplayNotEnoughSpace(); } else if (response == ShipPlacement.Overlap) { ConsoleOutput.DisplayOverlap(); } else { Console.WriteLine("Good Job"); Console.ReadLine(); } } while (response != ShipPlacement.Ok); } } }
public static void StartGame(Player p1, Player p2) { Random rng = new Random(); int whoseTurn = rng.Next(1, 3); bool isValid = true; Coordinate xy; bool Victory = false; FireShotResponse response = new FireShotResponse(); if (whoseTurn == 1) { Console.WriteLine("Ok, let's get started!"); Console.ReadLine(); Console.Clear(); Console.WriteLine($"{p1.Name}, you have been randomly chosen to go first."); Console.ReadLine(); Console.Clear(); } else { Console.Clear(); Console.WriteLine("Ok, let's get started!"); Console.ReadLine(); Console.Clear(); Console.WriteLine($"{p2.Name}, you have been randomly chose to go first."); } while (Victory == false) { if (whoseTurn == 1) { VisualBoard.HitBoard(p2); //Getting cords to fire Console.WriteLine($"{p1.Name} enter a coordinate to fire at"); string cord = Console.ReadLine(); xy = ConsoleInput.ConvertToCord(cord); //setting fireshot response response = p2.pBoard.FireShot(xy); if (response.ShotStatus == ShotStatus.Duplicate) { ConsoleOutput.DisplayDuplicate(); } else if (response.ShotStatus == ShotStatus.Hit) { ConsoleOutput.DisplayHit(); } else if (response.ShotStatus == ShotStatus.HitAndSunk) { ConsoleOutput.DisplayHitAndSunk(); } else if (response.ShotStatus == ShotStatus.Invalid) { ConsoleOutput.DisplayInvalid(); } else if (response.ShotStatus == ShotStatus.Miss) { ConsoleOutput.DisplayMiss(); } else { ConsoleOutput.DisplayVictory(); Victory = true; } if (response.ShotStatus == ShotStatus.Duplicate) { whoseTurn = 1; } else if (response.ShotStatus == ShotStatus.Invalid) { whoseTurn = 1; } else { whoseTurn = 2; } } else { VisualBoard.HitBoard(p1); Console.WriteLine($"{p2.Name} enter a coordinate to fire at"); string cord = Console.ReadLine(); xy = ConsoleInput.ConvertToCord(cord); response = p1.pBoard.FireShot(xy); if (response.ShotStatus == ShotStatus.Duplicate) { ConsoleOutput.DisplayDuplicate(); } else if (response.ShotStatus == ShotStatus.Hit) { ConsoleOutput.DisplayHit(); } else if (response.ShotStatus == ShotStatus.HitAndSunk) { ConsoleOutput.DisplayHitAndSunk(); } else if (response.ShotStatus == ShotStatus.Invalid) { ConsoleOutput.DisplayInvalid(); } else if (response.ShotStatus == ShotStatus.Miss) { ConsoleOutput.DisplayMiss(); } else { ConsoleOutput.DisplayVictory(); Victory = true; } if (response.ShotStatus == ShotStatus.Duplicate) { whoseTurn = 2; } else if (response.ShotStatus == ShotStatus.Invalid) { whoseTurn = 2; } else { whoseTurn = 1; } } } }