Ejemplo n.º 1
0
        public Cell(int i, int j, Barco b, CeldasBarcoBackend logica, Jugador jugador, Server servidor)
        {
            if (servidor != null)
            {
                servidor.p.jugada += cambiarC;

                servidor.p.jug += cambiarCo;

                servidor.p.jiji += pintarBarco;
            }

            this.jugador  = jugador;
            this.servidor = servidor;
            barco         = b;
            dic           = new Dictionary <int, Brush>();
            ataqueAotro   = new Dictionary <int, LinearGradientBrush>();

            #region
            //rojo
            LinearGradientBrush uno = new LinearGradientBrush();
            uno.EndPoint      = new Point(1, 0.5);
            uno.StartPoint    = new Point(0, 0.5);
            uno.GradientStops = new GradientStopCollection(2);
            GradientStop aa = new GradientStop(Colors.Black, 0);
            GradientStop ab = new GradientStop(Colors.Red, 1);
            uno.GradientStops.Add(aa);
            uno.GradientStops.Add(ab);

            //violet
            LinearGradientBrush dos = new LinearGradientBrush();
            dos.EndPoint      = new Point(1, 0.5);
            dos.StartPoint    = new Point(0, 0.5);
            dos.GradientStops = new GradientStopCollection(2);
            GradientStop aaa = new GradientStop(Colors.Black, 0);
            GradientStop aab = new GradientStop(Colors.Green, 1);
            dos.GradientStops.Add(aaa);
            dos.GradientStops.Add(aab);


            //pink
            LinearGradientBrush tres = new LinearGradientBrush();
            tres.EndPoint      = new Point(1, 0.5);
            tres.StartPoint    = new Point(0, 0.5);
            tres.GradientStops = new GradientStopCollection(2);
            GradientStop aaaa = new GradientStop(Colors.Black, 0);
            GradientStop aaab = new GradientStop(Colors.Yellow, 1);
            tres.GradientStops.Add(aaaa);
            tres.GradientStops.Add(aaab);

            //coral
            LinearGradientBrush cuatro = new LinearGradientBrush();
            cuatro.EndPoint      = new Point(1, 0.5);
            cuatro.StartPoint    = new Point(0, 0.5);
            cuatro.GradientStops = new GradientStopCollection(2);
            GradientStop aaaaa = new GradientStop(Colors.Black, 0);
            GradientStop aaaab = new GradientStop(Colors.Coral, 1);
            cuatro.GradientStops.Add(aaaaa);
            cuatro.GradientStops.Add(aaaab);


            ataqueAotro.Add(1, uno);
            ataqueAotro.Add(2, dos);
            ataqueAotro.Add(3, tres);
            ataqueAotro.Add(4, cuatro);

            #endregion


            #region
            dic.Add(1, Brushes.Red);
            dic.Add(2, Brushes.Green);
            dic.Add(3, Brushes.Yellow);
            dic.Add(4, Brushes.Coral);
            dic.Add(11, Brushes.Red);
            dic.Add(12, Brushes.Green);
            dic.Add(13, Brushes.Yellow);
            dic.Add(14, Brushes.Coral);
            #endregion
            this.logica = logica;
            posX        = i;
            posY        = j;
            InitializeComponent();

            if (logica == null)
            {
                color = Brushes.Transparent;
            }
            else
            {
                color = Brushes.Gray;//Brushes.BlanchedAlmond;
                #region
                if (logica.dueño == 1)
                {
                    colorAUX = Brushes.Red;
                }
                else if (logica.dueño == 2)
                {
                    colorAUX = Brushes.Violet;
                }
                else if (logica.dueño == 3)
                {
                    colorAUX = Brushes.Pink;
                }
                else if (logica.dueño == 4)
                {
                    colorAUX = Brushes.Coral;
                }
                #endregion
            }

            cambiarColor(color);
        }
        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);
            }
        }