Beispiel #1
0
        public static List <MyRectangle> GetNeighbors(MyRectangle rect)
        {
            int x = rect.Position.X, y = rect.Position.Y;
            List <MyRectangle> neighbors = new List <MyRectangle>();

            if (rect.Width == 50)
            {
                if (y > 50 && y < 250)
                {
                    neighbors.Add(AtVertical(x, y - 50));
                    neighbors.Add(AtVertical(x + 50, y - 50));
                    neighbors.Add(AtHorizontal(x, y - 50));
                    neighbors.Add(AtHorizontal(x, y + 50));
                    neighbors.Add(AtVertical(x + 50, y));
                    neighbors.Add(AtVertical(x, y));
                }
                if (y == 50)
                {
                    neighbors.Add(AtVertical(x, y));
                    neighbors.Add(AtVertical(x + 50, y));
                    neighbors.Add(AtHorizontal(x, y + 50));
                }
                if (y == 250)
                {
                    neighbors.Add(AtVertical(x, y - 50));
                    neighbors.Add(AtVertical(x + 50, y - 50));
                    neighbors.Add(AtHorizontal(x, y - 50));
                }
            }
            else
            {
                if (x > 50 && x < 250)
                {
                    neighbors.Add(AtHorizontal(x - 50, y));
                    neighbors.Add(AtHorizontal(x - 50, y + 50));
                    neighbors.Add(AtHorizontal(x, y));
                    neighbors.Add(AtHorizontal(x, y + 50));
                    neighbors.Add(AtVertical(x - 50, y));
                    neighbors.Add(AtVertical(x + 50, y));
                }
                if (x == 50)
                {
                    neighbors.Add(AtHorizontal(x, y));
                    neighbors.Add(AtHorizontal(x, y + 50));
                    neighbors.Add(AtVertical(x + 50, y));
                }
                if (x == 250)
                {
                    neighbors.Add(AtHorizontal(x - 50, y));
                    neighbors.Add(AtHorizontal(x - 50, y + 50));
                    neighbors.Add(AtVertical(x - 50, y));
                }
            }

            return(neighbors);
        }
Beispiel #2
0
 public override void OnTurn(MyRectangle selected, List <MyRectangle> rectangles)
 {
     if (selected != null && selected.isClicked == false)
     {
         rectangles
         .Where(r => r == selected)
         .FirstOrDefault().isClicked = true;
         selected.Color = Color;
         Turn           = false;
     }
 }
Beispiel #3
0
 public static void ReturnCounters(List <MyRectangle> neighbors, MyRectangle current, out int br1, out int br2)
 {
     br1 = 0;
     br2 = 0;
     if (neighbors
         .Where(r => r.isClicked)
         .ToList().Count == 6)
     {
         Form1.allneighbors = true;
         if (current.Width > 1)
         {
             Form1.point2 = new Point(current.Position.X, current.Position.Y - 50);
         }
         else
         {
             Form1.point2 = new Point(current.Position.X, current.Position.Y);
         }
     }
     foreach (var r in neighbors)
     {
         if (r.isClicked && current != null)
         {
             if (current.Width > 1)
             {
                 if (r.Position.Y < current.Position.Y)
                 {
                     br1++;
                 }
                 else
                 {
                     br2++;
                 }
             }
             else
             if (r.Position.X < current.Position.X)
             {
                 br1++;
             }
             else
             {
                 br2++;
             }
         }
     }
 }
Beispiel #4
0
 public void DrawSquare(Graphics g, bool flag, Point point, List <MyRectangle> rect, Color color)
 {
     if (flag)
     {
         MyRectangle rect2 = new MyRectangle(point.X + 6, point.Y + 6, 40, 40);
         rect2.Position = point;
         rect2.Color    = color;
         rect.Add(rect2);
     }
     foreach (var r in rect)
     {
         using (var brush = new SolidBrush(r.Color))
         {
             using (var pen = new Pen(Color.Gray, 1))
             {
                 g.FillRectangle(brush, r.Position.X + 6, r.Position.Y + 6, 40, 40);
             }
         }
     }
 }
Beispiel #5
0
        public List <MyRectangle> GetArray()
        {
            Point x = new Point(50, 50);
            Point y = new Point(50, 100);

            for (int i = 0; i < 5; i++)
            {
                y.Y = 100;
                x.Y = 50;
                for (int j = 0; j < 4; j++)
                {
                    MyRectangle rect = new MyRectangle(x.X, x.Y, 1, 50);
                    rect.Position = new Point(x.X, x.Y);
                    rect.Color    = Color.Gray;
                    rectangles.Add(rect);
                    x.Y += 50;
                }
                x.X += 50;
            }
            y.Y = 50;
            x.Y = 50;

            for (int i = 0; i <= 4; i++)
            {
                x.X = 50;
                y.X = 100;
                for (int j = 0; j < 4; j++)
                {
                    MyRectangle rect2 = new MyRectangle(x.X, y.Y, 50, 1);
                    rect2.Position = new Point(x.X, y.Y);
                    rect2.Color    = Color.Gray;
                    rectangles.Add(rect2);
                    x.X += 50;
                }
                y.Y += 50;
            }
            return(rectangles);
        }
Beispiel #6
0
 public virtual void OnTurn(MyRectangle element, List <MyRectangle> rectangles)
 {
 }
Beispiel #7
0
        private void Cmove()
        {
            if (!gameover)
            {
                selected = Computer.Move(rectangles);
            }

            if (selected != null && selected.isClicked == false)
            {
                rectangles.Where(r => r == selected)
                .FirstOrDefault().isClicked = true;
                selected.Color = computer.Color;
                var selectedNeighbors = Board.GetNeighbors(selected);

                int br1 = 0, br2 = 0, minx, miny;
                if (selectedNeighbors
                    .Where(r => r.isClicked)
                    .ToList().Count == 6)
                {
                    allneighbors = true;
                    if (selected.Width > 1)
                    {
                        point2 = new Point(selected.Position.X, selected.Position.Y - 50);
                    }
                    else
                    {
                        point2 = new Point(selected.Position.X, selected.Position.Y);
                    }
                }
                foreach (var r in selectedNeighbors)
                {
                    if (r.isClicked && selected != null)
                    {
                        if (selected.Width > 1)
                        {
                            if (r.Position.Y < selected.Position.Y)
                            {
                                br1++;
                            }
                            else
                            {
                                br2++;
                            }
                        }
                        else
                        if (r.Position.X < selected.Position.X)
                        {
                            br1++;
                        }
                        else
                        {
                            br2++;
                        }
                    }

                    if (br1 == 3 || br2 == 3)
                    {
                        minx  = Math.Min(r.Position.X, selected.Position.X);
                        miny  = Math.Min(r.Position.Y, selected.Position.Y);
                        flag  = true;
                        point = new Point(minx, miny);
                        // MessageBox.Show(br1.ToString() + " "+ br2.ToString());
                        if (human.Turn)
                        {
                            sqcolor = human.Color;
                        }
                        else
                        {
                            sqcolor = computer.Color;
                        }
                        br1 = 0;
                        br2 = 0;
                    }
                }
                if (flag)
                {
                    human.Turn    = false;
                    computer.Turn = true;
                    computer.Score++;
                    if (allneighbors)
                    {
                        computer.Score++;
                    }
                }
                else
                {
                    human.Turn    = true;
                    computer.Turn = false;
                }
                selected = null;
            }
            Invalidate();
        }
Beispiel #8
0
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (human.Turn)
                {
                    selected = rectangles
                               .Where(r => r.Contains(e.Location))
                               .FirstOrDefault();

                    if (selected != null && selected.isClicked == false)
                    {
                        rectangles
                        .Where(r => r == selected)
                        .FirstOrDefault().isClicked = true;
                        selected.Color = human.Color;

                        var selectedNeighbors = Board.GetNeighbors(selected);
                        int br1 = 0, br2 = 0, minx, miny;
                        if (selectedNeighbors
                            .Where(r => r.isClicked)
                            .ToList().Count == 6)
                        {
                            allneighbors = true;
                            if (selected.Width > 1)
                            {
                                point2 = new Point(selected.Position.X, selected.Position.Y - 50);
                            }
                            else
                            {
                                point2 = new Point(selected.Position.X, selected.Position.Y);
                            }
                        }
                        foreach (var r in selectedNeighbors)
                        {
                            if (r.isClicked && selected != null)
                            {
                                if (selected.Width > 1)
                                {
                                    if (r.Position.Y < selected.Position.Y)
                                    {
                                        br1++;
                                    }
                                    else
                                    {
                                        br2++;
                                    }
                                }
                                else
                                if (r.Position.X < selected.Position.X)
                                {
                                    br1++;
                                }
                                else
                                {
                                    br2++;
                                }
                            }

                            if (br1 == 3 || br2 == 3)
                            {
                                minx  = Math.Min(r.Position.X, selected.Position.X);
                                miny  = Math.Min(r.Position.Y, selected.Position.Y);
                                flag  = true;
                                point = new Point(minx, miny);
                                if (human.Turn)
                                {
                                    sqcolor = human.Color;
                                }
                                else
                                {
                                    sqcolor = computer.Color;
                                }
                                br1 = 0;
                                br2 = 0;
                            }
                        }

                        if (flag)
                        {
                            human.Turn    = true;
                            computer.Turn = false;
                            human.Score++;
                            if (allneighbors)
                            {
                                human.Score++;
                            }
                        }
                        else
                        {
                            human.Turn    = false;
                            computer.Turn = true;
                        }
                        selected = null;
                    }
                }
            }
            Invalidate();
        }