Esempio n. 1
0
        public void Results(int xp)
        {
            //not focused on screen
            focus = false;

            //update high scores
            hs = new HighScore("YOU", xp);
            scores.Add(hs);
            scores = scores.OrderByDescending(x => x.score).ToList();

            //if a highscore
            if (scores.IndexOf(hs) < 3)
            {
                //play sound
                highScore.Play();
                //4s pause
                this.Refresh();
                Thread.Sleep(4000);
            }

            //make labels visible
            yourName1.Visible = true;
            yourName2.Visible = true;
            yourName3.Visible = true;
            yourScore.Visible = true;
            yourPlace.Visible = true;

            //display your score
            yourScore.Text       = Convert.ToString(xp);
            mainScreenLabel.Text = "save score";

            firstName.Text  = scores[0].name;
            secondName.Text = scores[1].name;
            thirdName.Text  = scores[2].name;

            firstScore.Text  = Convert.ToString(scores[0].score);
            secondScore.Text = Convert.ToString(scores[1].score);
            thirdScore.Text  = Convert.ToString(scores[2].score);

            yourPlace.Text = Convert.ToString(scores.IndexOf(hs) + 1);
        }
Esempio n. 2
0
        private void HighScoreScreen_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            //when key is pressed
            switch (e.KeyCode)
            {
            case Keys.W:
                //so that at Z returns to A
                if (upDown == 26)
                {
                    upDown = 1;
                }
                else
                {
                    upDown++;
                }
                Initials();
                break;

            case Keys.D:
                if (leftRight == 3)
                {
                    leftRight = 1;
                }
                else
                {
                    leftRight++;
                }
                Initials();
                break;

            case Keys.A:
                if (leftRight == 1)
                {
                    leftRight = 3;
                }
                else
                {
                    leftRight--;
                }
                Initials();
                break;

            case Keys.S:
                if (upDown == 1)
                {
                    upDown = 26;
                }
                else
                {
                    upDown--;
                }
                Initials();
                break;

            case Keys.Escape:
                //close program
                Application.Exit();
                break;

            case Keys.Space:
                //if focused on screen or enough time has passed
                if (myWatch.ElapsedMilliseconds > 2000 || focus == true)
                {
                    //stop watch
                    myWatch.Stop();

                    try
                    {
                        //if saving high score
                        //add new high score object (your initials, your score)
                        scores.Remove(hs);
                        hs = new HighScore(yourName1.Text + yourName2.Text + yourName3.Text, Convert.ToInt16(yourScore.Text));
                        scores.Add(hs);
                        scores = scores.OrderByDescending(x => x.score).ToList();

                        List <string> tempList = new List <string>();

                        // Add all info from each HighScore object to temp list
                        foreach (HighScore hs in scores)
                        {
                            tempList.Add(hs.name);
                            tempList.Add(Convert.ToString(hs.score));
                        }

                        //upload updated scores to text file
                        File.WriteAllLines("Score.txt", tempList);
                    }
                    catch
                    {
                        //if viewing high scores
                    }

                    //return to main screen
                    MainScreen ms = new MainScreen();
                    Form       f  = this.FindForm();
                    ms.Location = new Point((f.Width - ms.Width) / 2, (f.Height - ms.Height) / 2);
                    f.Controls.Remove(this);
                    ms.Size = f.Size;
                    f.Controls.Add(ms);
                    ms.Focus();
                }
                break;
            }
        }