public void GetGridUdp(TetrisGrid grid) { UdpListener = new UdpClient(); try { IPEndPoint ClientEndPoint = new IPEndPoint(IPAddress.Any, ReceiveGridPort); UdpListener.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); UdpListener.ExclusiveAddressUse = false; UdpListener.Client.Bind(ClientEndPoint); while (true) { Byte[] data = UdpListener.Receive(ref ClientEndPoint); string Message = Encoding.ASCII.GetString(data); if (Message.Substring(0, 1) == "S") { Score = int.Parse(Message.Substring(1, Message.Length - 1)); } else { int[,] getgrid = JsonConvert.DeserializeAnonymousType <int[, ]>(Message, grid.Grid2); grid.Grid2 = getgrid; } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { UdpListener.Close(); } }
protected override void LoadContent() { screen = new Point(1340, 1180); windowSize = new Point(924, 868); FullScreen = false; // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); tetrisGrid = new TetrisGrid(Content); gameWorld = new GameWorld(Content); block = new Block(Content, Color.White); rnd = new Random(); //activeBlock = new Block(Content, Color.White); //shape = new bool[,]; }
public void SendGrid(TetrisGrid grid) { string jsonObject = JsonConvert.SerializeObject(grid.Grid1, Formatting.Indented, new JsonSerializerSettings { }); try { if (UserIP != null) { UdpSender = new UdpClient(SendGridPort, AddressFamily.InterNetwork); ipUserEndPoint = new IPEndPoint(UserIP, SendGridPort); byte[] SendData = Encoding.ASCII.GetBytes(jsonObject); int sendedData = UdpSender.Send(SendData, SendData.Length, ipUserEndPoint); UdpSender.Close(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public UdpListenSend(TetrisGrid grid, int score, int[] pieces) { Grid = grid; Score = score; Pieces = pieces; }
public WaitingForm(TetrisGrid grid) { InitializeComponent(); playing = false; this.ShowDialog(); }
public TetrisGame() { mTetrisGrid = new TetrisGrid(this, new Rectangle(512 - 200, 40, 400, 768 - (40 + 44)), new Rectangle(512 - 480 + 10, 40, 290 - 50, 280)); Components.Add(mTetrisGrid); }