Exemple #1
0
        /// <summary>
        /// 指定の位置に指定のピースが存在出来るか同課を返します.
        /// </summary>
        /// <param name="row"></param>
        /// <param name="column"></param>
        /// <param name="piece"></param>
        /// <returns></returns>
        private bool IsSafeLocation(int row, int column, IPiece piece)
        {
            List <TetrisPoint> list = GetPointList(row, column, piece);

            //壁を越えているか検査
            if (IsOverRange(list))
            {
                return(false);
            }
            //全てのマスに対して
            for (int i = 0; i < RowCount; i++)
            {
                for (int j = 0; j < ColumnCount; j++)
                {
                    //そのマスが空or今検査しているピース自身なら無視
                    IPiece at = this[i, j];
                    if (at == null || at.Equals(piece))
                    {
                        continue;
                    }
                    //そのマスがもともと今検査しているピースの占有範囲内なら無視
                    bool self = false;
                    foreach (TetrisPoint elem in list)
                    {
                        if (elem.Row == i && elem.Column == j)
                        {
                            self = true;
                            break;
                        }
                    }
                    if (self)
                    {
                        continue;
                    }
                    //そのピースの全ての占有範囲に対して
                    for (int otherWidth = 0; otherWidth < at.Width; otherWidth++)
                    {
                        for (int otherHeight = 0; otherHeight < at.Height; otherHeight++)
                        {
                            int otherRealRow    = otherHeight + i;
                            int otherRealColumn = otherWidth + j;
                            if (!at.IsVisible(i, j, otherRealRow, otherRealColumn))
                            {
                                continue;
                            }
                            //他のピースの占有範囲と重複するなら
                            foreach (TetrisPoint elem in list)
                            {
                                if (elem.Row == otherRealRow &&
                                    elem.Column == otherRealColumn)
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }
Exemple #2
0
        public bool IsPlaceable(int row, int column, IPiece piece)
        {
            List <TetrisPoint> list = GetPointList(row, column, piece);

            //壁を越えているか検査
            if (IsOverRange(list))
            {
                return(false);
            }
            //全てのマスに対して
            for (int i = 0; i < RowCount; i++)
            {
                for (int j = 0; j < ColumnCount; j++)
                {
                    //そのマスが空or今検査しているピース自身なら無視
                    IPiece at = this[i, j];
                    if (at == null || at.Equals(piece))
                    {
                        continue;
                    }
                    //そこにピースがあるので無理
                    if (i == row && j == column)
                    {
                        return(false);
                    }
                    //そのピースの全ての占有範囲に対して
                    for (int otherWidth = 0; otherWidth < at.Width; otherWidth++)
                    {
                        for (int otherHeight = 0; otherHeight < at.Height; otherHeight++)
                        {
                            int otherRealRow    = otherHeight + i;
                            int otherRealColumn = otherWidth + j;
                            if (!at.IsVisible(i, j, otherRealRow, otherRealColumn))
                            {
                                continue;
                            }
                            if (IsOverRange(otherRealRow, otherRealColumn))
                            {
                                return(false);
                            }
                            if (list.Contains(new TetrisPoint(otherRealRow, otherRealColumn)))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            return(true);
        }