/// <summary> /// 向下移动 /// </summary> public void MoveDown() { /* 检测碰撞 */ int length = gameStage.stageBoxs.GetLength(0); if (position.Y / size + BoxUtil.getBottom(boxData) < length && BoxUtil.CheckBoxByBottom(this, gameStage.stageBoxs)) { Vector2 pstion = position; pstion.Y += size; position = pstion; } else { /* 将方块放进游戏舞台里并重新落下方块 */ gameStage.AddDropBox(this); DropNewBox(nextBox); /* 判断是否满足消除的条件 */ Queue rows = gameStage.GetFullRows(); if (rows.Count > 0) { gameStage.DeleteRowByRows(rows); } } }
/// <summary> /// 重新加载位置 /// </summary> public void ReloadPosition() { Vector2 p = position; p.X = 3 * size; p.Y = 0 - BoxUtil.getTop(boxData) * size; position = p; }
/// <summary> /// 向左移动 /// </summary> public void MoveLeft() { /* 检测碰撞 */ if (position.X / size > -BoxUtil.getLeft(boxData) && BoxUtil.CheckBoxByLeft(this, gameStage.stageBoxs)) { Vector2 pstion = position; pstion.X -= size; position = pstion; } }
/// <summary> /// 判断是否游戏结束 /// </summary> private void CheckGameOver() { /* 检测碰撞 */ int length = gameStage.stageBoxs.GetLength(0); if (!(position.Y / size + BoxUtil.getBottom(boxData) < length && BoxUtil.CheckBoxByBottom(this, gameStage.stageBoxs))) { Controller.IsGameOver = true; } }
/// <summary> /// 向右移动 /// </summary> public void MoveRight() { /* 检测碰撞 */ int length = gameStage.stageBoxs.GetLength(1); if (position.X / size + BoxUtil.getRight(boxData) < length && BoxUtil.CheckBoxByRight(this, gameStage.stageBoxs)) { Vector2 pstion = position; pstion.X += size; position = pstion; } }