Пример #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;
 }