예제 #1
0
        // Public Methods
        public bool AddFigure(AbstractFigure figure)
        {
            if (IsFull() || IsRunning())
                return false;

            currentFigure = figure;
            x = (Const.NUM_COLS / 2) - 1;
            y = 0;

            if(! canFit(currentFigure, x, y)){
                full = true;
                currentFigure = null;
                return false;
            }

            paintCurrentFigure( true );
            return true;
        }
예제 #2
0
        public void FallDown()
        {
            if( ! IsRunning() ) return;

            paintCurrentFigure ( false );

            for (int newY = y + 1; newY <= Const.NUM_ROWS; ++newY){
                if (! canFit ( currentFigure, x, newY )){
                    y = newY - 1;
                    paintCurrentFigure ( true );
                    currentFigure = null;
                    return;
                }
            }

            throw new ApplicationException();
        }
예제 #3
0
        public void StepDown()
        {
            if ( ! IsRunning() ) return;

            paintCurrentFigure ( false );

            if ( canFit ( currentFigure, x, y + 1 ) ){
                y++;
                paintCurrentFigure(true);
            }else{
                paintCurrentFigure(true);
                currentFigure = null;
            }
        }
예제 #4
0
        private bool canFit(AbstractFigure figure, int cx, int cy)
        {
            if(figure == null) return false;

            bool[][] fig = figure.GetModel();
            int w = figure.GetWidth();
            int h = figure.GetHeight();

            if(cx < 0 || cy < 0 || cx + w - 1 >= Const.NUM_COLS || cy + h - 1 >= Const.NUM_ROWS) return false;

            for(int dx = 0; dx < w; ++dx)
                for(int dy = 0; dy < h; ++dy)
                    if(fig[dx][dy] && field[cx + dx][cy + dy] != Const.UNUSED_COLOR)
                        return false;

            return true;
        }
예제 #5
0
 public static AbstractFigure NewFigure()
 {
     AbstractFigure ret = nextFigure;
     nextFigure = GetFigure();
     return ret;
 }