private void Form1_Shown(object sender, EventArgs e) { this.Size = new Size(800, 800); this.Location = new Point(400, 0); //this.TopMost = true; { TLP = new MyTableLayoutPanel((panelCount + 1) / 2, Math.Min(panelCount, 2), new Func <int, string>((int n) => { string ans = ""; for (int i = 0; i < n; i++) { ans += "P"; } return(ans); })((panelCount + 1) / 2), panelCount == 1 ? "P" : "PP"); for (int i = 0; i < panelCount; i++) { TLP.AddControl(new GamePanel(port + i, i == 0 ? 20 : fps), i / 2, i % 2); } this.Controls.Add(TLP); } this.FormClosing += Form1_FormClosing; { Thread thread = new Thread(() => { Random rand = new Random(); while (true) { public_random = rand.Next(int.MaxValue); Thread.Sleep(500); } }); thread.IsBackground = true; thread.Start(); } }
public Game() { controlPanel = new MyTableLayoutPanel(3, 1, "AAS300", "A"); { { imageFeedBack = new MyCheckBox("Image Feed Back"); imageFeedBack.Checked = true; controlPanel.AddControl(imageFeedBack, 0, 0); } { showImageFeedBack = new MyCheckBox("Show Image Feed Back"); showImageFeedBack.Checked = false; showImageFeedBack.CheckedChanged += ShowImageFeedBack_CheckedChanged; controlPanel.AddControl(showImageFeedBack, 0, 0); } { Panel pnl = new Panel(); { pnl.Dock = DockStyle.Fill; pnl.AutoScroll = true; { generalSettings = new MyInputField(); generalSettings.Dock = DockStyle.Top; generalSettings.AddField("Image Feed Back Width", imageFeedBackSize.Width.ToString()).TextChanged += (o, e) => { try { imageFeedBackSize.Width = int.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("Image Feed Back Height", imageFeedBackSize.Height.ToString()).TextChanged += (o, e) => { try { imageFeedBackSize.Height = int.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("Port", SocketHandler.port.ToString()).TextChanged += (o, e) => { try { SocketHandler.port = int.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("darryMode", darryMode.ToString()).TextChanged += (o, e) => { try { darryMode = bool.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("max_upward_speed", max_upward_speed.ToString()).TextChanged += (o, e) => { try { max_upward_speed = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("alpha", alpha.ToString()).TextChanged += (o, e) => { try { alpha = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("重利", gravity.ToString()).TextChanged += (o, e) => { try { gravity = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("升力", liftForce.ToString()).TextChanged += (o, e) => { try { liftForce = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("可見障礙物數量", obstacleCount.ToString()).TextChanged += (o, e) => { try { obstacleCount = int.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("存活區的範圍", rangeY.ToString()).TextChanged += (o, e) => { try { rangeY = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物距離的範圍", obstacleDistance.ToString()).TextChanged += (o, e) => { try { obstacleDistance = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物寬度(通過時間)的範圍", obstacleWidth.ToString()).TextChanged += (o, e) => { try { obstacleWidth = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物通道底部高度的範圍", obstacleY.ToString()).TextChanged += (o, e) => { try { obstacleY = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物通道寬度的範圍", obstacleHeight.ToString()).TextChanged += (o, e) => { try { obstacleHeight = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; pnl.Controls.Add(generalSettings); } } controlPanel.AddControl(pnl, 2, 0); } } Reset(); Update(true); }
public Form1() { //MessageBox.Show(Color.FromArgb(127,127,127).ToString()); this.Size = new Size(1200, 750); this.FormClosing += Form1_FormClosing; { MyTableLayoutPanel tlp = new MyTableLayoutPanel(1, 2, "A", "PP"); { TLP = new MyTableLayoutPanel(2, 1, "AP", "P"); { TLP.AddControl(Game.controlPanel, 0, 0); } { TXB = new MyTextBox(true); TLP.AddControl(TXB, 1, 0); } tlp.AddControl(TLP, 0, 0); } { PictureBox pbx = new PictureBox(); pbx.Image = new Bitmap(pbx.Width, pbx.Height); pbx.Dock = DockStyle.Fill; pbx.SizeMode = PictureBoxSizeMode.Zoom; /*pbx.SizeChanged += (sender, e) => * { * SocketHandler_logAppended(pbx.Size.ToString()); * pbx.Image.Dispose(); * pbx.Image = new Bitmap(pbx.Width, pbx.Height); * };*/ new Thread(() => { while (true) { Thread.Sleep(20); Do(() => { var bmp = new Bitmap(game.imageFeedBackSize.Width, game.imageFeedBackSize.Height); //new Bitmap(pbx.Width, pbx.Height); this.Text = bmp.Size.ToString(); << << << < HEAD game.drawImage(bmp, true); == == == = game.drawImage(bmp, false);
public Form1() { this.Size = new Size(750, 750); this.FormClosing += Form1_FormClosing; { TLP = new MyTableLayoutPanel(2, 1, "AP", "P"); { TLP.AddControl(game.inputField, 0, 0); } { TXB = new MyTextBox(true); TLP.AddControl(TXB, 1, 0); } this.Controls.Add(TLP); } socketHandler.logAppended += SocketHandler_logAppended; socketHandler.msgReceived += SocketHandler_msgReceived; socketHandler.Start(); }
public Game() { controlPanel = new MyTableLayoutPanel(2, 1, "AA", "A"); { generalSettings = new MyInputField(); generalSettings.AddField("Port", SocketHandler.port.ToString()).TextChanged += (o, e) => { try { SocketHandler.port = int.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("darryMode", darryMode.ToString()).TextChanged += (o, e) => { try { darryMode = bool.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("max_upward_speed", max_upward_speed.ToString()).TextChanged += (o, e) => { try { max_upward_speed = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("alpha", alpha.ToString()).TextChanged += (o, e) => { try { alpha = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("重利", gravity.ToString()).TextChanged += (o, e) => { try { gravity = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("升力", liftForce.ToString()).TextChanged += (o, e) => { try { liftForce = double.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("可見障礙物數量", obstacleCount.ToString()).TextChanged += (o, e) => { try { obstacleCount = int.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("存活區的範圍", rangeY.ToString()).TextChanged += (o, e) => { try { rangeY = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物距離的範圍", obstacleDistance.ToString()).TextChanged += (o, e) => { try { obstacleDistance = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物寬度(通過時間)的範圍", obstacleWidth.ToString()).TextChanged += (o, e) => { try { obstacleWidth = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物通道底部高度的範圍", obstacleY.ToString()).TextChanged += (o, e) => { try { obstacleY = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; generalSettings.AddField("障礙物通道寬度的範圍", obstacleHeight.ToString()).TextChanged += (o, e) => { try { obstacleHeight = Interval.Parse((o as MyTextBox).Text); } catch (Exception) { MessageBox.Show("格式不正確"); } }; controlPanel.AddControl(generalSettings, 1, 0); } Reset(); Update(true); }
public Form1() { this.Size = new Size(700, 500); this.FormClosing += Form1_FormClosing; { TLPmain = new MyTableLayoutPanel(2, 1, "PA", "P"); { TXBoutput = new MyTextBox(true); TLPmain.AddControl(TXBoutput, 0, 0); } { TLPbtn = new MyTableLayoutPanel(1, 5, "A", $"AAAPS{Database.scopeSize.Width}"); { BTNstart = new MyButton("Start"); BTNstart.Click += BTNstart_Click; TLPbtn.AddControl(BTNstart, 0, 0); } { BTNscan = new MyButton("Scan"); BTNscan.Click += BTNscan_Click; TLPbtn.AddControl(BTNscan, 0, 1); } { CHBpressKey = new MyCheckBox("Press Key"); CHBpressKey.CheckedChanged += CHBpressKey_CheckedChanged; CHBpressKey.Checked = true; TLPbtn.AddControl(CHBpressKey, 0, 2); } { LBL = new MyLabel(""); TLPbtn.AddControl(LBL, 0, 3); } { PBX = new PictureBox(); PBX.Dock = DockStyle.Fill; PBX.SizeMode = PictureBoxSizeMode.AutoSize; TLPbtn.AddControl(PBX, 0, 4); } TLPmain.AddControl(TLPbtn, 1, 0); } this.Controls.Add(TLPmain); } socketHandler = new SocketHandler(); socketHandler.logAppended += SocketHandler_logAppended; socketHandler.msgReceived += SocketHandler_msgReceived; { Thread thread = new Thread(() => { int pre_count = 0; while (true) { Thread.Sleep(5000); if (socketHandler.dataConnectionCounter != pre_count) SocketHandler_logAppended((pre_count = socketHandler.dataConnectionCounter).ToString() + " communications"); } }); thread.IsBackground = true; thread.Start(); } { Thread thread = new Thread(() => { while (true) { Thread.Sleep(500); PBX.Invoke(new Action(() => { var bmp = getFeedBackImage(); if (bmp == null) LBL.Text = "Unavailable"; else LBL.Text = (IsLive(bmp) ? "Alive" : "Dead"); var preImg = PBX.Image; PBX.Image = bmp; if (preImg != null) preImg.Dispose(); })); } }); thread.IsBackground = true; thread.Start(); }
public GamePanel(int _port, double fps) { this.Dock = DockStyle.Fill; port = _port; socketHandler = new SocketHandler(port); game = new Game(socketHandler, new Random(Form1.public_random)); //MessageBox.Show(Color.FromArgb(127,127,127).ToString()); //this.Size = new Size(1200, 750); { TLPmain = new MyTableLayoutPanel(1, 2, "A", "S1P"); { TLPctrl = new MyTableLayoutPanel(2, 1, "PP", "P"); TLPctrl.AutoSize = false; { TLPctrl.AddControl(game.controlPanel, 0, 0); } { TXB = new MyTextBox(true); TLPctrl.AddControl(TXB, 1, 0); } TLPmain.AddControl(TLPctrl, 0, 0); } { PictureBox pbx = new PictureBox(); pbx.Image = new Bitmap(pbx.Width, pbx.Height); pbx.Dock = DockStyle.Fill; pbx.SizeMode = PictureBoxSizeMode.Zoom; /*pbx.SizeChanged += (sender, e) => * { * SocketHandler_logAppended(pbx.Size.ToString()); * pbx.Image.Dispose(); * pbx.Image = new Bitmap(pbx.Width, pbx.Height); * };*/ bool humanFriendly = true; pbx.Click += (object sender, EventArgs e) => { humanFriendly ^= true; }; pbx.DoubleClick += Pbx_DoubleClick; { Thread thread = new Thread(() => { while (true) { Thread.Sleep((int)Math.Ceiling(1000.0 / fps)); var bmp = (humanFriendly ? new Bitmap(pbx.Width, pbx.Height) : new Bitmap(game.imageFeedBackSize.Width, game.imageFeedBackSize.Height)); game.drawImage(bmp, humanFriendly); Do(() => { //this.Text = bmp.Size.ToString(); //{ // BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); // unsafe // { // byte *p=(byte*)bd.Scan0.ToPointer // } //} var img = pbx.Image; pbx.Image = bmp; img.Dispose(); }); } }); thread.IsBackground = true; thread.Start(); } TLPmain.AddControl(pbx, 0, 1); } this.Controls.Add(TLPmain); } socketHandler.logAppended += SocketHandler_logAppended; socketHandler.msgReceived += SocketHandler_msgReceived; socketHandler.Start(); { Thread thread = new Thread(() => { int pre_count = 0; while (true) { Thread.Sleep(5000); if (socketHandler.dataConnectionCounter != pre_count) { SocketHandler_logAppended((pre_count = socketHandler.dataConnectionCounter).ToString() + " communications"); } } }); thread.IsBackground = true; thread.Start(); } }
private void InitializeControls() { this.FormClosing += Form1_FormClosing; { TLP = new MyTableLayoutPanel(5, 1, "PAAAA", "P"); { { LBL = new MyLabel(""); status = "Q, W, O: control\r\nP: restart all"; TLP.AddControl(LBL, 0, 0); } { MyTableLayoutPanel tlp = new MyTableLayoutPanel(1, 2, "A", "AA"); { PBX = new PictureBox(); PBX.Dock = DockStyle.Fill; PBX.SizeMode = PictureBoxSizeMode.AutoSize; PBX.Image = Properties.Resources.buttonDark; tlp.AddControl(PBX, 0, 0); } { Panel pnl = new Panel(); pnl.Dock = DockStyle.Fill; pnl.AutoSize = true; pnl.AutoSizeMode = AutoSizeMode.GrowAndShrink; PictureBox pbx = new PictureBox(); pbx.Dock = DockStyle.Fill; pbx.SizeMode = PictureBoxSizeMode.Zoom; pbx.Image = Properties.Resources.computer; MyLabel lbl = new MyLabel(""); lbl.Font = new Font("Consolas", 8, FontStyle.Bold); lbl.Dock = DockStyle.None; lbl.ForeColor = Color.FromArgb(64, 0, 0, 0); lbl.BackColor = Color.Transparent; lbl.Parent = pbx; //{ // Bitmap bmp = new Bitmap(1, 1); // bmp.SetPixel(0, 0, Color.Transparent); // lbl.BackgroundImage = bmp; //} //pnl.Controls.Add(lbl); pnl.Controls.Add(pbx); tlp.AddControl(pnl, 0, 1); Thread thread = new Thread(() => { Thread.Sleep(3000); while (true) { Thread.Sleep(20); StringBuilder s = new StringBuilder(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 30; j++) { s.Append(random.Next(0, 2) == 0 ? '0' : '1'); } s.Append("\r\n"); } lbl.Invoke(new Action(() => { lbl.Text = s.ToString(); })); } }); thread.IsBackground = true; thread.Start(); } TLP.AddControl(tlp, 1, 0); } { TB = new TrackBar(); TB.Dock = DockStyle.Fill; TB.Minimum = 0; TB.Maximum = 1000; TLP.AddControl(TB, 2, 0); } { TXB = new MyTextBox(false); TXB.KeyDown += Form1_KeyDown; TXB.KeyUp += Form1_KeyUp; TXB.TextChanged += (object s, EventArgs e1) => { TXB.Text = null; }; TLP.AddControl(TXB, 3, 0); } { IFD = new MyInputField(); IFD.AddField("Play speed (FPS)", FPS.ToString()).TextChanged += (object s, EventArgs e1) => { double t; if (!double.TryParse((s as TextBox).Text, out t)) { MessageBox.Show("格式不正確"); } else { FPS = t; } }; TLP.AddControl(IFD, 4, 0); } } this.Controls.Add(TLP); } }
public Form1() { //MessageBox.Show(Color.FromArgb(127,127,127).ToString()); this.Size = new Size(1200, 750); this.FormClosing += Form1_FormClosing; { MyTableLayoutPanel tlp = new MyTableLayoutPanel(1, 2, "A", "PP"); { TLP = new MyTableLayoutPanel(2, 1, "AP", "P"); { TLP.AddControl(game.controlPanel, 0, 0); } { TXB = new MyTextBox(true); TLP.AddControl(TXB, 1, 0); } tlp.AddControl(TLP, 0, 0); } { PictureBox pbx = new PictureBox(); pbx.Image = new Bitmap(pbx.Width, pbx.Height); pbx.Dock = DockStyle.Fill; pbx.SizeMode = PictureBoxSizeMode.Normal; /*pbx.SizeChanged += (sender, e) => * { * SocketHandler_logAppended(pbx.Size.ToString()); * pbx.Image.Dispose(); * pbx.Image = new Bitmap(pbx.Width, pbx.Height); * };*/ new Thread(() => { while (true) { Thread.Sleep(500); Do(() => { var bmp = new Bitmap(pbx.Width, pbx.Height); this.Text = bmp.Size.ToString(); game.drawImage(bmp); pbx.Image.Dispose(); pbx.Image = bmp; }); } }).Start(); tlp.AddControl(pbx, 0, 1); } this.Controls.Add(tlp); } socketHandler.logAppended += SocketHandler_logAppended; socketHandler.msgReceived += SocketHandler_msgReceived; socketHandler.Start(); Thread thread = new Thread(() => { int pre_count = 0; while (true) { Thread.Sleep(5000); if (socketHandler.dataConnectionCounter != pre_count) { SocketHandler_logAppended((pre_count = socketHandler.dataConnectionCounter).ToString() + " communications"); } } }); thread.IsBackground = true; thread.Start(); }