예제 #1
0
        // Appelé régulièrement à chaque tour de jeu
        public void Routine()
        {
            System.Console.WriteLine("Routine");

            // TODO Envoie de sa direction : myTron.getDirection()
            byte[] directionSend = new byte[1];
            directionSend[0] = myTron.getDirection();
            try
            {
                if (clientSocket.Connected)
                {
                    clientSocket.Send(directionSend, directionSend.Length, SocketFlags.None);
                }
            } catch
            {
                byte[] directions = myTron.getDirections();
                directions[myTron.getMonNum()] = 5;
                myTron.setDirections(directions);
                clientSocket.Close();
            }
            // TOSO Reception de toutes les directions : myTron.setDirections(byte[] < toutes les directions>);

            byte[] directionsReceive = new byte[myTron.getNJoueurs()];
            try
            {
                if (clientSocket.Connected)
                {
                    clientSocket.Receive(directionsReceive, directionsReceive.Length, SocketFlags.None);
                }
            } catch
            {
                byte[] directions = myTron.getDirections();
                directions[myTron.getMonNum()] = 5;
                myTron.setDirections(directions);
                clientSocket.Close();
            }
            myTron.setDirections(directionsReceive);
        }
        public void Rendu()
        {
            for (int i = 0; i < myTron.getNJoueurs(); i++)
            {
                SolidBrush b;
                if (myTron.getMonNum() == i)
                {
                    b = new SolidBrush(Color.Blue);
                }
                else
                {
                    b = new SolidBrush(Color.Red);
                }

                e.FillRectangle(b,
                                new Rectangle(new Point(myTron.getPosX(i) * tailleJoueur, myTron.getPosY(i) * tailleJoueur),
                                              new Size(tailleJoueur, tailleJoueur)));
            }

            // On affiche notre image Bitmap dans la PictureBox
            pictureBox1.Image = bmp;
        }