Esempio n. 1
0
        /// <summary>
        /// Datos recibidos del jugador que juega el turno actual
        /// </summary>
        void ComandoJugadorActualRecibidos(ushort comando, string[] subCadenas, string cadena, ClienteTCP cliente)
        {
            switch (comando)
            {
            case 53:     //Inicio de ronda recibido correctamente
                if (timer != null)
                {
                    timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                }
                break;

            case 203:     //Fin de turno
                EnviarComando(1, "OK", cliente);
                EsperandoFinTurno.Set();
                break;

            case 205:     //Envio de ataque (naves,origen,destino)
                Flota flota = new Flota();
                flota.Origen            = Mapa.ObtenerPlaneta(subCadenas[1]);
                flota.Destino           = Mapa.ObtenerPlaneta(subCadenas[2]);
                flota.TecnologiaMilitar = flota.Origen.TecnologiaMilitar;
                flota.Naves             = int.Parse(subCadenas[0]);
                if (flota.Naves > flota.Origen.Naves)
                {
                    flota.Naves = flota.Origen.Naves;
                }
                flota.Origen.Naves -= flota.Naves;

                flota.Distancia    = Cliente.CalcularDistancia(flota.Origen, flota.Destino);
                flota.RondaSalida  = ronda;
                flota.RondaLlegada = (ronda + (int)Math.Round(flota.Distancia));
                Clientes[cliente].Flotas.Add(flota);

                EnviarComando(1, "OK", cliente);
                break;

            case 210:     //Cargar partida
                if (Clientes[cliente].AdministradorServidor)
                {
                    ronda = int.Parse(subCadenas[2]);
                    DifundirMensaje(comando,
                                    string.Format("Cargar mapa de semilla '{0}' y '{1}' neutrales", subCadenas[0], subCadenas[1]));
                    Mapa.Inicializar(int.Parse(subCadenas[0]), Mapa.Jugadores, int.Parse(subCadenas[1]));
                    Mapa.RondaActual = ronda;

                    System.Windows.Forms.Application.DoEvents();
                    System.Threading.Thread.Sleep(100);
                    System.Windows.Forms.Application.DoEvents();

                    string datos = subCadenas[3].Replace("&apos;", "'");
                    DifundirMensaje(206, datos);
                    Mapa.CargarDatos(ClienteTCP.ObtenerSubCadenas(datos));

                    System.Windows.Forms.Application.DoEvents();
                    System.Threading.Thread.Sleep(100);
                    System.Windows.Forms.Application.DoEvents();

                    iniciarRonda = true;
                    EsperandoFinTurno.Set();
                }
                break;
            }
        }