コード例 #1
0
 /// <summary>
 /// 将方块添加进游戏舞台
 /// </summary>
 /// <param name="dropBox"></param>
 public void AddDropBox(DropBox dropBox)
 {
     int[,] boxData = dropBox.boxData;
     for (int i = 0; i < boxData.GetLength(0); i++) {
         for (int j = 0; j < boxData.GetLength(1); j++) {
             if (boxData[i, j] == 1) {
                 DropedBox db = new DropedBox(game);
                 db.color = dropBox.color;
                 db.Background = dropBox.Background;
                 db.position = new Vector2(dropBox.position.X + j * DropBox.size,
                     dropBox.position.Y + i * DropBox.size);
                 stageBoxs[(int)dropBox.position.Y / DropBox.size + i,
                     (int)dropBox.position.X / DropBox.size + j] = db;
             }
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// 下落时检查方块碰撞
 /// </summary>
 /// <returns></returns>
 public static bool CheckBoxByBottom(DropBox box, DropedBox[,] stageBoxs)
 {
     /* 检测方块碰撞 */
     for (int i = 0, c = 0; i < box.boxData.GetLength(0) && c < 4; i++) {
         for (int j = box.boxData.GetLength(1) - 1; j >= 0; j--) {
             if (box.boxData[j, i] == 1) {
                 c++;
                 if ((int)box.position.Y / DropBox.size + j + 1 < stageBoxs.GetLength(0)) {
                     if (stageBoxs[(int)box.position.Y / DropBox.size + j + 1,
                                 (int)box.position.X / DropBox.size + i] != null) {
                         return false;
                     }
                 }
             }
         }
     }
     return true;
 }
コード例 #3
0
 /// <summary>
 /// 右移时检查方块碰撞
 /// </summary>
 /// <returns></returns>
 public static bool CheckBoxByLeft(DropBox box, DropedBox[,] stageBoxs)
 {
     /* 检测方块碰撞 */
     for (int i = 0, c = 0; i < box.boxData.GetLength(0) && c < 4; i++)
     {
         for (int j = box.boxData.GetLength(1) - 1; j >= 0; j--)
         {
             if (box.boxData[j, i] == 1)
             {
                 c++;
                 if ((int)box.position.X / DropBox.size + i - 1 > 0)
                 {
                     if (stageBoxs[(int)box.position.Y / DropBox.size + j,
                                   (int)box.position.X / DropBox.size + i - 1] != null)
                     {
                         return(false);
                     }
                 }
             }
         }
     }
     return(true);
 }
コード例 #4
0
        /// <summary>
        /// 初始化对象
        /// </summary>
        public void InitObjects()
        {
            Rectangle clientBounds = tetris.Window.ClientBounds;

            BigStage.AlphaChange = AlphaChange;
            bigStage = new BigStage(tetris);

            /* 在整个场景的中间绘制游戏场景 */
            DropBox.size = boxSize;
            gameStage = new GameStage(new Rectangle((clientBounds.Width - gameStageWidth) / 2,
                (clientBounds.Height - gameStageHeight) / 2, gameStageWidth, gameStageHeight), tetris);

            pointStage = new PointStage(tetris);

            dropBox = new DropBox(tetris);

            input = new InputState();

            table = new Hashtable();

            DropBoxThread = new Thread(new ThreadStart(dropBox.AutoDrop));

            lib = new ResourcesLIB(tetris.Content);
        }