/*
         * Normal: débil frente a Lucha
         * Fuego: débil frente a Agua, Tierra, Roca
         * Agua: débil frente a Planta, Eléctrico
         * Planta: débil frente a Fuego, Hielo, Veneno, Volador, Bicho
         * Eléctrico: débil frente a Tierra
         * Hielo: débil frente a Fuego, Lucha, Roca, Acero
         * Lucha: débil frente a Volador, Psíquico, Hada
         * Veneno: débil frente a Tierra, Psíquico
         * Tierra: débil frente a Agua, Planta, Hielo
         * Volador: débil frente a Eléctrico, Hielo, Roca
         * Psíquico: débil frente a Bicho, Fantasma, Siniestro
         * Bicho: débil frente a Volador, Roca, Fuego
         * Roca: débil frente a Agua, Planta, Lucha, Tierra, Acero
         * Fantasma: débil frente a Fantasma, Siniestro
         * Dragón: débil frente a Hielo, Dragón, Hada
         * Siniestro: débil frente a Lucha, Bicho, Hada
         * Acero: débil frente a Fuego, Lucha, Tierra
         * Hada: débil frente a Veneno, Acero
         *
         */
        public String SendAllTypes()
        {
            List <String> ListTypes = new List <String>();

            ListTypes.Add("Normal");
            ListTypes.Add("Fuego");
            ListTypes.Add("Agua");
            XmlWorker.XmlConverter converter = new XmlWorker.XmlConverter();
            return(converter.ProcessXmlResponse(ListTypes.ToArray(), true));
        }
Beispiel #2
0
 static void Connect(String server, String message)
 {
     //Reference to library class
     XmlWorker.XmlConverter converter = new XmlWorker.XmlConverter();
     String[] example = new String[1];
     example[0] = "fuego";
     try
     {
         // Create a TcpClient.
         // Note, for this client to work you need to have a TcpServer
         // connected to the same address as specified by the server, port
         // combination.
         Int32     port   = 13000;
         TcpClient client = new TcpClient(server, port);
         // Translate the passed message into ASCII and store it as a Byte array.
         Byte[] data = System.Text.Encoding.ASCII.GetBytes(converter.ProcessXmlResponse(example, false));
         // Get a client stream for reading and writing
         NetworkStream stream = client.GetStream();
         // Send the message to the connected TcpServer.
         stream.Write(data, 0, data.Length);
         Console.WriteLine("Sent: {0}", converter.ProcessXmlResponse(example, false));
         // Receive the TcpServer.response.
         // Buffer to store the response bytes.
         data = new Byte[256];
         // String to store the response ASCII representation.
         String responseData = String.Empty;
         // Read the first batch of the TcpServer response bytes.
         Int32 bytes = stream.Read(data, 0, data.Length);
         responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
         Console.WriteLine("Received: {0}", responseData);
         // Close everything.
         stream.Close();
         client.Close();
     }
     catch (ArgumentNullException e)
     {
         Console.WriteLine("ArgumentNullException: {0}", e);
     }
     catch (SocketException e)
     {
         Console.WriteLine("SocketException: {0}", e);
     }
     Console.WriteLine("\n Press Enter to continue...");
     Console.Read();
 }
        public void ProcessRequest()
        {
            XmlWorker.XmlConverter converter = new XmlWorker.XmlConverter();
            Byte[]        bytes  = new Byte[256];
            String        data   = null;
            NetworkStream stream = client.GetStream();
            Int32         i      = stream.Read(bytes, 0, bytes.Length);

            // Traducimos los datos enviados a un string ASCII
            data = System.Text.Encoding.ASCII.GetString(bytes, 0, i).Trim();
            // Determinamos el tipo de conversión y la efectuamos
            if (data == "tipos")
            {
                data = SendAllTypes();
            }
            else
            {
                data = converter.ProcessXmlResponse(GetWeaknessTypes(converter.GetXmlData(data)), true);
            }
            Byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
            stream.Write(msg, 0, msg.Length);
            // Cerramos el cliente y la conexión con él
            client.Close();
        }