Пример #1
0
        //TODO :
        //animateするならblock単位に動かす必要あり
        public void Move(Direction direction, Stage parent, bool forceF = false)
        {
            if (!forceF && !CanMove(direction, parent))
                return;

            Point movedP = m_trans.LeftTop;
            switch (direction)
            {
                case Direction.Bottom:
                    Update();
                    ++movedP.Y;
                    break;

                case Direction.Left:
                    --movedP.X;
                    break;

                case Direction.Right:
                    ++movedP.X;
                    break;

                case Direction.Up:
                    --movedP.Y;
                    break;
            }

            m_trans.LeftTop = movedP;
        }
Пример #2
0
        public bool CanMove(Direction direction, Stage parent)
        {
            //
            Piece copyedActivePiece = (Piece)this.Clone();
            copyedActivePiece.Move(direction, parent, forceF:true);

            //壁と衝突?
            if (copyedActivePiece.X < 0)
                return false;
            //123456789101
            //□□□□□□□□□■□
            //□□□□□□□□■■■
            if (copyedActivePiece.X + copyedActivePiece.Width > parent.Width)
                return false;

            if (copyedActivePiece.Y < 0)
                return false;
            if (copyedActivePiece.Y + copyedActivePiece.Height > parent.Height)
                return false;

            //他のピースと衝突?

            bool[,] lockedLayer = new bool[parent.Height, parent.Width];
            bool[,] activeLayer = new bool[parent.Height, parent.Width];
            Piece p;

            for (int y = 0; y < parent.Width; ++y)
            {
                for (int x = 0; x < parent.Width; ++x)
                {
                    lockedLayer[y, x] = false;
                    activeLayer[y, x] = false;
                }
            }
            for (int i = 0; i < parent.Pieces.Count ; ++i)
            {
                p = parent.Pieces[i];

                if (p.X == this.X && p.Y == this.Y)
                    continue;

                for (int y = p.Y; y < p.Y + p.Height; ++y)
                {
                    for (int x = p.X; x < p.X + p.Width; ++x)
                    {
                        lockedLayer[y, x] = p[y - p.Y, x - p.X];
                    }
                }

            }

            p = copyedActivePiece;
            for (int y = p.Y; y < p.Y + p.Height; ++y)
            {
                for (int x = p.X; x < p.X + p.Width; ++x)
                {
                    activeLayer[y, x] = p[y - p.Y, x - p.X];
                }
            }

            return !Util.HitTest(lockedLayer, activeLayer);
        }
Пример #3
0
 public Tetris(int stage_Width, int stage_Height)
 {
     m_stage = new Stage(stage_Width, stage_Height);
     m_status = TetrisStatus.NOTSTART;
 }
Пример #4
0
 public TetrisEventArgs(TetrisStatus status, Stage stage)
 {
     m_status = status;
     m_stage = stage;
 }
Пример #5
0
 public Tetris(int stage_Width, int stage_Height)
 {
     m_stage  = new Stage(stage_Width, stage_Height);
     m_status = TetrisStatus.NOTSTART;
 }
Пример #6
0
 public TetrisEventArgs(TetrisStatus status, Stage stage)
 {
     m_status = status;
     m_stage  = stage;
 }