private Tytanic crearTitanic(int dueño)
        {
            CeldasBarcoBackend[] misCeldas = new CeldasBarcoBackend[5];
            while (true)
            {
                int posInicialX         = r.Next(40);
                int posInicialY         = r.Next(40);
                int horizontalOvertical = r.Next(2);

                if (puedePonerse(posInicialX, posInicialY, 5, horizontalOvertical))
                {
                    if (horizontalOvertical == 0) //horizontal
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            misCeldas[i] = new CeldasBarcoBackend(posInicialX + i, posInicialY, Tytanic.nombreBarco, dueño, -2);
                            matrizJuego[posInicialX + i, posInicialY] = misCeldas[i];
                        }
                        Tytanic aux = new Tytanic(misCeldas);

                        return(aux);
                    }
                    else if (horizontalOvertical == 1)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            misCeldas[i] = new CeldasBarcoBackend(posInicialX, posInicialY + i, Tytanic.nombreBarco, dueño, -2);
                            matrizJuego[posInicialX, posInicialY + i] = misCeldas[i];
                        }
                        Tytanic aux = new Tytanic(misCeldas);

                        return(aux);
                    }
                }
            }
            //return null;
        }
        public Tablero(Server servidor, Jugador jugador)
        {
            Backend__Cell = new Dictionary <CeldasBarcoBackend, Cell>();
            Cell__Backend = new Dictionary <Cell, CeldasBarcoBackend>();

            intCell = new Dictionary <int[], Cell>();

            celdasTotales = new Cell[40, 40];

            this.servidor = servidor;
            this.jugador  = jugador;
            if (servidor != null)
            {
                programa = servidor.p;
            }
            InitializeComponent();

            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 40; j++)
                {
                    Cell a = new Cell(i, j, null, null, jugador, servidor);
                    celdasTotales[i, j] = a;
                    int[] enter = { 1000 * i, 1000 * j };
                    intCell.Add(enter, a);
                    Grid.SetColumn(a, i);
                    Grid.SetRow(a, j);
                    grid.Children.Add(a);
                }
            }

            #region
            for (int i = 0; i < 40; i++)
            {
                grid.ColumnDefinitions.Add(new ColumnDefinition());
            }
            for (int j = 0; j < 40; j++)
            {
                grid.RowDefinitions.Add(new RowDefinition());
            }
            #endregion

            if (servidor != null)
            {
                servidor.p.hayGanador += ganador;

                Tytanic           t   = (Tytanic)programa.una[0];
                MerrilMarineForce m   = (MerrilMarineForce)programa.una[1];
                Trololo           tro = (Trololo)programa.una[2];
                PernaNegra        per = (PernaNegra)programa.una[3];
                HolandesVolador   h   = (HolandesVolador)programa.una[4];

                Barco[] arrB = { t, m, tro, per, h };

                for (int j = 0; j < 5; j++)
                {
                    for (int i = 0; i < arrB[j].celdasDelBarco.Length; i++)
                    {
                        CeldasBarcoBackend logica = arrB[j].celdasDelBarco[i];
                        Cell a = new Cell(arrB[j].celdasDelBarco[i].posX, arrB[j].celdasDelBarco[i].posY, arrB[j], logica, null, servidor);
                        Grid.SetColumn(a, arrB[j].celdasDelBarco[i].posX);
                        Grid.SetRow(a, arrB[j].celdasDelBarco[i].posY);
                        Backend__Cell.Add(arrB[j].celdasDelBarco[i], a);
                        Cell__Backend.Add(a, arrB[j].celdasDelBarco[i]);
                        int[] o = { arrB[j].celdasDelBarco[i].posX, arrB[j].celdasDelBarco[i].posY };
                        intCell.Add(o, a);
                        grid.Children.Add(a);
                    }
                }
                #region
                for (int r = 1; r < servidor.p.todosBarcos.Length; r++)
                {
                    Barco[] arr = servidor.p.todosBarcos[r];
                    for (int j = 0; j < 5; j++)
                    {
                        for (int i = 0; i < arr[j].celdasDelBarco.Length; i++)
                        {
                            Cell a = new Cell(arr[j].celdasDelBarco[i].posX, arr[j].celdasDelBarco[i].posY, arr[j], arr[j].celdasDelBarco[i], null, null);
                            Backend__Cell.Add(arr[j].celdasDelBarco[i], a);
                            Cell__Backend.Add(a, arr[j].celdasDelBarco[i]);
                            int[] o = { arrB[j].celdasDelBarco[i].posX, arrB[j].celdasDelBarco[i].posY };
                            intCell.Add(o, a);
                        }
                    }
                }

                #endregion
            }

            if (jugador != null)
            {
                jugador.hayGanador += ganador;
                Barco[] arrB = jugador.misBarcos;
                for (int j = 0; j < 5; j++)
                {
                    for (int i = 0; i < arrB[j].celdasDelBarco.Length; i++)
                    {
                        Cell a = new Cell(arrB[j].celdasDelBarco[i].posX, arrB[j].celdasDelBarco[i].posY, arrB[j], arrB[j].celdasDelBarco[i], jugador, null);
                        Grid.SetColumn(a, arrB[j].celdasDelBarco[i].posX);
                        Grid.SetRow(a, arrB[j].celdasDelBarco[i].posY);
                        Backend__Cell.Add(arrB[j].celdasDelBarco[i], a);
                        celdasTotales[arrB[j].celdasDelBarco[i].posX, arrB[j].celdasDelBarco[i].posY] = a;
                        int[] ar = { arrB[j].celdasDelBarco[i].posX, arrB[j].celdasDelBarco[i].posY };
                        intCell.Add(ar, a);
                        grid.Children.Add(a);
                    }
                }


                Thread esperarJugada = new Thread(new ParameterizedThreadStart(revisarCambio));
                esperarJugada.Start(this);
            }
        }