コード例 #1
0
        private void frmScores_Load(object sender, EventArgs e)
        {
            // Clear score list
            rtbScores.Clear();

            // Load score objects from CSV
            List <Score> scoreList = ScoreCSV.LoadFile();

            // If the CSV wasn't empty, then
            if (scoreList != null)
            {
                // initialize an instance of StringBuilder
                StringBuilder StrBld = new StringBuilder();

                rtbScores.AppendText("Initials            Score\n");

                // Iterate the scoreList
                for (int i = 0; i < scoreList.Count; i++)
                {
                    // For each property in an object in the list, print them out in a formatted,
                    // human readable form.
                    StrBld.AppendFormat("{0, -20}{1, -20}",
                                        scoreList.ElementAt(i).UserInitial,
                                        scoreList.ElementAt(i).UserScore.ToString());

                    // Append the contents of the StringBuilder object to the rich text box
                    rtbScores.AppendText(StrBld.ToString() + "\n");

                    // Clear the contents of the string builder object
                    StrBld.Clear();
                }
            }
        }
コード例 #2
0
ファイル: frmOutOfTime.cs プロジェクト: MadManGaz/homewrk
        // Clicking no will save the user score to a CSV, and then return to the main menu.
        private void btnNo_Click(object sender, EventArgs e)
        {
            if (txtInitials.Text != "")
            {
                List <Score> scoreList = ScoreCSV.LoadFile();
                scoreList.Add(new Score(txtInitials.Text.ToUpper(), game.Score));
                ScoreCSV.SaveFile(scoreList);

                frmMainMenu MainMenu = new frmMainMenu();
                MainMenu.Show();
                Hide();
            }

            else
            {
                MessageBox.Show("Please enter your initials");
                txtInitials.Clear();
            }
        }
コード例 #3
0
ファイル: frmOutOfTime.cs プロジェクト: MadManGaz/homewrk
        // If yes is clicked the user score will be saved and the game will be restarted.
        private void btnYes_Click(object sender, EventArgs e)
        {
            if (txtInitials.Text != "")
            {
                List <Score> scoreList = ScoreCSV.LoadFile();
                scoreList.Add(new Score(txtInitials.Text.ToUpper(), game.Score));
                ScoreCSV.SaveFile(scoreList);

                // Resets variables in frmGame object to default and starts timer
                game.Score         = 0;
                game.lblScore.Text = "0";
                game.Counter       = 30;
                game.Show();
                game.LoadNewQuestion();
                game.tmrCountdown.Start();
                this.Hide();
            }

            else
            {
                MessageBox.Show("Please enter your initials");
                txtInitials.Clear();
            }
        }