• Viernes 29 de Marzo de 2024, 15:58

Autor Tema:  Dibujar tablero ajedrez  (Leído 9062 veces)

maduelo

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
Dibujar tablero ajedrez
« en: Miércoles 15 de Julio de 2009, 20:21 »
0
Alguien me podria decir como dibujar un tablero de ajedrez en c#, en el cual en un textbox o algo le diera una posicion del alfil i me marxara con una x hacia donde me puedo mover?
Yo ya lo tengo hecho pero solo para aplicacion consola y lo queria pasar a un formulario en que me aparecieran las 64 celdas del tablero que serian botones de colores blanco o negro segun corresponda y despues aplicar el desplazamiento del alfil.
El codigo lo tengo xo no c como dibujar el tablero.

Legend

  • Nuevo Miembro
  • *
  • Mensajes: 7
  • Nacionalidad: pe
    • Ver Perfil
Re: Dibujar tablero ajedrez
« Respuesta #1 en: Domingo 26 de Julio de 2009, 19:45 »
0
ummm creo q te puedo dar una mano con loq  me pides mira yo hice un codigo para resolver ecuaciones lineales en las cuales creo las graficas de esas ecuaciones (Ecuaciones lineales) y  ademas hice un tablaro tipo "Tablero de ajedrez" para mis coordenadas aki te paso el codigo  :P
ahhh verdad crea 6 text box y rellenalos con numeros para q veas como funciona

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace aplicacion_de_prueba_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Graficar_Click(object sender, EventArgs e)
        {
            /*******************************************
             * Desarrollado por: Elias Nicolas Ocon Osorio
             * UAC
             * ****************************************/
            try
            {
                int ys = 16, x1 = 1, xs = 330;
                Graphics grafica = CreateGraphics();
                Pen ejes = new Pen(Color.Blue, 1),ejes2=new Pen(Color.Red,1),cuadric=new Pen(Color.Black,1);
                grafica.DrawRectangle(ejes, 300, 20, 330, 300);
                Font text = new Font("Arial", 8, FontStyle.Italic);
                for (int i = 10; i >= 0; i--)
                {
                    // eje de las Ys
                    grafica.DrawString(Convert.ToString(i), text, new SolidBrush(Color.Black), 280, ys);
                    ys = ys + 30;
                    //Eje de las Xs
                    grafica.DrawString(Convert.ToString(x1), text, new SolidBrush(Color.Black), xs, 330);
                    x1++;
                    xs += 30;
                }
                //rayando <---------------------- Esta parte te interesa a ti
                for (int i = 1; i <= 21; i++)
                {
                    if (i <= 19)
                    {
                        grafica.DrawLine(cuadric, 300, 320 - (30 * i)/2, 630, 320 - (30 * i)/2);
                    }
                    grafica.DrawLine(cuadric, 300+(i*30)/2, 20, 300+(i*30)/2, 320);
                }
                 //  <-------------  Hasta Aki xD
                //graficando x1 y y1
                int a = Convert.ToInt16(textBox1.Text);
                int b = Convert.ToInt16(textBox2.Text);
                int es = Convert.ToInt16(textBox5.Text);
                //a = es / a;
                //b = es / b;
                grafica.DrawLine(ejes, 300, 320 - (es/b * 30), 300 + (es/a * 30), 320);
                //graficando x2 y y2
                int c = Convert.ToInt16(textBox3.Text);
                int d = Convert.ToInt16(textBox4.Text);
                int fs = Convert.ToInt16(textBox6.Text);
                //c = fs / c;
                //d = fs / d;
                grafica.DrawLine(ejes2, 300, (320 - (fs/d * 30)), (300 + (fs/c * 30)), 320);
                Graficar.Enabled = false;
                pictureBox1.Visible = true;
               
            }
            catch
            {
                MessageBox.Show("Caracter no valido");
            }
        }

        private void Salir_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void Nuevo_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
            textBox6.Text = "";
            textBox1.Focus();
            Graficar.Enabled = true;
        }

       
    }
}

Suerte ...   :comp: