public void klikniecie(int x, int y, Plansza p, Gracz gracz)
        {
            //pole klasy "Ruchy"
            if (this.pole[x, y] == 0)
            {
                this.zerowanie();
                //jezeli w polu znajduje sie pionek
                if (p.pole[x, y] > 1)
                {
                    //obecnie zaznaczony pionek
                    this.pole[x, y] = 1;

                    //jezeli jest to Wilk
                    if (p.pole[x, y] == 2 && gracz.get_gracz() == 1)
                    {
                        //prawo gora
                        if (x > 0 && y > 0 && p.pole[x - 1, y - 1] == 1)
                        {
                            this.pole[x - 1, y - 1] = 2;
                        }
                        //prawo dol
                        if (x < 7 && y < 7 && p.pole[x + 1, y + 1] == 1)
                        {
                            this.pole[x + 1, y + 1] = 2;
                        }
                        //lewo gora
                        if (x < 7 && y > 0 && p.pole[x + 1, y - 1] == 1)
                        {
                            this.pole[x + 1, y - 1] = 2;
                        }
                        //lewo dol
                        if (x > 0 && y < 7 && p.pole[x - 1, y + 1] == 1)
                        {
                            this.pole[x - 1, y + 1] = 2;
                        }
                    }

                    //jezeli jest to Owca
                    else if (p.pole[x, y] == 3 && gracz.get_gracz() == 2)
                    {
                        //lewo dol
                        if (x > 0 && y < 7 && p.pole[x - 1, y + 1] == 1)
                        {
                            this.pole[x - 1, y + 1] = 2;
                        }
                        //prawo dol
                        if (x < 7 && y < 7 && p.pole[x + 1, y + 1] == 1)
                        {
                            this.pole[x + 1, y + 1] = 2;
                        }
                    }

                    this.wyswietlanie();
                }
                //przypisanie nowego polozenia pionka
                old_x = x;
                old_y = y;
            }
            else if (this.pole[x, y] == 2)
            {
                p.pole[x, y]         = p.pole[old_x, old_y];
                p.pole[old_x, old_y] = 1;
                wykonanoRuch         = true;
                this.zerowanie();
                gracz.zmiana_gracza();
            }
        }
示例#2
0
        //sprawdzenie wygranej graczy
        public int wygrana(Gracz g, Plansza p)
        {
            int Wilk_X = 0;
            int Wilk_Y = 0;
            int Owca_X = 0;
            int Owca_Y = 0;

            for (int j = 0; j < 8; j++)
            {
                for (int i = 0; i < 8; i++)
                {
                    if (p.pole[i, j] == 2)
                    {
                        Wilk_X = i;
                        Wilk_Y = j;
                    }
                }
            }

            int temp = 0;

            for (int j = 0; j < 8; j++)
            {
                for (int i = 0; i < 8; i++)
                {
                    //wygrana Wilka
                    if (p.pole[i, j] == 3)
                    {
                        Owca_X = i;
                        Owca_Y = j;
                        temp++;
                    }
                    if (temp == 1)
                    {
                        break;
                    }
                }
                if (temp == 1)
                {
                    break;
                }
            }

            //wygrana Wilka
            if (Wilk_Y <= Owca_Y)
            {
                Console.WriteLine("Wilk wygral!");
                return(2);
            }

            int x = 0, y = 0;

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (p.pole[i, j] == 2)
                    {
                        x = i;
                        y = j;
                        break;
                    }
                }
                if (x != 0 || y != 0)
                {
                    break;
                }
            }

            if (p.pole[x, y] == 2)
            {
                if ((x > 0 && x < 7 && y > 0 && y < 7) &&
                    p.pole[x - 1, y - 1] != 1 &&
                    p.pole[x + 1, y - 1] != 1 &&
                    p.pole[x - 1, y + 1] != 1 &&
                    p.pole[x + 1, y + 1] != 1)
                {
                    Console.WriteLine("Wygraly Owce!");
                    return(3);
                }
                if ((x == 0 && y == 7) && p.pole[x + 1, y - 1] != 1)
                {
                    Console.WriteLine("Wygraly Owce!");
                    return(3);
                }
                if ((x == 0 && y < 7) && p.pole[x + 1, y - 1] != 1 && p.pole[x + 1, y + 1] != 1)
                {
                    Console.WriteLine("Wygraly Owce!");
                    return(3);
                }
                if ((x == 7 && y < 7 && y > 0) && p.pole[x - 1, y - 1] != 1 && p.pole[x - 1, y + 1] != 1)
                {
                    Console.WriteLine("Wygraly Owce!");
                    return(3);
                }
                if ((x > 0 && y == 7) && p.pole[x - 1, y - 1] != 1 && p.pole[x + 1, y - 1] != 1)
                {
                    Console.WriteLine("Wygraly Owce!");
                    return(3);
                }
                else
                {
                    return(0);
                }
            }
            return(0);
        }