Beispiel #1
0
        public async void ClickHandler(int x, int y)
        {
            if (size == GameType.Small)
            {
                //board[x, y] - cell clicked
                if (!SmallGrid.Board[x, y].HasValue)                            //If the cell is empty
                {
                    SmallGrid.AddFigure(x, y, turn);                            //Add figure
                    turn = turn == Figure.Cross ? Figure.Circle : Figure.Cross; //Change the turn
                    if (SmallGrid.Status != Status.Nothing)
                    {
                        EndHandler(SmallGrid.Status); //End the game if the small grid is full
                    }
                }
            }
            else if (size == GameType.Big)
            {
                //board[x / 3, y / 3] - small grid clicked
                //board[x / 3, y / 3].board[x % 3, y % 3] - cell clicked
                if (BigGrid.Board[x / 3, y / 3].Status == Status.Nothing && !BigGrid.Board[x / 3, y / 3].Board[x % 3, y % 3].HasValue) //If the cell is empty and the small grid isn't locked
                {
                    BigGrid.AddFigure(x / 3, y / 3, x % 3, y % 3, turn);                                                               //Add figure
                    turn = turn == Figure.Cross ? Figure.Circle : Figure.Cross;                                                        //Change the turn
                    if (BigGrid.Status != Status.Nothing)
                    {
                        EndHandler(BigGrid.Status); //End the game if the big grid is full
                    }
                }
            }
            else if (size == GameType.Huge)
            {
                //board[x / 9, y / 9] - big grid clicked
                //board[x / 9, y / 9].board[x % 9 / 3, y % 9 / 3] - small grid clicked
                //board[x / 9, y / 9].board[x % 9 / 3, y % 9 / 3].board[x % 3, y % 3] - cell clicked
                if (HugeGrid.Board[x / 9, y / 9].Status == Status.Nothing && HugeGrid.Board[x / 9, y / 9].Board[x % 9 / 3, y % 9 / 3].Status == Status.Nothing && !HugeGrid.Board[x / 9, y / 9].Board[x % 9 / 3, y % 9 / 3].Board[x % 3, y % 3].HasValue) //If the cell is empty and the small grid isn't locked and the big grid isn't locked
                {
                    HugeGrid.AddFigure(x / 9, y / 9, x % 9 / 3, y % 9 / 3, x % 9 % 3, y % 9 % 3, turn);                                                                                                                                                   //Add figure
                    turn = turn == Figure.Cross ? Figure.Circle : Figure.Cross;                                                                                                                                                                           //Change the turn
                    if (HugeGrid.Status != Status.Nothing)
                    {
                        EndHandler(HugeGrid.Status); //End the game if the huge grid is full
                    }
                }
            }
            await Task.Delay(50);                        //Wait

            if (turn == Figure.Cross && player1 != null) //Make AIs make choices
            {
                player1.MakeChoice();
            }
            else if (turn == Figure.Circle && player2 != null)
            {
                player2.MakeChoice();
            }
        }
Beispiel #2
0
        public async void ClickHandler(int x, int y)
        {
            if (size == GameType.Small)
            {
                //board[x, y] - cell clicked
                if (!SmallGrid.Board[x, y].HasValue)                            //If the cell is empty
                {
                    SmallGrid.AddFigure(x, y, turn);                            //Add figure
                    turn = turn == Figure.Cross ? Figure.Circle : Figure.Cross; //Change the turn
                    if (SmallGrid.Status != Status.Nothing)
                    {
                        EndHandler(SmallGrid.Status); //End the game if the small grid is full
                    }
                }
            }
            else if (size == GameType.Big)
            {
                //board[x / 3, y / 3] - small grid clicked
                //board[x / 3, y / 3].board[x % 3, y % 3] - cell clicked
                if ((x / 3 == BigGridCurrentPosX && y / 3 == BigGridCurrentPosY || BigGridCurrentPosX == -1) && BigGrid.Board[x / 3, y / 3].Status == Status.Nothing && !BigGrid.Board[x / 3, y / 3].Board[x % 3, y % 3].HasValue) //If the cell is empty and the small grid isn't locked
                {
                    BigGrid.Color(BigGridCurrentPosX, BigGridCurrentPosY, Brushes.Black);                                                                                                                                          //Decolor the previous available small grid / small grids
                    BigGrid.AddFigure(x / 3, y / 3, x % 3, y % 3, turn);                                                                                                                                                           //Add figure
                    BigGridCurrentPosX = x % 3;                                                                                                                                                                                    //Set the new available small grid
                    BigGridCurrentPosY = y % 3;
                    if (BigGrid.Board[BigGridCurrentPosX, BigGridCurrentPosY].Status != Status.Nothing)
                    {
                        BigGridCurrentPosX = -1;                                         //If the selected small grid is complete select all the small grids
                    }
                    BigGrid.Color(BigGridCurrentPosX, BigGridCurrentPosY, Brushes.Blue); //Color the new available small grid / small grids
                    turn = turn == Figure.Cross ? Figure.Circle : Figure.Cross;          //Change the turn
                    if (BigGrid.Status != Status.Nothing)
                    {
                        EndHandler(BigGrid.Status); //End the game if the big grid is full
                    }
                }
            }
            else if (size == GameType.Huge)
            {
                //board[x / 9, y / 9] - big grid clicked
                //board[x / 9, y / 9].board[x % 9 / 3, y % 9 / 3] - small grid clicked
                //board[x / 9, y / 9].board[x % 9 / 3, y % 9 / 3].board[x % 3, y % 3] - cell clicked
                if ((HugeGridCurrentPosX == -1 || (HugeGridCurrentPosX == x / 9 && HugeGridCurrentPosY == y / 9)) && (BigGridCurrentPosX == -1 || (BigGridCurrentPosX == x % 9 / 3 && BigGridCurrentPosY == y % 9 / 3)) && HugeGrid.Board[x / 9, y / 9].Status == Status.Nothing && HugeGrid.Board[x / 9, y / 9].Board[x % 9 / 3, y % 9 / 3].Status == Status.Nothing && !HugeGrid.Board[x / 9, y / 9].Board[x % 9 / 3, y % 9 / 3].Board[x % 3, y % 3].HasValue) //If the cell is empty and the small grid isn't locked and the big grid isn't locked
                {
                    HugeGrid.Color(HugeGridCurrentPosX, HugeGridCurrentPosY, BigGridCurrentPosX, BigGridCurrentPosY, Brushes.Black);                                                                                                                                                                                                                                                                                                                             //Decolor the previous available small grid / big grid / big grids
                    HugeGrid.AddFigure(x / 9, y / 9, x % 9 / 3, y % 9 / 3, x % 9 % 3, y % 9 % 3, turn);                                                                                                                                                                                                                                                                                                                                                          //Add figure
                    HugeGridCurrentPosX = x % 9 / 3;                                                                                                                                                                                                                                                                                                                                                                                                             //Set the new available big grid
                    HugeGridCurrentPosY = y % 9 / 3;
                    if (HugeGrid.Board[HugeGridCurrentPosX, HugeGridCurrentPosY].Status != Status.Nothing)
                    {
                        HugeGridCurrentPosX = -1; //If the selected big grid is complete select everything
                        BigGridCurrentPosX  = -1;
                    }
                    else
                    {
                        BigGridCurrentPosX = x % 3; //Set the new available small grid
                        BigGridCurrentPosY = y % 3;
                        if (HugeGrid.Board[HugeGridCurrentPosX, HugeGridCurrentPosY].Board[BigGridCurrentPosX, BigGridCurrentPosY].Status != Status.Nothing)
                        {
                            BigGridCurrentPosX = -1; //If the selected small grid is complete select all the small grids in the same big grid
                        }
                    }
                    HugeGrid.Color(HugeGridCurrentPosX, HugeGridCurrentPosY, BigGridCurrentPosX, BigGridCurrentPosY, Brushes.Blue); //Color the new available small grid / big grid / big grids
                    turn = turn == Figure.Cross ? Figure.Circle : Figure.Cross;                                                     //Change the turn
                    if (HugeGrid.Status != Status.Nothing)
                    {
                        EndHandler(HugeGrid.Status); //End the game if the huge grid is full
                    }
                }
            }
            await Task.Delay(50);                        //Wait

            if (turn == Figure.Cross && player1 != null) //Make AIs make choices
            {
                player1.MakeChoice();
            }
            else if (turn == Figure.Circle && player2 != null)
            {
                player2.MakeChoice();
            }
        }