// Start a new game private void mnuNewGame_Click(object sender, EventArgs e) { using (frmOpponent f = new frmOpponent()) { DialogResult result = f.ShowDialog(); if (result != DialogResult.Cancel) { // Make sure board's file still exists if a new game is chosen if (!File.Exists(file)) { MessageBox.Show("New game failed to load because board's file was not found."); return; } // Stop the AI if a new game is chosen while the AI is thinking if (aiThread[0].IsAlive) { aiThread[0].Abort(); } if (aiThread[1].IsAlive) { aiThread[1].Abort(); } if (!endgame && (type == GameType.AIvsAI || (type == GameType.CPU && !playerTurn))) { stopai = true; } } // Set new game type based on the dialog's chosen item if (result == DialogResult.OK) { if (!endgame && (type == GameType.AIvsAI)) { stopai = true; } if (!SetGame(GameType.Human)) { return; } } else if (result == DialogResult.Yes) { if (!endgame && (type == GameType.AIvsAI)) { stopai = true; } SetGame(GameType.CPU); aiThread[1] = new Thread(aiThreadStart[1]); aiThread[1].IsBackground = true; } else if (result == DialogResult.Ignore) { stopai = false; if (!SetGame(GameType.AIvsAI)) { return; } aiThread[0] = new Thread(aiThreadStart[0]); aiThread[0].IsBackground = true; aiThread[1] = new Thread(aiThreadStart[1]); aiThread[1].IsBackground = true; int c = 1; while (!endgame && type == GameType.AIvsAI) { DoAI(c); c = (c == 1 ? 2 : 1); } } } }
// Start a new game private void mnuNewGame_Click(object sender, EventArgs e) { using (frmOpponent f = new frmOpponent()) { DialogResult result = f.ShowDialog(); if (result != DialogResult.Cancel) { // Make sure board's file still exists if a new game is chosen if (!File.Exists(file)) { MessageBox.Show("New game failed to load because board's file was not found."); return; } // Stop the AI if a new game is chosen while the AI is thinking if (aiThread[0].IsAlive) aiThread[0].Abort(); if (aiThread[1].IsAlive) aiThread[1].Abort(); if (!endgame && (type == GameType.AIvsAI || (type == GameType.CPU && !playerTurn))) stopai = true; } // Set new game type based on the dialog's chosen item if (result == DialogResult.OK) { if (!endgame && (type == GameType.AIvsAI)) stopai = true; if (!SetGame(GameType.Human)) return; } else if (result == DialogResult.Yes) { if (!endgame && (type == GameType.AIvsAI)) stopai = true; SetGame(GameType.CPU); aiThread[1] = new Thread(aiThreadStart[1]); aiThread[1].IsBackground = true; } else if (result == DialogResult.Ignore) { stopai = false; if (!SetGame(GameType.AIvsAI)) return; aiThread[0] = new Thread(aiThreadStart[0]); aiThread[0].IsBackground = true; aiThread[1] = new Thread(aiThreadStart[1]); aiThread[1].IsBackground = true; int c = 1; while (!endgame && type == GameType.AIvsAI) { DoAI(c); c = (c == 1 ? 2 : 1); } } } }