static void Main(string[] args) { DoAI(); var grid = new Grid(); while (!grid.AllShipsDestroyed) { grid.DisplayGrid(true); string x; string y; do { Console.WriteLine("Enter coordinates (x, y):"); Console.Write("("); x = Console.ReadKey().KeyChar.ToString(); Console.Write(", "); y = Console.ReadKey().KeyChar.ToString(); Console.Write(")"); Console.WriteLine(); } while (!("0123456789".Contains(x) && "0123456789".Contains(y))); if ("asdfsdf".All(char.IsDigit)) { } int aNumber = 0; if (!int.TryParse(Console.ReadLine(), out aNumber)) { } grid.Target(int.Parse(x), int.Parse(y)); } grid.DisplayGrid(); Console.WriteLine(); Console.WriteLine("YOU WON!!!!!!!!!! YEAH!"); Console.WriteLine(); Console.ReadKey(); }
/// <summary> /// Main Game Loop /// </summary> static void PlayGame() { int attacks = 0; Bot liitleBot = new Bot(); //While there are still ships to destroy while (!Ocean.AllShipsDestroyed && !myOcean.AllShipsDestroyed) { int[] TargCoord = new int[2]; do { // Debug Section //for (int i = 0; i < 10; i++) //{ // for (int j = 0; j < 10; j++) // { // TargCoord = getTarget(i + "," + j); // myOcean.Target(TargCoord[0], TargCoord[1]); // Ocean.Target(TargCoord[0], TargCoord[1]); // } //} Console.WriteLine("Select your Coordinates (x,y): "); TargCoord = getTarget(Console.ReadLine()); attacks++; }while ((TargCoord[0] > 9 || TargCoord[0] < 0) && (TargCoord[1] > 9 || TargCoord[1] < 0)); Ocean.Target(TargCoord[0], TargCoord[1]); if (!Ocean.AllShipsDestroyed) { Point pnt = liitleBot.Hit(); if (myOcean.Target(pnt.x, pnt.y)) { liitleBot.BotGotIt(pnt); } else { liitleBot.BotNotGotIt(pnt); } } Console.Clear(); DisplayOceans(Ocean, myOcean); } Console.WriteLine(); if (Ocean.AllShipsDestroyed) { Console.WriteLine("Winner, winner!"); AddHighScore(attacks); DisplayHighScores(); SayString("Congratulations, you've won."); } else { Console.WriteLine("You lose"); SayString("You are a big loser."); } }