개발에서 프로토타입 또는 스켈레톤 방식 있다.

간단하게 구연 후에 계속 수정하며서 완성도를 높혀가는 방법이다.

그래서, 바둑이나 오목을 위해서 바둑판 그리기 1차로 만들고

다음에 함수로 수정하고 그 다음엔  바둑알이 있는 위치를 기억하도록 수정하겠다.

 

※ 소스

using System.Security.Cryptography.Pkcs;

namespace omk
{
    public partial class Form1 : Form
    {
        const int size = 40;
        SolidBrush bBrush = new SolidBrush(Color.Black);
        SolidBrush wBrush = new SolidBrush(Color.White);
        Graphics gr;
        bool flg = true;
        public FrmOmk()
        {
            InitializeComponent();
        }

        private void Form_Load(object sender, EventArgs e)
        {
            gr = this.CreateGraphics();
            this.BackColor = Color.Orange;
        }
        private void Form_Paint(object sender, PaintEventArgs e)
        {
            DrawBoard(e.Graphics);
        }
        private void Form_MouseClick(Object sender, MouseEventArgs e)
        {
            int m1 = 5;
            int m2 = 18 * size + m1 + 1;
            int x = ((e.X - m1) / size) * size + m1;
            int y = ((e.Y - m1) / size) * size + m1;
            if (x > 0 && y > 0 && x < m2 && y < m2)
            {
                if (flg) gr.FillEllipse(bBrush, x, y, size - 2, size - 2);
                else gr.FillEllipse(wBrush, x, y, size - 2, size - 2);
                flg = !flg;
            }

        }

        private void DrawBoard(Graphics gr)
        {
            int m1 = size / 2 + 5;
            int m2 = 18 * size + m1;
            using (Pen pen = new Pen(Color.Black))
            {
                int p1 = m1, p2 = 0;
                for (int i = 0; i < 19; i++, p1 += size)
                {
                    gr.DrawLine(pen, p1, m1, p1, m2);
                    gr.DrawLine(pen, m1, p1, m2, p1);
                }

                for (int x = 3; x < 19; x += 6)
                {
                    p1 = x * size + m1 - 5;
                    for (int y = 3; y < 19; y += 6)
                    {
                        p2 = y * size + m1 - 5;
                        gr.FillEllipse(bBrush, p1, p2, 10, 10);
                    }
                }
            }
        }
        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.Width = 800;
            this.Height = 830;
            this.Load += Form_Load;
            this.Paint += Form_Paint;
            this.MouseClick += Form_MouseClick;
        }
    }
}

 

※ 실행화면

728x90

+ Recent posts