Beispiel #1
0
 /// <summary>
 /// 移动元素
 /// </summary>
 /// <param name="container"></param>
 /// <param name="element"></param>
 /// <param name="direction"></param>
 /// <returns></returns>
 public static TetrisElement move(TetrisContainer container, TetrisElement element, TetrisDirection direction)
 {
     return(container.change(element, direction));
 }
Beispiel #2
0
        /// <summary>
        /// 状态发生改变
        /// </summary>
        /// <param name="element"></param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public TetrisElement change(TetrisElement element, TetrisDirection direction)
        {
            TetrisElement tmp = null;

            //判断不同的方向
            switch (direction)
            {
            case TetrisDirection.DEFAULT:
                //如果可以向下移动
                if (checkDefault(element))
                {
                    //向下移动一个元素
                    element.move(element.location.X, element.location.Y + 1);
                    tmp = element;
                }
                else
                {
                    //如果不可以向下移动,则更新容器
                    updateTetris(element);
                    tmp = null;
                }

                break;

            case TetrisDirection.DOWN:
                break;

            case TetrisDirection.UP:
                break;

            case TetrisDirection.LEFT:
                if (checkLeft(element))
                {
                    //判断是否可以向左移动
                    //向下移动一个元素
                    element.move(element.location.X - 1, element.location.Y);
                    tmp = element;
                }
                break;

            case TetrisDirection.RIGHT:
                if (checkRight(element))
                {
                    //判断是否可以右左移动
                    //向下移动一个元素
                    element.move(element.location.X + 1, element.location.Y);
                    tmp = element;
                }
                break;
            }

            //局部变更
            if (onPartialChanged != null)
            {
                Point   location = element.location;
                Point[] content  = new Point[4];
                element.content.CopyTo(content, 0);

                for (int i = 0; i < content.Length; i++)
                {
                    content[i].X = location.X + content[i].X;
                    content[i].Y = location.Y + content[i].Y;
                }
                onPartialChanged(location, content, direction);
            }

            //判断游戏是否结束
            if (onCompleted != null)
            {
                if (checkComplete())
                {
                    onCompleted();
                }
            }

            //全部变更
            if (onFullChanged != null)
            {
                //判断是是否有权为1的行,如果有则消掉
                int[] rows = checkAllTetris();
                if (rows.Length > 0)
                {
                    updateAllTetris(rows);//消掉行
                    onFullChanged(tetris);
                }
            }

            return(tmp);
        }