p-GeoGame / CSharp_GeographyGame / worldmapForm.cs
worldmapForm.cs
Raw
// Continents: https://www.mapsofworld.com/maps/world-map-with-continents.jpg
// Continents & Oceans: https://www.nationsonline.org/maps/World-Continents-Topographic-map.jpg
// As countries are added, need to update totEntries, and tbsFillCorrectAnswers() function

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
using System.Diagnostics;
using MySql.Data.MySqlClient;
using System.Threading;
using Microsoft.VisualBasic;


namespace CSharp_GeographyGame
{
    public partial class worldmapForm : Form
    {

        string connectionString;
        SqlConnection connection;
        double corCount = 0;
        double perNum = 0.0;
        bool clockIt = false;
        string nID;
        int totEntries = 26; // make sure this matches lblTotal number (visually) on form

        public worldmapForm(string inName)
        {
            nID = inName;
            InitializeComponent();
            bgWorkerW.DoWork += bgWorkerW_DoWork;
            bgWorkerW.ProgressChanged += bgWorkerW_ProgressChanged;
            bgWorkerW.WorkerReportsProgress = true;
            userToolStripMenuItem.Text = "User: " + nID;
            connectionString = ConfigurationManager.ConnectionStrings["CSharp_GeographyGame.Properties.Settings.userScoresConnectionString"].ConnectionString;
        }

        private void worldmapForm_Shown(object sender, EventArgs e)
        {
            bgWorkerW.RunWorkerAsync();
        }

        private void insertDataLocally(double scoreID, string sqlFormattedDate)
        {
            //// FOR LOCAL DATABASE
            string con = "INSERT INTO USMapscores ([Name], [Score], [Time], [Date]) VALUES(@name, @score, @time, @date)";
            using (connection = new SqlConnection(connectionString))
            using (SqlCommand command = new SqlCommand(con, connection))
            {
                try
                {
                    connection.Open();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                command.Parameters.AddWithValue("@name", nID);
                command.Parameters.AddWithValue("@score", scoreID);
                command.Parameters.AddWithValue("@time", lblClock.Text);
                command.Parameters.AddWithValue("@date", sqlFormattedDate);
                int result = command.ExecuteNonQuery();
                // Check Error
                if (result < 0)
                    MessageBox.Show("Error inserting data into database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                connection.Close();
            }
        }

        private void insertDataOnline(double scoreID, string sqlFormattedDate)
        {
            //// FOR ONLINE DATABASE
            string conWeb = "Server = remotemysql.com; Port = 3306; database = 2Ds6YxqaDW; username = 2Ds6YxqaDW; password = VJKMThFkcO";
            MySqlConnection connTwo = new MySqlConnection(conWeb);
            MySqlCommand commWeb = connTwo.CreateCommand();
            commWeb.CommandType = System.Data.CommandType.Text;
            commWeb.CommandText = "INSERT INTO onUSmapscores (Name, Score, Time, Date) VALUES(@name, @score, @time, @date)";
            commWeb.Parameters.AddWithValue("@name", nID);
            commWeb.Parameters.AddWithValue("@score", scoreID);
            commWeb.Parameters.AddWithValue("@time", lblClock.Text);
            commWeb.Parameters.AddWithValue("@date", sqlFormattedDate);
            try
            {
                connTwo.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            commWeb.ExecuteNonQuery();
            connTwo.Close();
        }

        private void vbScoreInputDialog(double scoreID, string sqlFormattedDate)
        {
            //// Using microsoft.visualbasic reference allowing the user to choose where to submit his score (allows offline score submission)
            string message, title, defaultValue;
            object myValue;

            message = "Would you like to submit your results to the Local, Online, or Both databases?\n" +
                "Type the following in the textbox below:\n" +
                "Local\n" +
                "Online\n" +
                "Both";
            title = "Score Submission";
            defaultValue = "Both";

            bool validSelection = false;

            do
            {
                myValue = Interaction.InputBox(message, title, defaultValue); // input box

                if ((string)myValue == "")
                {
                    object uChoice = Microsoft.VisualBasic.Interaction.MsgBox("Are you sure you don't want to submit your score?", MsgBoxStyle.YesNo, "Score Submission");
                    if ((int)uChoice == 6)
                    {
                        System.Environment.Exit(0);
                    }
                    else
                    {
                        // do nothing, reset back to original input box
                    }
                }
                else if ((string)myValue == "Local" || (string)myValue == "local")
                {
                    insertDataLocally(scoreID, sqlFormattedDate);
                    validSelection = true;
                }
                else if ((string)myValue == "Online" || (string)myValue == "online")
                {
                    insertDataOnline(scoreID, sqlFormattedDate);
                    validSelection = true;
                }
                else if ((string)myValue == "Both" || (string)myValue == "both")
                {
                    insertDataLocally(scoreID, sqlFormattedDate);
                    insertDataOnline(scoreID, sqlFormattedDate);
                    validSelection = true;
                }
                else
                {
                    Microsoft.VisualBasic.Interaction.MsgBox("Wrong input entered... Please try again and this time, read.");
                }
            } while (validSelection == false);
            /////
        }

        private void BrowserCheck()
        {
            var RunningProcessPaths = ProcessFileNameFinderClass.GetAllRunningProcessFilePaths();

            if (RunningProcessPaths.Contains("firefox.exe"))
            {
                foreach (Process proc in Process.GetProcessesByName("firefox"))
                    proc.Kill();
                MessageBox.Show(new Form { TopMost = true }, "Firefox was open... No no no.", "Suspicious", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            if (RunningProcessPaths.Contains("chrome.exe"))
            {
                foreach (Process proc in Process.GetProcessesByName("chrome"))
                    proc.Kill();
                MessageBox.Show(new Form { TopMost = true }, "Chrome was open... No no no.", "Suspicious", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            if (RunningProcessPaths.Contains("msedge.exe"))
            {
                foreach (Process proc in Process.GetProcessesByName("msedge"))
                    proc.Kill(); // reference: https://social.msdn.microsoft.com/Forums/vstudio/en-US/50ecbcf2-d2d3-4f21-9775-5b8be1bd4346/how-to-terminate-a-process-in-c?forum=csharpgeneral
                MessageBox.Show(new Form { TopMost = true }, "Microsoft Edge was open... No no no.", "Suspicious", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }

        private void bgWorkerW_DoWork(object sender, DoWorkEventArgs e)
        {
            double cCount = 0;
            double prev = 0;
            pbStatusW.Invoke((MethodInvoker)(() => pbStatusW.Minimum = 0));
            pbStatusW.Invoke((MethodInvoker)(() => pbStatusW.Maximum = totEntries));
            while (true)
            {
                cCount = corCount;

                if (cCount > prev)
                {
                    prev = cCount;
                    pbStatusW.Invoke((MethodInvoker)(() => pbStatusW.Increment(1)));
                    bgWorkerW.ReportProgress((int)cCount);
                    //Thread.Sleep(1000);
                }
                Application.DoEvents();

                if (cCount == totEntries)
                {
                    break; // ***is needed for the bgWorker to end to run bgWorker_RunWorkerCompleted
                }
            }
        }

        private void bgWorkerW_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            pbStatusW.Value = e.ProgressPercentage;
        }

        private void bgWorkerW_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                MessageBox.Show("Error. I suck.");
            }
            else if (e.Error != null)
            {
                MessageBox.Show("Ran into an unknown error... I really suck.");
            }
            else
            {
                if (lblCorrect.Text.ToString() == lblTotal.Text.ToString())
                {
                    lblClock.ForeColor = System.Drawing.Color.Green;
                }
                timerClockW.Stop();
                i = 0;
                clockIt = false;
                tbsEnableDisable();
                System.Diagnostics.Process.Start("https://media1.tenor.com/images/2386d12e54aa11ce0298d100954d982a/tenor.gif");
                string xTract = lblPercentage.Text.Trim(new Char[] { '%', '*', '.' });
                int xConversion;
                Int32.TryParse(xTract, out xConversion);
                double scoreID = xConversion;
                DateTime myDateTime = DateTime.Now;
                string sqlFormattedDate = myDateTime.ToString("MM-dd-yyyy HH:mm:ss.fff");

                vbScoreInputDialog(scoreID, sqlFormattedDate);

                DialogResult diaBox;
                diaBox = MessageBox.Show("Great job, you are a genius! Would you like to reset the map (yes) or keep showing your glorious results (no)?", "Congratulations", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (diaBox == DialogResult.Yes)
                {
                    lblClock.ForeColor = System.Drawing.Color.Black;
                    ResetText();
                    lblClock.Text = "00:00:00";
                    pbStatusW.Value = 0;
                    lblPercentage.Text = "%";
                    clearTextBoxes();
                    btnPause.Enabled = false;
                    btnQuit.Enabled = false;
                }
                if (diaBox == DialogResult.No)
                {
                    btnBegin.Enabled = false;
                    btnPause.Enabled = false;
                    btnQuit.Enabled = false;
                }

            }
        }

        private void PercentageFormula()
        {
            perNum = ((corCount / totEntries) * 100);
            lblPercentage.Text = perNum.ToString("0.###") + "%";
        }

        private void clearTextBoxes()
        {
            foreach (Control tb in this.Controls)
            {
                if (tb is TextBox)
                {
                    ((TextBox)tb).Text = String.Empty;
                    ((TextBox)tb).Font = new Font(((TextBox)tb).Font, FontStyle.Regular);
                }
            }
        }

        private void tbsClearIncorrectText()
        {
            foreach (Control tb in this.Controls)
            {
                if (tb is TextBox)
                {
                    if (((TextBox)tb).Enabled == true && !String.IsNullOrEmpty(((TextBox)tb).Text))
                    {
                        ((TextBox)tb).Text = String.Empty;
                    }
                }

            }
        }

        private void tbsEnableDisable()
        {
            if (clockIt == true)
            {
                foreach (Control tb in this.Controls)
                {
                    if (tb is TextBox)
                    {
                        ((TextBox)tb).Enabled = true;

                        if (!String.IsNullOrEmpty(((TextBox)tb).Text))  // recently added feature 10/29/2020 - Needed so Correct States are not enabled for editing during pause
                        {
                            ((TextBox)tb).Enabled = false;
                        }
                    }
                }
            }
            else
            {
                foreach (Control tb in this.Controls)
                {
                    if (tb is TextBox)
                    {
                        ((TextBox)tb).Enabled = false;
                    }
                }
            }
        }

        int i = 0;
        private void timerClockW_Tick(object sender, EventArgs e)
        {
            i++;
            if (lblClock.ForeColor == System.Drawing.Color.Red)
            {
                lblClock.ForeColor = System.Drawing.Color.Blue;
            }
            TimeSpan time = TimeSpan.FromSeconds(i);
            lblClock.Text = time.ToString(@"hh\:mm\:ss");
        }

        private void btnBegin_Click(object sender, EventArgs e)
        {
            clockIt = true;
            tbsEnableDisable();
            lblClock.ForeColor = System.Drawing.Color.Blue;
            timerClockW.Stop();
            timerClockW.Start();
            btnBegin.Enabled = false;

            if (btnPause.Enabled == false || btnQuit.Enabled == false)
            {
                btnPause.Enabled = true;
                btnQuit.Enabled = true;
            }
        }

        private void btnPause_Click(object sender, EventArgs e)
        {
            clockIt = false;
            timerClockW.Stop();
            tbsClearIncorrectText(); // recently added feature 10/29/2020 - Removes incorrect text from enabled textboxes
            tbsEnableDisable();
            lblClock.ForeColor = System.Drawing.Color.Red;

            if (btnBegin.Enabled == false)
            {
                btnBegin.Text = "Resume";
                btnBegin.Enabled = true;
            }

            btnPause.Enabled = false;
        }

        private void btnQuit_Click(object sender, EventArgs e)
        {
            timerClockW.Stop();
            string xTract = lblPercentage.Text.Trim(new Char[] { '%', '*', '.' });
            int xConversion;
            Int32.TryParse(xTract, out xConversion);
            double scoreID = xConversion;
            DateTime myDateTime = DateTime.Now;
            string sqlFormattedDate = myDateTime.ToString("MM-dd-yyyy HH:mm:ss.fff");

            vbScoreInputDialog(scoreID, sqlFormattedDate);

            i = 0;
            clockIt = false;
            //clearTextBoxes();
            lblClock.ForeColor = System.Drawing.Color.Black;
            lblClock.Text = "00:00:00";
            //tbsEnableDisable();
            lblCorrect.Text = 0.ToString();
            lblPercentage.Text = "%";
            pbStatusW.Value = 0;

            tbsFillCorrectAnswers();
            tbsEnableDisable();

            MessageBox.Show("Quitting is never an option. However, the map and timer shall reset. Give it another go.", "Never Quit!");

            if (btnBegin.Enabled == false || btnPause.Enabled == false)
            {
                btnBegin.Text = "Begin";
                btnBegin.Enabled = true;
                btnPause.Enabled = true;
            }

            btnPause.Enabled = false;
            btnQuit.Enabled = false;
            clearTextBoxes();
        }

        void tbsFillCorrectAnswers()
        {
            int size = totEntries;
            string[] correctAnswers = new string[]
            {
                "*North America", "*Europe", "*Asia", "*Africa", "*South America", "*Australia", "*Antarctica", "*Artic Ocean", "*Artic Ocean", "*North Pacific Ocean",
                "*North Atlantic Ocean", "*North Pacific Ocean", "*South Pacific Ocean", "*South Atlantic Ocean", "*Indian Ocean", "*South Pacific Ocean", "*Southern Ocean", "*Greenland", "*Russia", "*Canada",
                "*United States", "*China", "*India", "*Brasil", "*Australia", "*Algeria"
            };

            var textboxArray = new[]
            {
                tbNA, tbEurope, tbAsia, tbAfrica, tbSA, tbAustralia, tbAntart, tbArtoceantwo, tbArtocean, tbNPocean,
                tbNAocean, tbNPoceantwo, tbSPocean, tbSAocean, tbIndocean, tbSPoceantwo, tbSthocean, tbGreen, tbRussia, tbCan,
                tbUsa, tbChina, tbInd, tbBrasil, tbAustcntry, tbAlg
            };

            for (int i = 0; i < size; i++)
            {
                if (textboxArray[i].Enabled == false && !String.IsNullOrEmpty((textboxArray[i]).Text))
                {
                    // Do nothing, keep correct answers written by user
                }
                else
                {
                    textboxArray[i].Text = correctAnswers[i];
                    textboxArray[i].Font = new Font(textboxArray[i].Font, FontStyle.Bold);
                }
            }
        }

        private void tbNA_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbNA.Text, "north america", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbNA.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbEurope_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbEurope.Text, "europe", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbEurope.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbAsia_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbAsia.Text, "asia", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbAsia.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbAfrica_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbAfrica.Text, "africa", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbAfrica.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbSA_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbSA.Text, "south america", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbSA.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbAustralia_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbAustralia.Text, "australia", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbAustralia.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbAntart_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbAntart.Text, "antarctica", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbAntart.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbArtoceantwo_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbArtoceantwo.Text, "artic ocean", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbArtoceantwo.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbArtocean_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbArtocean.Text, "artic ocean", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbArtocean.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbNPocean_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbNPocean.Text, "north pacific ocean", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbNPocean.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbNAocean_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbNAocean.Text, "north atlantic ocean", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbNAocean.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbNPoceantwo_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbNPoceantwo.Text, "north pacific ocean", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbNPoceantwo.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbSPocean_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbSPocean.Text, "south pacific ocean", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbSPocean.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbSAocean_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbSAocean.Text, "south atlantic ocean", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbSAocean.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbIndocean_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbIndocean.Text, "indian ocean", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbIndocean.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbSPoceantwo_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbSPoceantwo.Text, "south pacific ocean", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbSPoceantwo.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbSthocean_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbSthocean.Text, "southern ocean", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbSthocean.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbGreen_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbGreen.Text, "greenland", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbGreen.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbRussia_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbRussia.Text, "russia", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbRussia.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbCan_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbCan.Text, "canada", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbCan.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbUsa_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbUsa.Text, "united states", true) == 0 || string.Compare(tbUsa.Text, "america", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbUsa.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbChina_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbChina.Text, "china", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbChina.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbInd_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbInd.Text, "india", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbInd.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbBrasil_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbBrasil.Text, "brasil", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbBrasil.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbAustcntry_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbAustcntry.Text, "australia", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbAustcntry.Enabled = false;
                PercentageFormula();
            }
        }

        private void tbAlg_TextChanged(object sender, EventArgs e)
        {
            if (string.Compare(tbAlg.Text, "algeria", true) == 0)
            {
                corCount++;
                lblCorrect.Text = corCount.ToString();
                tbAlg.Enabled = false;
                PercentageFormula();
            }
        }

        private void worldmapForm_Load(object sender, EventArgs e)
        {
            tbsEnableDisable();
            btnPause.Enabled = false;
            btnQuit.Enabled = false;
        }

        private void tbConts_Entered(object sender, EventArgs e)
        {
            ((TextBox)sender).BackColor = System.Drawing.Color.SpringGreen;
        }

        private void tbConts_Left(object sender, EventArgs e)
        {
            ((TextBox)sender).BackColor = System.Drawing.Color.Honeydew;
        }

        private void tbCntrys_Entered(object sender, EventArgs e)
        {
            ((TextBox)sender).BackColor = System.Drawing.Color.SandyBrown;
        }

        private void tbCntrys_Left(object sender, EventArgs e)
        {
            ((TextBox)sender).BackColor = System.Drawing.Color.Linen;
        }

        private void tbOceans_Entered(object sender, EventArgs e)
        {
            ((TextBox)sender).BackColor = System.Drawing.Color.LightSkyBlue;
        }

        private void tbOceans_Left(object sender, EventArgs e)
        {
            ((TextBox)sender).BackColor = System.Drawing.Color.AliceBlue;
        }

        private void worldmapForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            FormProvider.gForm.Show();
        }

        private void mapofCont_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("https://www.mapsofworld.com/maps/world-map-with-continents.jpg");
        }

        private void mapofContOcean_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("https://www.nationsonline.org/maps/World-Continents-Topographic-map.jpg");
        }

        private void backtoMain_Click(object sender, EventArgs e)
        {
            FormProvider.gForm.Show();

            //** Important addition **//
            if (bgWorkerBrowsers.IsBusy)
            {
                bgWorkerBrowsers.CancelAsync();
            }
            //this.Hide();
            this.Close();
        }

        private void viewScoresToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool isOpen = false;

            foreach (Form F in Application.OpenForms)
            {
                if (F.Name == "dbscoresForm")
                {
                    isOpen = true;
                    F.BringToFront();
                }
            }
            if (isOpen == false)
            {
                dbscoresForm dbF = new dbscoresForm();
                dbF.Show();
            }
        }

        private void trainerInformationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool isOpen = false;

            foreach (Form F in Application.OpenForms)
            {
                if (F.Name == "infoForm")
                {
                    isOpen = true;
                    F.BringToFront();
                }
            }
            if (isOpen == false)
            {
                infoForm inf = new infoForm();
                inf.Show();
            }
        }

        private void exitProgramToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (var process in Process.GetProcessesByName("Trainer"))
            {
                process.Kill();
            }
            Application.ExitThread();
            Application.Exit();
        }

        private void restartComputerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult diaBox;
            diaBox = MessageBox.Show(new Form { TopMost = true }, "Are you sure you would like to restart your computer?", "Restart Computer", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            if (diaBox == DialogResult.Yes)
            {
                //Code referenced: https://stackoverflow.com/questions/1215139/reboot-machine-from-a-c-wpf-app
                System.Diagnostics.Process.Start("shutdown.exe", "-r -t 0");
            }
            if (diaBox == DialogResult.No)
            {
                return;
            }
        }

        private void disableWebBrowsersToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (disableWebBrowsersToolStripMenuItem.Checked == true)
            {
                disableWebBrowsersToolStripMenuItem.BackColor = System.Drawing.Color.LightYellow;
                bgWorkerBrowsers.RunWorkerAsync();
            }
            else
            {
                disableWebBrowsersToolStripMenuItem.BackColor = System.Drawing.Color.WhiteSmoke;
                bgWorkerBrowsers.CancelAsync();
            }
        }

        private void bgWorkerBrowsers_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                if (bgWorkerBrowsers.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
                BrowserCheck();
                Thread.Sleep(3000);
            }
        }

        private void bgWorkerBrowsers_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                MessageBox.Show(new Form { TopMost = true }, "You may use your browsers again.", "Browsers Re-enabled");
            }
            else if (e.Error != null)
            {
                MessageBox.Show("It's impossible to get here, or is it? :D");
            }
            else
            {
                MessageBox.Show("Should NEVER get here :)");
            }
        }

        private void btnLegend_Click(object sender, EventArgs e)
        {
            bool isOpen = false;

            foreach (Form F in Application.OpenForms)
            {
                if (F.Name == "worldmaplegendForm")
                {
                    isOpen = true;
                    F.BringToFront();
                }
            }
            if (isOpen == false)
            {
                worldmaplegendForm legend = new worldmaplegendForm();
                legend.Show();
            }
        }
    }
}