private void ResponseWrapper() { string response = tcpClient.LastResponse; if (response == "requesting move") { tcpClient.SendRequest(snakeUser.SendNextDireciton()); } else if (response == "game over") { state = "postgame"; string winner = map.getWinner(); if (winner == "none") { postgameMessage = "Everyone lost"; } else if (winner == "multiple") { postgameMessage = "server fail"; } else { postgameMessage = String.Format("{0} won!", winner); } tcpClient.Disconnect(); } else { MapUpdatePacket mapUpdatePacket = new MapUpdatePacket(tcpClient.LastResponse); map.UpdateFromMapUpdatePacket(mapUpdatePacket); } }
/// <summary> /// 断开连接 /// </summary> public static void Disconnect() { try { smanager.Disconnect(); if (heartTimer != null) { heartTimer = null; } } catch (Exception) { Console.WriteLine("未能关闭socket连接"); } }