// EndGame Button private void button1_Click(object sender, EventArgs e) { // Ask user to play new game DialogResult dialogResult = MessageBox.Show("Play New Game?", "Quit Menu", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { Form myForm = new FindTheIslandGame(); myForm.Show(); this.Dispose(); } else if (dialogResult == DialogResult.No) { Application.Exit(); } }
// Submit Button private void button2_Click(object sender, EventArgs e) { int rowguess = Int32.Parse(userrow); int colguess = Int32.Parse(usercol); if ((rowguess <= 0) || (rowguess > linerows)) { MessageBox.Show("Invalid Row Input"); } else if ((colguess <= 0) || (colguess > linecols)) { MessageBox.Show("Invalid Column Input"); } else { System.Drawing.Graphics filledRect; filledRect = this.CreateGraphics(); // Show user guess on map. SolidBrush brush = new SolidBrush(Color.Brown); Rectangle rect = new Rectangle((20 * (colguess)), (20 * (rowguess)), 20, 20); filledRect.FillRectangle(brush, rect); if (Map[(rowguess - 1), (colguess - 1)] == true) { Direct.Text = "Won"; MessageBox.Show("Congratulations: You found the island!"); DialogResult dialogResult = MessageBox.Show("Play New Game?", "Game Menu", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { Form myForm = new FindTheIslandGame(); myForm.Show(); this.Dispose(); } else if (dialogResult == DialogResult.No) { Application.Exit(); } } else { // Generate headinmg based on turn number if ((userturn % 2) == 0) { if ((rowguess - randrow) < 0) { Direct.Text = "South"; } else if ((rowguess - randrow) == 0) { Direct.Text = "Center"; } if ((rowguess - randrow) > 0) { Direct.Text = "North"; } userturn++; } else { // Generate headinmg based on turn number if ((colguess - randcol) < 0) { Direct.Text = "East"; } else if ((colguess - randcol) == 0) { Direct.Text = "Center"; } if ((colguess - randcol) > 0) { Direct.Text = "West"; } userturn++; } } } }