private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { string winner = null; var rules = new Rules(); rules.checkWinner(gb); if (gb.Winner != status.free) { switch (gb.Winner) { case status.draw: winner = "Hra skočila remízou!"; break; case status.whitePlayer: winner = "Bílý hráč zvítězil"; break; case status.blackPlayer: winner = "Černý hráč zvítězil"; break; } } if (e.Cancelled) { Action enableHistory = () => History.Enabled = true; Action enablePause = () => ButtonPause.Enabled = true; History.Invoke(enableHistory); ButtonPause.Invoke(enablePause); gb.drawBoard(); MessageBox.Show("Hra byla pozastavena"); Action setResumeText = () => ButtonPause.Text = "Pokračovat"; pauseButton.Invoke(setResumeText); } else if (e.Error != null) { MessageBox.Show(String.Format("Doslo k chybe pri vykonavani vypoctu {0}", e.Error)); } else if (winner != null) { MessageBox.Show(winner); pauseButton.Enabled = false; } else { Activated += FriskaDama_Activated; } }
private void fw_2ndClick(object sender, EventArgs e) { var form = Form.ActiveForm as Friska_dama; BackgroundWorker bw = form.bw; var fwClicked = (Fairway)sender; List <Fairway> playersFigures = rules.choosableFigures(this); List <string> posMoves = possibleMoves(From); if (fwClicked == From) { foreach (var fw in Board) { fw.Click -= fw_2ndClick; fw.Click += fw_1stClick; } if (ShowMoveHelp) { colorUp(); } From = null; form.statusBarLabel.Text = "Vyberte figurku, kterou chcete táhnout"; } else if (fwClicked != From && playersFigures.Contains(fwClicked)) { From = fwClicked; fairwayColorUp(this, From); } else if (posMoves.Contains(fwClicked.Name)) { addHistory(From, fwClicked); rules.makeMove(From, fwClicked, this, false); Winner = rules.checkWinner(this); from = null; foreach (var fw in Board) { fw.Click -= fw_2ndClick; fw.Click += fw_1stClick; } if (ShowMoveHelp) { colorUp(); } form.Activate(); form.FriskaDama_Activated(sender, e); } }
private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { string winner = null; Rules rules = new Rules(); rules.checkWinner(gb); if (gb.Winner != status.free) { switch (gb.Winner) { case status.draw: winner = "Hra skočila remízou!"; break; case status.whitePlayer: winner = "Bílý hráč zvítězil"; break; case status.blackPlayer: winner = "Černý hráč zvítězil"; break; } } if (e.Cancelled) { Action enableHistory = () => this.History.Enabled = true; Action enablePause = () => this.ButtonPause.Enabled = true; History.Invoke(enableHistory); ButtonPause.Invoke(enablePause); gb.drawBoard(); MessageBox.Show("Hra byla pozastavena"); Action setResumeText = () => this.ButtonPause.Text = "Pokračovat"; pauseButton.Invoke(setResumeText); } else if (e.Error != null) { MessageBox.Show(String.Format("Doslo k chybe pri vykonavani vypoctu {0}", e.Error)); } else if (winner != null) { MessageBox.Show(winner); this.pauseButton.Enabled = false; } else { this.Activated += this.FriskaDama_Activated; } }