/// <summary> /// Method containing thread recieving data from server /// </summary> private void ConnectThread() { try { tcpClient = new TcpClient(); tcpClient.Connect(hostname, port); stream = tcpClient.GetStream(); SendPacket(new SnakeGameTCPPacketInit(numSnakes)); while (true) { Object o = formatter.Deserialize(stream); if (o is SnakeGameTCPPacketInitResponse) { SnakeGameTCPPacketInitResponse packet = (SnakeGameTCPPacketInitResponse)o; snakeGame.Field = packet.Field; draw.DrawAll(); } else if (o is SnakeGameTCPPacketDraw) { SnakeGameTCPPacketDraw packet = (SnakeGameTCPPacketDraw)o; draw.Draw(packet.DrawUpdate); draw.DrawUpdate(); } } } catch (Exception) { Stop(); System.Windows.Forms.MessageBox.Show("Connection lost to server"); } }
/// <summary> /// Moves all the snakes (and indirectly food) /// </summary> /// <param name="sender">Required by Timer.Tick, not used</param> /// <param name="e">Required by Timer.Tick, not used</param> public void MoveStuff(object sender, EventArgs e) { foreach (Snake snake in allSnakes) { snake.MoveSnake(); } //Draw for real draw.DrawUpdate(); }