Exemplo n.º 1
0
        /// <summary>
        /// Dibuja el tablero del tamaño seleccionado
        /// </summary>
        private void DibujarTablero()
        {
            Graphics g = TableroPanel.CreateGraphics();

            g.Clear(COLOR_TABLERO);

            int   width  = TableroPanel.Width;
            int   height = TableroPanel.Height;
            float ancho  = width / tamano;
            float alto   = height / tamano;

            Pen pincel = new Pen(Color.Black, 2);

            tablero = new Tablero(tamano, tamano);

            for (int x = 0; x < tamano; x++)
            {
                for (int y = 0; y < tamano; y++)
                {
                    tablero.SetEstado(x, y, Estado.libre);
                    g.DrawRectangle(pincel, x * ancho, y * alto, ancho, alto);
                }
            }

            this.Invalidate();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Redibuja el tablero, manteniendo el estado en el que se encuentra.
        /// </summary>
        private void RepaintTablero()
        {
            Graphics g = TableroPanel.CreateGraphics();

            g.Clear(COLOR_TABLERO);

            int   width  = TableroPanel.Width;
            int   height = TableroPanel.Height;
            float ancho  = width / tamano;
            float alto   = height / tamano;

            for (int x = 0; x < tamano; x++)
            {
                for (int y = 0; y < tamano; y++)
                {
                    Estado estado = tablero.GetEstado(x, y);

                    int xInicio     = (int)(x * ancho + OFFSET_PINCEL);
                    int yInicio     = (int)(y * alto + OFFSET_PINCEL);
                    int anchoOffset = (int)(ancho - OFFSET_PINCEL);
                    int altoOffset  = (int)(alto - OFFSET_PINCEL);

                    switch (estado)
                    {
                    case Estado.libre:
                        g.DrawRectangle(pincel, x * ancho, y * alto, ancho, alto);
                        break;

                    case Estado.ocupado:
                        g.FillRectangle(brochaNegra, xInicio, yInicio, anchoOffset, altoOffset);
                        break;

                    case Estado.origen:
                        g.FillRectangle(brochaVerde, xInicio, yInicio, anchoOffset, altoOffset);
                        break;

                    case Estado.destino:
                        g.FillRectangle(brochaRoja, xInicio, yInicio, anchoOffset, altoOffset);
                        break;

                    case Estado.visitado:
                        g.FillRectangle(brochaAzul, xInicio, yInicio, anchoOffset, altoOffset);
                        break;

                    case Estado.evaluado:
                        g.FillRectangle(brochaCeleste, xInicio, yInicio, anchoOffset, altoOffset);
                        break;
                    }
                }
            }

            this.Invalidate();
        }
Exemplo n.º 3
0
        private void TableroPanel_Click(object sender, EventArgs e)
        {
            MouseEventArgs ev = (MouseEventArgs)e;

            Graphics g = TableroPanel.CreateGraphics();

            float xOffset = TableroPanel.Width / tamano;
            float yOffset = TableroPanel.Height / tamano;

            int x = (int)Math.Ceiling(ev.X / xOffset) - 1;
            int y = (int)Math.Ceiling(ev.Y / yOffset) - 1;

            Console.WriteLine("Click en " + x + " " + y);

            tablero.QuitarRecorrido();

            String tipoNodo = getTextGroupBox(TipoNodo);

            int[] nodo = new int[2];
            nodo[0] = x;
            nodo[1] = y;

            switch (tipoNodo)
            {
            case ORIGEN:
                // Resetea el origen anterior
                if (tablero.Origen >= 0)
                {
                    int origen = tablero.Origen;
                    tablero.SetEstado(tablero.GetX(origen), tablero.GetY(origen), Estado.libre);
                }

                tablero.Origen = tablero.GetId(x, y);
                tablero.SetEstado(x, y, Estado.origen);

                break;

            case DESTINO:
                if (tablero.Destino >= 0)
                {
                    int destino = tablero.Destino;
                    tablero.SetEstado(tablero.GetX(destino), tablero.GetY(destino), Estado.libre);
                }

                tablero.Destino = tablero.GetId(x, y);
                tablero.SetEstado(x, y, Estado.destino);
                break;

            case OBSTACULO:
                if (tablero.GetEstado(x, y) == Estado.ocupado)
                {
                    tablero.SetEstado(x, y, Estado.libre);
                }
                else
                {
                    tablero.SetEstado(x, y, Estado.ocupado);
                }
                break;

            default:
                tablero.SetEstado(x, y, Estado.libre);
                break;
            }


            RepaintTablero();
        }