Beispiel #1
0
        bool isWin(Board gameBoard, Player player)
        {
            for (int j = 0; j < Settings.Default.BoardWidth; j++)
            {
                for (int i = 0; i <= Settings.Default.BoardHeight - winCount; i++)
                {
                    int k = 0;

                    while (k < winCount && gameBoard.IsPlayerCell(i + k, j, player))
                    {
                        k++;
                    }

                    if (k == winCount)
                    {
                        showWinCells(i, j, 0, 0, 1, 0);
                        return(true);
                    }
                }
            }

            for (int i = 0; i < Settings.Default.BoardHeight; i++)
            {
                for (int j = 0; j <= Settings.Default.BoardWidth - winCount; j++)
                {
                    int k = 0;

                    while (k < winCount && gameBoard.IsPlayerCell(i, j + k, player))
                    {
                        k++;
                    }

                    if (k == winCount)
                    {
                        showWinCells(i, j, 0, 0, 0, 1);
                        return(true);
                    }
                }
            }

            for (int i = 0; i <= Settings.Default.BoardHeight - winCount; i++)
            {
                for (int j = 0; j <= Settings.Default.BoardWidth - winCount; j++)
                {
                    int k = 0;

                    while (k < winCount && gameBoard.IsPlayerCell(i + k, j + k, player))
                    {
                        k++;
                    }

                    if (k == winCount)
                    {
                        showWinCells(i, j, 0, 0, 1, 1);
                        return(true);
                    }
                }
            }

            for (int i = Settings.Default.BoardHeight - 1; i >= winCount - 1; i--)
            {
                for (int j = winCount - 1; j < Settings.Default.BoardWidth; j++)
                {
                    int k = 0;

                    while (k < winCount && gameBoard.IsPlayerCell(i - k, j - winCount + 1 + k, player))
                    {
                        k++;
                    }

                    if (k == winCount)
                    {
                        showWinCells(i, j, 0, 1 - winCount, -1, 1);
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #2
0
        string[] getLines(int i0, int j0, int radius, Player player, Board board)
        {
            string[] lines = new string[4];

            for (int i = i0 - radius; i <= i0 + radius; i++)
            {
                if (i < 0 || i >= n)
                {
                    continue;
                }

                if (i == i0)
                {
                    lines[0] += "0";
                }
                else if (board[i, j0].isFree())
                {
                    lines[0] += " ";
                }
                else if (board.IsPlayerCell(i, j0, player))
                {
                    lines[0] += "#";
                }
                else
                {
                    lines[0] += "@";
                }
            }

            for (int j = j0 - radius; j <= j0 + radius; j++)
            {
                if (j < 0 || j >= m)
                {
                    continue;
                }

                if (j == j0)
                {
                    lines[1] += "0";
                }
                else if (board[i0, j].isFree())
                {
                    lines[1] += " ";
                }
                else if (board.IsPlayerCell(i0, j, player))
                {
                    lines[1] += "#";
                }
                else
                {
                    lines[1] += "@";
                }
            }

            for (int k = -radius; k <= radius; k++)
            {
                if (i0 + k < 0 || i0 + k >= n || j0 + k < 0 || j0 + k >= m)
                {
                    continue;
                }

                if (k == 0)
                {
                    lines[2] += "0";
                }
                else if (board[i0 + k, j0 + k].isFree())
                {
                    lines[2] += " ";
                }
                else if (board.IsPlayerCell(i0 + k, j0 + k, player))
                {
                    lines[2] += "#";
                }
                else
                {
                    lines[2] += "@";
                }
            }

            for (int k = -radius; k <= radius; k++)
            {
                if (i0 + k < 0 || i0 + k >= n || j0 - k < 0 || j0 - k >= m)
                {
                    continue;
                }

                if (k == 0)
                {
                    lines[3] += "0";
                }
                else if (board[i0 + k, j0 - k].isFree())
                {
                    lines[3] += " ";
                }
                else if (board.IsPlayerCell(i0 + k, j0 - k, player))
                {
                    lines[3] += "#";
                }
                else
                {
                    lines[3] += "@";
                }
            }

            return(lines);
        }