예제 #1
0
 public bool CanTurnRight(int row, int column, IPiece piece)
 {
     piece.RightRotate();
     try
     {
         return(IsSafeLocation(row, column, piece));
     } finally
     {
         piece.LeftRotate();
     }
 }
예제 #2
0
        private void Control()
        {
            int      sRow     = SelectionModel.Row;
            int      sCol     = SelectionModel.Column;
            bool     move     = false;
            IPiece   sPiece   = SelectionModel.Piece;
            Detector detector = Detector.GetInstance();

            //キー入力で移動
            if (detector.IsDetect(Handle.LEFT))
            {
                move = true;
                SelectionModel.Column--;
            }
            else if (detector.IsDetect(Handle.RIGHT))
            {
                move = true;
                SelectionModel.Column++;
            }
            else if (detector.IsDetect(Handle.DOWN))
            {
                if (Model.IsPlaceable(SelectionModel.Row + 1, SelectionModel.Column, sPiece))
                {
                    move = true;
                    SelectionModel.Row++;
                }
            }
            else if (detector.IsDetect(Keys.Enter))
            {
                sPiece.RightRotate();
            }
            //移動を適用
            if (!move)
            {
                return;
            }
            SelectionModel.Row    = Math.Min(Model.RowCount - sPiece.Height, Math.Max(0, SelectionModel.Row));
            SelectionModel.Column = Math.Min(Model.ColumnCount - sPiece.Width, Math.Max(0, SelectionModel.Column));
            if (Model.IsPlaceable(SelectionModel.Row, SelectionModel.Column, SelectionModel.Piece))
            {
                Model[sRow, sCol] = null;
                Model[SelectionModel.Row, SelectionModel.Column] = SelectionModel.Piece;
            }
            else
            {
                SelectionModel.Row    = sRow;
                SelectionModel.Column = sCol;
            }
        }