Example #1
0
        public Board(PictureBox box)  //inicjalizuje nody
        {
            this.box = box;

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    nodeTable[i, j] = new BoardNodes();
                }
            }


            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    nodeTable[i, j].x1 = i * 50;
                    nodeTable[i, j].y1 = j * 50;
                    nodeTable[i, j].x2 = (i * 50) + 50;
                    nodeTable[i, j].y2 = (j * 50) + 50;

                    if ((i + j) % 2 == 0)  //kolorowanie nodów
                    {
                        nodeTable[i, j].base_colour = 1;
                        nodeTable[i, j].colour      = 1;
                    }
                    else
                    {
                        nodeTable[i, j].base_colour = 2;
                        nodeTable[i, j].colour      = 2;
                    }
                }
            }

            Create_figures();
        }
Example #2
0
        public void Selected_node(Point coordinates)
        {
            for (int i = 0; i < 8; i++)
            {
                if (nodeTable[i, 0].x2 <= coordinates.Y)
                {
                    continue;
                }

                else
                {
                    for (int j = 0; j < 8; j++)
                    {
                        if (nodeTable[i, j].y2 < coordinates.X)
                        {
                            continue;
                        }
                        else
                        {
                            if (nodeTable[j, i].colour == 3)
                            {
                                nodeTable[j, i].colour = nodeTable[j, i].base_colour;
                                if (selected1 == nodeTable[j, i])
                                {
                                    selected1 = null;
                                }
                                if (selected2 == nodeTable[j, i])
                                {
                                    selected2 = null;
                                }
                                break;
                            }

                            else
                            {
                                if (selected1 == null)
                                {
                                    if (nodeTable[j, i].figure != null)
                                    {
                                        selected1 = nodeTable[j, i];
                                        nodeTable[j, i].colour = 3;
                                        break;
                                    }
                                    break;
                                }
                                else if (selected2 == null)
                                {
                                    selected2 = nodeTable[j, i];
                                    nodeTable[j, i].colour = 3;
                                    break;
                                }
                                else
                                {
                                    break;  //kiedy wybrane są już 2 pola
                                }
                            }
                        }
                    }
                    break;
                }
            }
            Draw();
        }