コード例 #1
0
        public FormTron(Client myMyClient)
        {
            this.Visible = false;

            myClient = myMyClient;
            myTron   = myClient.Init();
            InitializeComponent();

            pictureBox1.Size = new System.Drawing.Size(myTron.getTaille() * tailleJoueur, myTron.getTaille() * tailleJoueur);
            this.ClientSize  = new System.Drawing.Size(myTron.getTaille() * tailleJoueur, myTron.getTaille() * tailleJoueur);

            // Creation bitmap de dessin
            bmp = new System.Drawing.Bitmap(myTron.getTaille() * tailleJoueur, myTron.getTaille() * tailleJoueur);
            e   = System.Drawing.Graphics.FromImage(bmp);
            this.ResumeLayout(false);

            keh = new KeyEventHandler(OnKeyPress);

            this.KeyDown += keh;

            aTimer          = new System.Timers.Timer();
            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            aTimer.Interval = myClient.freq;
            aTimer.Enabled  = true;

            stillAlive = true;
        }
コード例 #2
0
        // Specify what you want to happen when the Elapsed event is raised.
        private void OnTimedEvent(object source, ElapsedEventArgs eventArgs)
        {
            aTimer.Enabled = false;

            myClient.Routine();
            myTron.Deplacement();


            if (myTron.IsDead() && stillAlive)
            {
                stillAlive = false;

                // Désactivation clavier
                this.KeyDown -= keh;
                //MessageBox.Show(null, "You LOSE!!!", "Conclusion",
                //     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                e.DrawString("You LOSE!!!", new Font(FontFamily.GenericSansSerif, 20.00f),
                             new SolidBrush(Color.Red), new PointF(myTron.getTaille() * tailleJoueur / 2 - 80, myTron.getTaille() * tailleJoueur / 2 - 10));
            }
            if (myTron.IsFinished())
            {
                myClient.Conclusion();

                if (myTron.IsWinner())
                {
                    //MessageBox.Show(null, "You WIN!!!", "Conclusion",
                    //     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    e.DrawString("You WIN!!!", new Font(FontFamily.GenericSansSerif, 20.00f),
                                 new SolidBrush(Color.Blue), new PointF(myTron.getTaille() * tailleJoueur / 2 - 80, myTron.getTaille() * tailleJoueur / 2 - 10));
                }
            }
            else
            {
                aTimer.Enabled = true;
            }

            Rendu();
        }