示例#1
0
 private void ChangeToDamaIfPossible(Square sq, Kaminek k)
 {
     if (sq.Souradnice.Y == 0 || sq.Souradnice.Y == 7)
     {
         k.IsDama = true;
     }
 }
示例#2
0
        public void ukazatDostupnePole(Kaminek k, int hrac)
        {
            //Smazat kamen z pole
            if (k.X == squares[k.Index].X + 5 && k.Y == squares[k.Index].Y + 5) // podle souradnice mysi na Canvasu
            {
                originSquare = squares[k.Index];                                // Pole obsahuje puvodni pozici origin_kaminka
            }

            if (hrac == 2)
            {
                if (k.IsDama)
                {
                    naplnitDiagonali(k);
                }
                else
                {
                    if (squares[k.Index].Souradnice.Y % 2 == 0)
                    {
                        dostupnePole2(k.Index, k.Index - 3, k.Index - 7);
                        dostupnePole2(k.Index, k.Index - 4, k.Index - 9);
                    }
                    else if (squares[k.Index].Souradnice.Y % 2 == 1)
                    {
                        dostupnePole2(k.Index, k.Index - 4, k.Index - 7);
                        dostupnePole2(k.Index, k.Index - 5, k.Index - 9);
                    }
                }
            }
            else if (hrac == 1)
            {
                if (k.IsDama)
                {
                    naplnitDiagonali(k);
                }
                else
                {
                    if (squares[k.Index].Souradnice.Y % 2 == 0)
                    {
                        dostupnePole1(k.Index, k.Index + 4, k.Index + 7);
                        dostupnePole1(k.Index, k.Index + 5, k.Index + 9);
                    }
                    else if (squares[k.Index].Souradnice.Y % 2 == 1)
                    {
                        dostupnePole1(k.Index, k.Index + 3, k.Index + 7);
                        dostupnePole1(k.Index, k.Index + 4, k.Index + 9);
                    }
                }
            }
        }
示例#3
0
 void OznacDostupnePoleProDamu(Kaminek k) // Označit dostupné políčka podle každé diagonále
 {
     for (int i = diagonal_topLeft.Count - 1; i >= 0; i--)
     {
         if (diagonal_topLeft[i].Kamen?.BelongToHrac == k.BelongToHrac)
         {
             break;
         }
         else
         {
             oznacitDostupnePole(diagonal_topLeft[i]);
         }
     }
     for (int i = diagonal_topRight.Count - 1; i >= 0; i--)
     {
         if (diagonal_topRight[i].Kamen?.BelongToHrac == k.BelongToHrac)
         {
             break;
         }
         else
         {
             oznacitDostupnePole(diagonal_topRight[i]);
         }
     }
     for (int i = 0; i < diagonal_botLeft.Count; i++)
     {
         if (diagonal_botLeft[i].Kamen?.BelongToHrac == k.BelongToHrac)
         {
             break;
         }
         else
         {
             oznacitDostupnePole(diagonal_botLeft[i]);
         }
     }
     for (int i = 0; i < diagonal_botRight.Count; i++)
     {
         if (diagonal_botRight[i].Kamen?.BelongToHrac == k.BelongToHrac)
         {
             break;
         }
         else
         {
             oznacitDostupnePole(diagonal_botRight[i]);
         }
     }
 }
示例#4
0
 public void EnableAllKaminek(Kaminek k)
 {
     if (k.BelongToHrac == 1)
     {
         foreach (Kaminek kaminky in hrac1.kaminky)
         {
             kaminky.Disable = false;
         }
     }
     if (k.BelongToHrac == 2)
     {
         foreach (Kaminek kaminky in hrac2.kaminky)
         {
             kaminky.Disable = false;
         }
     }
 }
示例#5
0
        // Zkontroluje jestli nemuze skocit dal (Pro normalni)
        public bool Skoc_Dal(Kaminek k)
        {
            clearDostupnePole();
            ukazatDostupnePole(k, k.BelongToHrac);
            if (!k.IsDama)
            {
                foreach (Square sq in dostupePolicka)
                {
                    if (!k.IsDama && Math.Abs(squares[k.Index].Souradnice.Y - sq.Souradnice.Y) == 2)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#6
0
        void naplnitDiagonali(Kaminek k) // Naplnit 4 směry(top-left/right, bot-left/right) do listu
        {
            all_diagonals     = new List <Square>();
            diagonal_botLeft  = new List <Square>();
            diagonal_botRight = new List <Square>();
            diagonal_topLeft  = new List <Square>();
            diagonal_topRight = new List <Square>();

            for (int i = 0; i < squares.Count; i++)
            {
                if (Math.Abs(squares[i].Souradnice.X - squares[k.Index].Souradnice.X) == Math.Abs(squares[i].Souradnice.Y - squares[k.Index].Souradnice.Y))
                {
                    all_diagonals.Add(squares[i]);
                }
            }

            for (int i = 0; i < all_diagonals.Count; i++)
            {
                if (all_diagonals[i].Index < k.Index)
                {
                    if (all_diagonals[i].Souradnice.X < squares[k.Index].Souradnice.X)
                    {
                        diagonal_topLeft.Add(all_diagonals[i]);
                    }
                    else
                    {
                        diagonal_topRight.Add(all_diagonals[i]);
                    }
                }
                if (all_diagonals[i].Index > k.Index)
                {
                    if (all_diagonals[i].Souradnice.X < squares[k.Index].Souradnice.X)
                    {
                        diagonal_botLeft.Add(all_diagonals[i]);
                    }
                    else
                    {
                        diagonal_botRight.Add(all_diagonals[i]);
                    }
                }
            }

            OznacDostupnePoleProDamu(k);
        }
示例#7
0
 public int umistitKamen(Kaminek k)
 {
     foreach (Square sq in dostupePolicka)
     {
         if (sq.X < k.X + k.Velikost / 2 &&
             sq.X + Square.width > k.X + k.Velikost / 2 &&
             sq.Y < k.Y + k.Velikost / 2 &&
             sq.Y + Square.width > k.Y + k.Velikost / 2)
         {
             if (k.IsDama)
             {
                 Dama_SebratKamen(originSquare.Index, sq.Index, k);
                 k.X                = sq.X + 5;
                 k.Y                = sq.Y + 5;
                 k.Index            = sq.Index;
                 sq.Kamen           = k;
                 originSquare.Kamen = null;
                 return(3);
             }
             else if (Math.Abs(sq.Index - originSquare.Index) > 5)
             {
                 SebratKamen(originSquare.Index, sq.Index);
                 k.X                = sq.X + 5;
                 k.Y                = sq.Y + 5;
                 k.Index            = sq.Index;
                 sq.Kamen           = k;
                 originSquare.Kamen = null;
                 ChangeToDamaIfPossible(sq, k);
                 return(2);
             }
             else
             {
                 k.X                = sq.X + 5;
                 k.Y                = sq.Y + 5;
                 k.Index            = sq.Index;
                 sq.Kamen           = k;
                 originSquare.Kamen = null;
                 ChangeToDamaIfPossible(sq, k);
                 return(1);
             }
         }
     }
     return(0);
 }
示例#8
0
        public void createKaminky()
        {
            for (int i = 0; i < 12; i++)
            {
                Kaminek k1 = new Kaminek(Square.width - 10, squares[i].X + 5, squares[i].Y + 5, 1);
                k1.Color         = "#000000";
                k1.Index         = i;
                squares[i].Kamen = k1;
                hrac1.kaminky.Add(k1);

                Kaminek k2 = new Kaminek(Square.width - 10, squares[32 - i - 1].X + 5, squares[32 - i - 1].Y + 5, 2);
                k2.Color = "#FFFFFF";
                k2.Index = 32 - i - 1;
                squares[32 - i - 1].Kamen = k2;
                hrac2.kaminky.Add(k2);
            }
            hrac1.kaminky[9].IsDama = true;
            hrac2.kaminky[9].IsDama = true;
            //hrac2.kaminky[10].IsDama = true;
        }
示例#9
0
        private void canvas_MouseDown(object sender, MouseEventArgs e)
        {
            Kaminek kamen = chessBoard.selectKaminek(_turnHrace, e.X, e.Y);

            if (kamen != null && kamen.Disable == false)
            {
                if (kamen.BelongToHrac != _turnHrace)
                {
                    return;
                }
                selected_kamen = kamen;
                origin_x       = kamen.X;
                origin_y       = kamen.Y;
                selected       = true;
                chessBoard.ukazatDostupnePole(kamen, _turnHrace);
                canvas.Refresh();
            }
            else
            {
                selected_kamen = null; // Kdyz si vybiram spatne kaminky
            }
        }
示例#10
0
 public void DisableOtherKamen(Kaminek k)
 {
     if (k.BelongToHrac == 1)
     {
         foreach (Kaminek kaminky in hrac1.kaminky)
         {
             if (kaminky != k)
             {
                 kaminky.Disable = true;
             }
         }
     }
     if (k.BelongToHrac == 2)
     {
         foreach (Kaminek kaminky in hrac2.kaminky)
         {
             if (kaminky != k)
             {
                 kaminky.Disable = true;
             }
         }
     }
 }
示例#11
0
        // Skontroluje jestli Dama může ještě někam skočit po snězení nějakého kamínku
        // Projede postupně 4 diagonály. Zkontroluje jestli za protiherním kamínkem je nějaké dostupné políčko.
        public bool CanDamaJumpMore(Kaminek k)
        {
            naplnitDiagonali(k);
            int count = 0; // Pocita pocet dostupnych polich

            // Cac vong for ben duoi sau phai dc gop thanh ham
            if (k.BelongToHrac == 2)
            {
                for (int i = 0; i < diagonal_botLeft.Count; i++)
                {
                    if (diagonal_botLeft[i].Kamen?.BelongToHrac == 1)
                    {
                        int j = i + 1;
                        while (j < diagonal_botLeft.Count)
                        {
                            if (diagonal_botLeft[j].Kamen == null)
                            {
                                count++;
                                j++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        break;
                    }
                }
                for (int i = 0; i < diagonal_botRight.Count; i++)
                {
                    if (diagonal_botRight[i].Kamen?.BelongToHrac == 1)
                    {
                        int j = i + 1;
                        while (j < diagonal_botRight.Count)
                        {
                            if (diagonal_botRight[j].Kamen == null)
                            {
                                count++;
                                j++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        break;
                    }
                }
                for (int i = diagonal_topLeft.Count - 1; i > 0; i--)
                {
                    if (diagonal_topLeft[i].Kamen?.BelongToHrac == 1)
                    {
                        int j = i - 1;
                        while (j > 0)
                        {
                            if (diagonal_topLeft[j].Kamen == null)
                            {
                                count++;
                                j--;
                            }
                            else
                            {
                                break;
                            }
                        }
                        break;
                    }
                }
                for (int i = diagonal_topRight.Count - 1; i > 0; i--)
                {
                    if (diagonal_topRight[i].Kamen?.BelongToHrac == 1)
                    {
                        int j = i - 1;
                        while (j > 0)
                        {
                            if (diagonal_topRight[j].Kamen == null)
                            {
                                count++;
                                j--;
                            }
                            else
                            {
                                break;
                            }
                        }
                        break;
                    }
                }
            }
            else if (k.BelongToHrac == 1)
            {
                for (int i = 0; i < diagonal_topLeft.Count; i++)
                {
                    if (diagonal_topLeft[i].Kamen?.BelongToHrac == 2)
                    {
                        int j = i + 1;
                        while (j < diagonal_topLeft.Count)
                        {
                            if (diagonal_topLeft[j].Kamen == null)
                            {
                                count++;
                                j++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        break;
                    }
                }
                for (int i = 0; i < diagonal_botLeft.Count; i++)
                {
                    if (diagonal_botLeft[i].Kamen?.BelongToHrac == 2)
                    {
                        int j = i + 1;
                        while (j < diagonal_botLeft.Count)
                        {
                            if (diagonal_botLeft[j].Kamen == null)
                            {
                                count++;
                                j++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        break;
                    }
                }
                for (int i = diagonal_topRight.Count - 1; i > 0; i--)
                {
                    if (diagonal_topRight[i].Kamen?.BelongToHrac == 1)
                    {
                        int j = i - 1;
                        while (j > 0)
                        {
                            if (diagonal_topRight[j].Kamen == null)
                            {
                                count++;
                                j--;
                            }
                            else
                            {
                                break;
                            }
                        }
                        break;
                    }
                }

                for (int i = diagonal_botRight.Count - 1; i > 0; i--)
                {
                    if (diagonal_botRight[i].Kamen?.BelongToHrac == 1)
                    {
                        int j = i - 1;
                        while (j > 0)
                        {
                            if (diagonal_botRight[j].Kamen == null)
                            {
                                count++;
                                j--;
                            }
                            else
                            {
                                break;
                            }
                        }
                        break;
                    }
                }
            }

            //---------------------------------------------------------------------------------------
            if (count > 0 && nejakyKaminekBylOdstranen())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#12
0
        void Dama_SebratKamen(int indexOrigin, int destinationIndex, Kaminek k)
        {
            // Myslenka je sebrat kameny tak, ze zkontroluji 4 diagonaly
            if (squares[indexOrigin].Souradnice.Y > squares[destinationIndex].Souradnice.Y)
            {
                if (squares[indexOrigin].Souradnice.X < squares[destinationIndex].Souradnice.X)
                {
                    for (int i = diagonal_topRight.Count - 1; i > 0; i--) // Sebrat po TOP_RIGHT diagonale
                    {
                        if (diagonal_topRight[i].Index > destinationIndex)
                        {
                            if (k.BelongToHrac == 1)
                            {
                                hrac2.kaminky.RemoveAll(r => r.Index == diagonal_topRight[i].Index);
                            }
                            else if (k.BelongToHrac == 2)
                            {
                                hrac1.kaminky.RemoveAll(r => r.Index == diagonal_topRight[i].Index);
                            }

                            squares[diagonal_topRight[i].Index].Kamen = null;
                        }
                    }
                }
                if (squares[indexOrigin].Souradnice.X > squares[destinationIndex].Souradnice.X)
                {
                    for (int i = diagonal_topLeft.Count - 1; i > 0; i--) // Sebrat po TOP_LEFT diagonale
                    {
                        if (diagonal_topLeft[i].Index > destinationIndex)
                        {
                            if (k.BelongToHrac == 1)
                            {
                                hrac2.kaminky.RemoveAll(r => r.Index == diagonal_topLeft[i].Index);
                            }
                            else if (k.BelongToHrac == 2)
                            {
                                hrac1.kaminky.RemoveAll(r => r.Index == diagonal_topLeft[i].Index);
                            }

                            squares[diagonal_topLeft[i].Index].Kamen = null;
                        }
                    }
                }
            }
            else if (squares[indexOrigin].Souradnice.Y < squares[destinationIndex].Souradnice.Y)
            {
                if (squares[indexOrigin].Souradnice.X < squares[destinationIndex].Souradnice.X)
                {
                    for (int i = 0; i < diagonal_botRight.Count; i++) // Sebrat po BOT_RIGHT diagonale
                    {
                        if (diagonal_botRight[i].Index < destinationIndex)
                        {
                            if (k.BelongToHrac == 1)
                            {
                                hrac2.kaminky.RemoveAll(r => r.Index == diagonal_botRight[i].Index);
                            }
                            else if (k.BelongToHrac == 2)
                            {
                                hrac1.kaminky.RemoveAll(r => r.Index == diagonal_botRight[i].Index);
                            }

                            squares[diagonal_botRight[i].Index].Kamen = null;
                        }
                    }
                }
                else if (squares[indexOrigin].Souradnice.X > squares[destinationIndex].Souradnice.X)
                {
                    for (int i = 0; i < diagonal_botLeft.Count; i++) // Sebrat po BOT_LEFT diagonale
                    {
                        if (diagonal_botLeft[i].Index < destinationIndex)
                        {
                            if (k.BelongToHrac == 1)
                            {
                                hrac2.kaminky.RemoveAll(r => r.Index == diagonal_botLeft[i].Index);
                            }
                            else if (k.BelongToHrac == 2)
                            {
                                hrac1.kaminky.RemoveAll(r => r.Index == diagonal_botLeft[i].Index);
                            }

                            squares[diagonal_botLeft[i].Index].Kamen = null;
                        }
                    }
                }
            }
            sumKaminky_after = hrac1.kaminky.Count + hrac2.kaminky.Count;
        }