Пример #1
0
        private void loadGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog OpenFile = new OpenFileDialog();
                OpenFile.Filter = "Score File|*.bin|All Files|*.*";
                OpenFile.Title  = "Open Scores";

                //Opens the binary file
                if (OpenFile.ShowDialog() == DialogResult.OK)
                {
                    FileStream   fs          = new FileStream(OpenFile.FileName, FileMode.Open);
                    BinaryReader ScoreReader = new BinaryReader(fs);

                    Wins1 = ScoreReader.ReadInt32();
                    Wins2 = ScoreReader.ReadInt32();

                    lblWins1.Text = "Wins: " + Wins1.ToString();
                    lblWins2.Text = "Wins: " + Wins2.ToString();

                    ScoreReader.Close();
                }
            }
            catch
            {
                MessageBox.Show("File Error");
            }
        }
Пример #2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            for (int i = 0; i < balls.Count; i++)
            {
                int  j;
                Ball b = balls[i];
                for (int k = i + 1; k < balls.Count; k++)
                {
                    Ball a = balls[k];
                    b.Collide(a);
                }
                j = b.Move(P1, P2);
                //Checks to see if any ball has collided

                if (j == 1) //Score a point for player 2
                {
                    Score2        += 1;
                    lblScore2.Text = Score2.ToString();
                    if (Score2 >= 11)
                    {
                        //player 2 wins game
                        Timer.Stop();
                        MessageBox.Show("Player 2 Wins!");
                        Wins2           += 1;
                        lblWins2.Text    = "Wins:" + Wins2.ToString();
                        Score1           = 0;
                        lblScore1.Text   = Score1.ToString();
                        Score2           = 0;
                        lblScore2.Text   = Score2.ToString();
                        btnStart.Enabled = true;
                    }
                    ResetAll();
                }
                else if (j == 2) //Score a point for player 1
                {
                    Score1        += 1;
                    lblScore1.Text = Score1.ToString();
                    if (Score1 >= 11)
                    {
                        //player 1 wins game
                        Timer.Stop();
                        MessageBox.Show("Player 1 Wins!");
                        Wins1           += 1;
                        lblWins1.Text    = "Wins:" + Wins1.ToString();
                        Score1           = 0;
                        lblScore1.Text   = Score1.ToString();
                        Score2           = 0;
                        lblScore2.Text   = Score2.ToString();
                        btnStart.Enabled = true;
                    }
                    ResetAll();
                }
            }
            //moving on keydown, stopping on key up
            if (W == true)
            {
                P1.Move(1);
            }

            if (S == true)
            {
                P1.Move(-1);
            }

            if (I == true)
            {
                P2.Move(1);
            }

            if (K == true)
            {
                P2.Move(-1);
            }

            pbGame.Invalidate();
        }