protected void lightBoxClick(object sender, EventArgs e, LightBox.Coordinates coordinates) { LightBox clickedLightBox = LightBoxHelper.GetLightBoxByCoordinates(lightBoxes, coordinates); clickedLightBox.Active = !clickedLightBox.Active; foreach (LightBox neighbours in clickedLightBox.Neighbours) { neighbours.Active = !neighbours.Active; } bool win = LightBoxHelper.CheckWin(lightBoxes, gridSize); if (win) { DialogResult dialogResult = MessageBox.Show("Would you like to try again?", "Well Done", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { NewGame(); } else if (dialogResult == DialogResult.No) { Application.Exit(); } } }
public void NewGame() { SetLayout(); Random rd = new Random(); int xCoord = 0; int yCoord = 0; int activeCount = 0; for (int i = 0; i < (gridSize * gridSize); i++) { bool lightActive = rd.Next(0, 10) > 8;//checking greater than 8 to lower chances of initially starting with too many lightboxes if (lightActive) { activeCount++; } if (activeCount == 0 && xCoord == (gridSize - 1) && yCoord == (gridSize - 1))//if no lights have been turned on, turn last lightbox on { lightActive = true; } LightBox lightBox = new LightBox(lightActive, new LightBox.Coordinates(xCoord, yCoord)); lightBox.Light.Click += delegate(object sender, EventArgs e) { lightBoxClick(sender, e, lightBox.Location); }; lightBoxes.Add(lightBox); panelLayout.Controls.Add(lightBox.Light); xCoord++; if (xCoord > (gridSize - 1)) { xCoord = 0; yCoord++; } } LightBoxHelper.SetLightBoxNeighbours(lightBoxes); }
private void runStopOnUI(object obj) { btnRunStop.Content = "运行"; btnPaush.Content = "继续"; btnPaush.IsEnabled = false; LightBoxHelper.stop(); btnReloadModels.IsEnabled = true; }
private void runBeginOnUI(object obj) { btnRunStop.Content = "停止"; btnPaush.Content = "暂停"; btnPaush.IsEnabled = true; LightBoxHelper.start(); btnReloadModels.IsEnabled = false; }
private void btnOk_Click(object sender, RoutedEventArgs e) { var runTime = tbKeepTime.Text; foreach (LBMsg msg in lBModel.ListLBMsg) { msg.KeepTime = Convert.ToInt16(runTime); LightBoxHelper.updateModelLBMsg(msg); } WriteXmlHelper.saveModel(lBModel); Close(); }
public override void ChannelRead(IChannelHandlerContext context, object message) { var buffer = message as IByteBuffer; if (buffer != null) { String msg = buffer.ToString(Encoding.UTF8); switch (msg) { case "Control:Reset": //复位 context.WriteAndFlushAsync(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes("Control:Reset"))); LightBoxHelper.reset(); break; case "Control:Pause": //暂停 context.WriteAndFlushAsync(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes("Control:Pause"))); MainWindow.ins.pasued(); break; case "Control:Stop": //停止 context.WriteAndFlushAsync(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes("Control:Stop"))); MainWindow.ins.runStop(); break; case "Control:Resume": //继续 context.WriteAndFlushAsync(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes("Control:Resume"))); MainWindow.ins.resume(); break; case "Page:Prev": //上一页 context.WriteAndFlushAsync(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes("Page:Prev"))); LightBoxHelper.prevPage(); break; case "Page:Next": //下一页 context.WriteAndFlushAsync(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes("Page:Next"))); LightBoxHelper.nextPage(); break; default: context.WriteAndFlushAsync(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes(msg))); break; } Console.WriteLine("Received from client: " + msg); } //context.WriteAsync(message); }
public MainWindow() { InitializeComponent(); m_SyncContext = SynchronizationContext.Current; ins = this; //logger.Info("indo"); //logger.Error("error"); ThreadPool.SetMinThreads(1000, 500); BaseConfig.ins.init(); ConfigHelper.init(); labelRowColumn.Content = BaseConfig.ins.Rows + "行" + BaseConfig.ins.Columns + "列"; menuRunOnPower.IsChecked = ConfigHelper.IS_POWER_RUN; menuWaitVideo.IsChecked = ConfigHelper.IS_WAIT_VIDEO; //LightBoxHelper.SelectedModel = null; LightBoxHelper.modelChanged += LightBoxHelper_modelChanged; LightBoxHelper.initModels(); listBoxModels.ItemsSource = LightBoxHelper.listModel; //SmsComm.ins.eventStateChanged += SmsComm_eventStateChanged; DataComm.ins.eventStateChanged += DataVideo_eventStateChanged; ECANHelper.ins.eventStateChanged += DataSms_eventStateChanged; ECANHelper.ins.eventBoxStateChanged += Ins_eventBoxStateChanged; DataComm.ins.init(); DataComm.ins.open(); //SmsComm.ins.init(); //SmsComm.ins.open(); string path = AppDomain.CurrentDomain.BaseDirectory; string str1 = Process.GetCurrentProcess().MainModule.FileName; Console.WriteLine(path + ",," + str1); LightBoxHelper.startCheckSysTimeThread(); NettyHelper.start(); ECANHelper.ins.openDevice(); }
private void btnOk_Click(object sender, RoutedEventArgs e) { int waitMinute = comboBoxMinute.SelectedIndex; int waitSecond = comboBoxSeconds.SelectedIndex; bool runAll = (bool)(cbRunAll.IsChecked); if (lBModel.MWaitTime.WaitMM != waitMinute || lBModel.MWaitTime.WaitSS != waitSecond) { lBModel.MWaitTime.WaitMM = waitMinute; lBModel.MWaitTime.WaitSS = waitSecond; WriteXmlHelper.saveModel(lBModel); } lBModel.runAll = runAll; string newName = txtName.Text; string oldName = lBModel.ModelName; LightBoxHelper.updateModel(lBModel); WriteXmlHelper.saveModel(lBModel); if (!newName.Equals(oldName)) { if (string.IsNullOrEmpty(newName)) { MessageBox.Show("模式名称不能为空"); return; } if (LightBoxHelper.modelNameIsHaved(newName)) { MessageBox.Show("模式名称已存在"); return; } LightBoxHelper.modelRename(oldName, newName); lBModel.ModelName = newName; } DialogResult = true; }
private void listBoxModels_SelectionChanged(object sender, SelectionChangedEventArgs e) { int index = listBoxModels.SelectedIndex; if (index >= 0 && index < LightBoxHelper.listModel.Count) { if (LightBoxHelper.isRunning) { if (index == 0) { LightBoxHelper.modelIndex = LightBoxHelper.listModel.Count; } else { LightBoxHelper.modelIndex = index - 1; } } else { LightBoxHelper.setModelSelected(LightBoxHelper.listModel[index]); } } }
private void setListBox(List <LightBox> listSelectedBox) { if (listSelectedBox.Count > 0) { WidLightBoxEdit wid = new WidLightBoxEdit(listSelectedBox[0].lBMsg); wid.ShowDialog(); if (wid.DialogResult == true) { double waitTime = wid.waitTime; Color color = Colors.Gray; foreach (LightBox box in lightBoxes) { if (box.lBMsg.WaitTime == waitTime) { color = box.oldColor; break; } } if (color == Colors.Gray) { color = GetRandomColor(); } foreach (LightBox box in listSelectedBox) { box.lBMsg.WaitTime = waitTime; box.lBMsg.RunTime = wid.runTime; box.lBMsg.KeepTime = wid.keepTime; box.lBMsg.RepeatCount = wid.repeatCount; box.refresh(); box.setSelected(); box.setBackGroundColor(color); LightBoxHelper.updateModelLBMsg(box.lBMsg); } } } }
private void btnDown_Click(object sender, RoutedEventArgs e) { LightBoxHelper.nowModelDown(); listBoxModels.ItemsSource = null; listBoxModels.ItemsSource = LightBoxHelper.listModel; }
private void btnReloadModels_Click(object sender, RoutedEventArgs e) { LightBoxHelper.initModels(); listBoxModels.ItemsSource = LightBoxHelper.listModel; }
private void resumeOnUI(object obj) { suspend = false; LightBoxHelper.setResume(); btnPaush.Content = "暂停"; }
private void pasuedOnUI(object obj) { suspend = true; LightBoxHelper.setSuspend(); btnPaush.Content = "继续"; }
private void optionsToolStripMenuItem_Click(object sender, EventArgs e) { gridSize = LightBoxHelper.ShowOptions(gridSize); NewGame(); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { LightBoxHelper.delModel(lBModel.ModelName); DialogResult = true; //Close(); }