Ejemplo n.º 1
0
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            dispatcherTimer.Stop();

            JugadorCliente jugadorActual = null;

            // Verificamos si algún jugador puede jugar
            // Si ninguno puede jugar "jugadorActual" seguirá siendo null
            if (Juego.Jugadores[0].CanPlay)
            {
                jugadorActual = Juego.Jugadores[0];
            }
            else if (Juego.Jugadores[1].CanPlay)
            {
                jugadorActual = Juego.Jugadores[1];
            }

            if (jugadorActual != null && jugadorActual.Id == 2)
            {
                int col = new Random().Next(7);


                if (Juego.Contador[col] >= 0)
                {
                    Juego.Anotacion(jugadorActual, col);

                    // Cambiamos de turno
                    Juego.Jugadores[0].CanPlay = !Juego.Jugadores[0].CanPlay;
                    Juego.Jugadores[1].CanPlay = !Juego.Jugadores[1].CanPlay;

                    BuildPlayGrid();
                }
            }
        }
Ejemplo n.º 2
0
        public void MarkCell(object sender, MouseButtonEventArgs e)
        {
            dispatcherTimer = new DispatcherTimer();

            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);

            dispatcherTimer.Interval = new TimeSpan(0, 0, 1);



            JugadorCliente jugadorActual = null;

            // Verificamos si algún jugador puede jugar
            // Si ninguno puede jugar "jugadorActual" seguirá siendo null
            if (Juego.Jugadores[0].CanPlay)
            {
                jugadorActual = Juego.Jugadores[0];
            }
            else if (Juego.Jugadores[1].CanPlay)
            {
                jugadorActual = Juego.Jugadores[1];
            }

            // Si ninguno puede jugar significa que el juego termino
            if (jugadorActual != null && jugadorActual.Id == 1)
            {
                // Determinamos la columna según la posición del mouse
                var    point            = Mouse.GetPosition(PlayGrid);
                int    col              = 0;
                double accumulatedWidth = 0.0;
                foreach (var columnDefinition in PlayGrid.ColumnDefinitions)
                {
                    accumulatedWidth += columnDefinition.ActualWidth;
                    if (accumulatedWidth >= point.X)
                    {
                        break;
                    }
                    col++;
                }

                if (Juego.Contador[col] >= 0)
                {
                    Juego.Anotacion(jugadorActual, col);

                    // Cambiamos de turno
                    Juego.Jugadores[0].CanPlay = !Juego.Jugadores[0].CanPlay;
                    Juego.Jugadores[1].CanPlay = !Juego.Jugadores[1].CanPlay;

                    BuildPlayGrid();
                }
            }


            dispatcherTimer.Start();
        }
Ejemplo n.º 3
0
        //---------Funciones----------------//

        private void EstablecerJugadorEnCliente()
        {
            if (_juegoServer.JugadorAzul == null)
            {
                _jugador = _juegoServer.JugadorRojo;
            }
            else
            {
                _jugador = _juegoServer.JugadorAzul;
            }


            JugadorCliente j1 = new JugadorCliente(1, "Jugador 1", true, Opciones.ColoresFicha.ColorJ1);

            JugadorCliente j2 = new JugadorCliente(2, "Jugador 2", false, Opciones.ColoresFicha.ColorJ2);



            juegoCliente.Jugadores = new JugadorCliente[] { j1, j2 };

            juegoCliente.Tablero = Converter.ArrayToMatrix(_juegoServer.Matriz);

            juegoCliente.Contador = _juegoServer.Contadores;
        }