private void Game_FormClosing(object sender, FormClosingEventArgs e) { if (!saved && !isFinished) { if (MessageBox.Show("Do you want to leave the game?", "Leave Game", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { e.Cancel = true; return; } } state = new State(); state.Computer = computer; state.Player = player; state.Score = score; state.Turn = Turn; state.Mute = MuteClicked; ComputerTimer.Stop(); ShootTimer.Stop(); }
private void ComputerTimer_Tick(object sender, EventArgs e) { label2.Text = Turn ? "Your turn" : "Bot's turn"; lblScore.Text = score.ToString(); if (score < 0) { lblScore.ForeColor = Color.Red; } else if (score > 0) { lblScore.ForeColor = Color.Green; } if (!Turn) { dgvComputer.Enabled = false; ShootTimer.Start(); } if (Turn) { dgvComputer.Enabled = true; ShootTimer.Stop(); } if (computer.Won()) { isFinished = true; ComputerTimer.Interval = 999999999; ShootTimer.Interval = 999999999; ShootTimer.Stop(); ShootTimer.Enabled = false; ComputerTimer.Enabled = false; dgvComputer.Enabled = false; ShootTimer.Enabled = false; if (score > 0) { View.InputScore form = new View.InputScore(); if (form.ShowDialog() == DialogResult.OK) { saveFile(form.winnerName, score); } } ComputerTimer.Dispose(); } if (player.Won()) { isFinished = true; ComputerTimer.Enabled = false; dgvComputer.Enabled = false; ComputerTimer.Interval = 999999999; ShootTimer.Interval = 999999999; ShootTimer.Stop(); dgvComputer.Enabled = false; ShootTimer.Dispose(); ComputerTimer.Dispose(); computer.ShowEndShips(dgvComputer); if (MessageBox.Show("YOU LOST! Do you want to play a new game?", "LOST", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { newGame(); } } }