Example #1
0
 public void Life(ClientProcessor[] players)
 {
     foreach (ClientProcessor processor in players)
     {
         processor.SendLife();
     }
 }
        public void AddPlayer(TcpClient client)
        {
            //Caso já se tenha 02 jogadores, não pode mais entrar no servidor.
            if (ready)
                DisconnectPlayer(client);

            //Identificador do cliente
            int id = NextID();
            Console.WriteLine("Novo cliente entrou: " + id);

            //Cria Thread para cuidar do cliente.
            players[id] = new ClientProcessor(this, id, client);
            Thread thread = new Thread(players[id].Run);
            thread.Start();

            if (id + 1 >= MAX_PLAYERS)
            {
                ready = true;
                //Cria o contorno da parede e envia aos clientes.
                matrizJogo =  wall.CreateWallPhase01(matrizJogo);
                wall.SendToCLient(players, matrizJogo);

                // Cria a 1ª posicao da comida e envia ao cliente.
                matrizJogo = food.NewPosition(matrizJogo);
                food.SendToClient(matrizJogo, players);
            }
        }
Example #3
0
 public static ClientProcessor GetInstance(IPAddress ip, int port, ScreenProcessor sProcessor)
 {
     if (_instance == null)
     {
         _instance = new ClientProcessor(ip, port, sProcessor);
     }
     return _instance;
 }
        public void SendToClient(int id, ClientProcessor[] players)
        {
            placares[id] += valorComida;

            foreach (ClientProcessor processor in players)
            {
                processor.SendScore(id.ToString() + "," + placares[id]);
            }
        }
Example #5
0
 public frmServer()
 {
     InitializeComponent();
     this._screenProcessor = ScreenProcessor.Instance;
     IPAddress ip = IPAddress.Parse("192.168.1.100");
     this._clientProcessor = ClientProcessor.GetInstance(ip, 21999, this._screenProcessor);
     using (Graphics g = this.pnScreen.CreateGraphics())
     {
         this._bg = BufferedGraphicsManager.Current.Allocate(g, new Rectangle(0, 0, this.pnScreen.Width, this.pnScreen.Height));
     }
     
 }
Example #6
0
        public void SendToCLient(ClientProcessor[] players, int[,] matrizJogo)
        {
            StringBuilder builder = new StringBuilder("");

            for (int x = 0; x < 50; x++)
            {
                for (int y = 0; y < 50; y++)
                {
                    //Coletar todas a posicao de cada parede.
                    if (matrizJogo[x, y] == 4)
                    {
                        builder.Append(x.ToString() + "," + y.ToString() + ";");
                    }
                }
            }

            foreach (ClientProcessor processor in players)
            {
                processor.SendWall(builder);
            }
        }
Example #7
0
        public void SendToClient(int[,] matrizJogo, ClientProcessor[] players)
        {
            StringBuilder builder = new StringBuilder("");

            for (int x = 0; x < 50; x++)
            {
                for (int y = 0; y < 50; y++)
                {
                    //Se achar a comida: Coletar a posicao X e Y para logo após sair do for.
                    if (matrizJogo[x, y] == 3)
                    {
                        builder.Append(x.ToString() + "," + y.ToString());
                        break;
                    }
                }
            }

            foreach (ClientProcessor processor in players)
            {
                processor.SendFood(builder);
                Console.WriteLine("Food position sent: " + builder);
            }
        }
Example #8
0
        public void Death(ClientProcessor player)
        {
            ClientProcessor processor = player;

            processor.SendDeath();
        }
Example #9
0
        public void Death(ClientProcessor player)
        {
            ClientProcessor processor = player;

            processor.SendDeath();
        }