コード例 #1
0
        private bool CheckHorizontalLines(MyTable table)
        {
            bool win = true;

            for (int i = 0; i < table.Rows; i++)
            {
                win = true;
                CellStatus cellStatus = table[i, 0].Status;

                if (cellStatus == CellStatus.Empty)
                {
                    win = false;
                    continue;
                }

                for (int j = 1; j < table.Columns; j++)
                {
                    if (cellStatus != table[i, j].Status)
                    {
                        win = false;
                        break;
                    }
                }

                if (win)
                {
                    return(true);
                }
            }
            return(win);
        }
コード例 #2
0
        private bool CheckDiagonal(MyTable table)
        {
            bool win = true;

            CellStatus cellStatus = table [0, 0].Status;

            if (cellStatus != CellStatus.Empty)
            {
                for (int i = 1; i < table.Rows; i++)
                {
                    if (cellStatus != table[i, i].Status)
                    {
                        win = false;
                        break;
                    }
                }
                if (win)
                {
                    return(true);
                }
            }
            else
            {
                win = false;
            }
            if (win)
            {
                return(true);
            }

            win        = true;
            cellStatus = table[0, table.Columns - 1].Status;
            if (cellStatus != CellStatus.Empty)
            {
                for (int i = 1; i < table.Rows; i++)
                {
                    if (cellStatus != table[i, (table.Columns - 1) - i].Status)
                    {
                        win = false;
                        break;
                    }
                }
                if (win)
                {
                    return(true);
                }
            }
            else
            {
                win = false;
            }
            return(win);
        }
コード例 #3
0
        private bool IsDraw(MyTable table)
        {
            bool result = true;

            foreach (Cell cell in table)
            {
                if (cell.Status == CellStatus.Empty)
                {
                    result = false;
                    break;
                }
            }
            return(result);
        }
コード例 #4
0
 private bool IsGameOver(MyTable table)
 {
     return(CheckHorizontalLines(table) || CheckVerticallLines(table) || CheckDiagonal(table));
 }