Ejemplo n.º 1
0
        // sprawdź w rzędzie pionowo, konkretnie sprawdz pola na wsp. y dla zadanego x
        bool CheckWinningPatternVertical(int startX, PlayerMarker player)
        {
            for (int y = 0; y < Settings.BoardSize; ++y)
            {
                int index = (y * Settings.BoardSize) + startX;
                if (buttons[index].Text != player.ToString())
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
 // sprawdź w rzędzie poziomo, konkretnie sprawdź pola na wsp. x dla zadanego y
 bool CheckWinningPatternHorizontal(int startY, PlayerMarker player)
 {
     for (int x = 0; x < Settings.BoardSize; ++x)
     {
         int index = (startY * Settings.BoardSize) + x;  // policz który to indeks w liście przycisków
         // jeżeli którykolwiek będzie inny od oczekiwanego możesz przerwać i zwrócić false
         if (buttons[index].Text != player.ToString())
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 3
0
        // sprawdź na skosk do prawej do lewej
        bool CheckWinningPatternDiagonallyLeft(PlayerMarker player)
        {
            bool win = true;

            for (int y = Settings.BoardSize; y > 0; --y)
            {
                for (int x = Settings.BoardSize; x > 0; --x)
                {
                    int index = (y * Settings.BoardSize) - x;
                    if (x == y)
                    {
                        if (buttons[index].Text != player.ToString())
                        {
                            win = false;
                        }
                    }
                }
            }
            return(win);
        }
Ejemplo n.º 4
0
        // sprwadź na skoks od lewej do prawej
        bool CheckWinningPatternDiagonallyRight(PlayerMarker player)
        {
            bool win = true;

            for (int y = 0; y < Settings.BoardSize; ++y)
            {
                for (int x = 0; x < Settings.BoardSize; ++x)
                {
                    int index = (y * Settings.BoardSize) + x;
                    if (x == y)
                    {
                        if (buttons[index].Text != player.ToString())
                        {
                            win = false;
                        }
                    }
                }
            }
            return(win);
        }
Ejemplo n.º 5
0
        void PerformPCMove(PlayerMarker player)
        {
            // Ruch komputera, można zaimplementować coś z...
https:      //en.wikipedia.org/wiki/Tic-tac-toe

            // wybierz losowe wolne pole
            System.Random rand = new Random();
            List <int> emptyIndexes = new List <int>();

            for (int i = 0; i < buttons.Count(); ++i)
            {
                if (buttons[i].Text == String.Empty) // sprawdź które przyciski są puste
                {
                    emptyIndexes.Add(i);             //  dodaj indeks to listy
                }
            }

            int selectedIndex = rand.Next(0, emptyIndexes.Count());        // wylosuj indeks wolnego pola

            buttons[emptyIndexes[selectedIndex]].Text = player.ToString(); // użyj go aby wykonać ruch
        }