public static void StartShooting(Connection.SocketClient socketClient) { do { Shoot(socketClient); } while (WhoWin == 0); }
public static void Shoot(Connection.SocketClient socketClient) { int[] cells = new int[2]; Console.WriteLine("Its your turn: shoot enemy battleship"); Console.WriteLine("Enter X coordinate"); string line = Console.ReadLine(); int value; if (int.TryParse(line, out value)) { cells[0] = value; } else { throw new Exception("Not an integer!"); } Console.WriteLine("Enter Y coordinate"); line = Console.ReadLine(); if (int.TryParse(line, out value)) { cells[1] = value; } else { throw new Exception("Not an integer!"); } socketClient.SendMessage(cells[0].ToString() + cells[1].ToString()); Console.Clear(); Console.WriteLine("Waiting for reply..."); while (socketClient.ReceiveMessage() == null) { } bool ifweshootagain = GetYourResult(socketClient.ReceiveMessage().ToString(), cells); if (ifweshootagain) { return; } }
public static void StartGame(int[,] Mytable) { Console.WriteLine("If u want to be server write 1, if u want to connect to server write 0"); char a = Console.ReadLine()[0]; switch (a) { case '0': { Console.WriteLine("Please write IP of device u want to connect formatted like : 127.0.0.1"); IPAddress ServerIP; IPAddress.TryParse(Console.ReadLine(), out ServerIP); Console.WriteLine("Please write port of server device"); int port; Int32.TryParse(Console.ReadLine(), out port); Connection.SocketClient socketClient = new Connection.SocketClient(ServerIP, port); // Connection.SocketServer socketServer = new Connection.SocketServer(IPAddress.Parse("127.0.0.1"), 11000); StartShooting(socketClient); } break; case '1': { Console.WriteLine("Please write IP your computer formatted like : 127.0.0.1"); IPAddress ServerIP; IPAddress.TryParse(Console.ReadLine(), out ServerIP); Console.WriteLine("Please write port of server device"); int port; Int32.TryParse(Console.ReadLine(), out port); Connection.SocketServer socketServer = new Connection.SocketServer(ServerIP, port); } break; default: StartGame(Myships); break; } Console.WriteLine("Wanna play again?"); Environment.Exit(0); }
public static void StartGame() { DrawBoard(); //SetFourCellShip(); //SetThreeCellShips(); //SetTwoCellShips(); //SetOneCellShips(); CreateBoardTest(); Console.WriteLine("If u want to be server write 1, if u want to connect to server write 0"); char a = Console.ReadLine()[0]; switch (a) { case '0': Console.WriteLine("Please write IP of device u want to connect formatted like : 127.0.0.1"); IPAddress ServerIP; IPAddress.TryParse(Console.ReadLine(), out ServerIP); Console.WriteLine("Please write port of server device"); int port; Int32.TryParse(Console.ReadLine(), out port); Connection.SocketClient socketClient = new Connection.SocketClient(ServerIP, port); // Connection.SocketServer socketServer = new Connection.SocketServer(IPAddress.Parse("127.0.0.1"), 11000); StartShooting(socketClient); break; case '1': break; default: StartGame(Myships); break; } Console.WriteLine("Wanna play again?"); Environment.Exit(0); }