private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { //Renderer render2 = new Renderer(jog2, tabForm2); Jogador jog2 = e.Argument as Jogador; jog2.StObserver = tStateMessage; jog2.MovementObserver = tMoveMessage; jog2.Start(); while (jog2.mStatus != PlayerStatus.Finalizado) { jog2.Jogar(); if (jog2.mStatus == PlayerStatus.CaminhoEncontrado) { string item = string.Join(",", jog2.mCaminho.Keys.ToList()); backgroundWorker1.ReportProgress(0, item); } // if (backgroundWorker1.CancellationPending) { mStatus = MyStatusForm.Completado_Parado_Cancelado; break; } } mStatus = MyStatusForm.Completado_Parado_Cancelado; e.Result = jog2; }
private void abrirToolStripButton1_Click(object sender, EventArgs e) { Jogador currentJogador = jog; bool enabled = timer1.Enabled; if (enabled) { timer1.Stop(); } OpenFileDialog openDIalog = new OpenFileDialog(); openDIalog.Filter = "Knight Simulator File (*.knight)|*.knight"; openDIalog.CheckPathExists = true; openDIalog.CheckFileExists = true; openDIalog.Title = "Choose a file with a simulation to load"; if (openDIalog.ShowDialog() == DialogResult.OK) { try { BinaryFormatter bf = new BinaryFormatter(); using (Stream input = File.OpenRead(openDIalog.FileName)) { jog = (Jogador)bf.Deserialize(input); } } catch (Exception ex) { MessageBox.Show("Unable to read the simulation file\r\n" + ex.Message, "Knight Simulator Error", MessageBoxButtons.OK, MessageBoxIcon.Error); jog = currentJogador; } } if (mStatus == MyStatusForm.Completado_Parado_Cancelado) { tabForm = new TabForm(); render = new Renderer(jog, tabForm); tabForm.Show(this); } else { render.mJogador = jog; render.ResizeTabuleiro(jog.Largura, jog.Altura); } jog.StObserver = iStateMessage; jog.MovementObserver = iMoveMessage; jog.Start(); if (enabled) { mStatus = MyStatusForm.PasseioInterativo; } else { mStatus = MyStatusForm.Pausado; } txLargura.Text = jog.Largura.ToString(); txAltura.Text = jog.Altura.ToString(); txPosX.Text = jog.posInicial.X.ToString(); txPosY.Text = jog.posInicial.Y.ToString(); ckTodasSolucoes.ThreeState = jog.TotalSolution; MoveChildForms(); UpdateForm(); if (enabled) { timer1.Start(); } }
private void lbStart_Click(object sender, EventArgs e) { if (mStatus == MyStatusForm.Completado_Parado_Cancelado) { int larg, alt, px, py; int tempInt; if (int.TryParse(txLargura.Text, out tempInt)) { larg = tempInt; } else { throw new ArgumentNullException(); } if (int.TryParse(txAltura.Text, out tempInt)) { alt = tempInt; } else { throw new ArgumentNullException(); } if (int.TryParse(txPosX.Text, out tempInt)) { px = tempInt; } else { throw new ArgumentNullException(); } if (int.TryParse(txPosY.Text, out tempInt)) { py = tempInt; } else { throw new ArgumentNullException(); } if ((px >= alt) || (py >= larg)) { MessageBox.Show("Posição Inicial fora do Tabuleiro", "Erro Knight Rider", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } jog = InitializeJogador(); tabForm = new TabForm(); render = new Renderer(jog, tabForm); tabForm.Show(this); jog.Start(); timer1.Start(); mStatus = MyStatusForm.PasseioInterativo; MoveChildForms(); UpdateForm(); } else { if (mStatus == MyStatusForm.PasseioInterativo) { timer1.Stop(); mStatus = MyStatusForm.Pausado; } else { timer1.Start(); mStatus = MyStatusForm.PasseioInterativo; } } UpdateForm(); }