示例#1
0
文件: Game1.cs 项目: samoKrajci/Sake
        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);
            }
        }
示例#2
0
 /// <summary>
 /// 断开连接
 /// </summary>
 public static void Disconnect()
 {
     try
     {
         smanager.Disconnect();
         if (heartTimer != null)
         {
             heartTimer = null;
         }
     }
     catch (Exception)
     {
         Console.WriteLine("未能关闭socket连接");
     }
 }