/// <summary> /// Check whether current shape can move to speicified direction /// </summary> /// <param name="theDirection">the specified direct</param> /// <returns>ture if can, otherwise false</returns> protected bool CanMove(EnumMoving theDirection) { if (null == m_curShape) return false; Block[] blocks = m_curShape.Blocks; if (null == blocks) return false; switch (theDirection) { case EnumMoving.Left: for (int i = 0; i < blocks.Length; i++) { if (EnumBlockType.Blank != m_Cells[blocks[i].Y, blocks[i].X - 1].Type) return false; } break; case EnumMoving.Right: for (int i = 0; i < blocks.Length; i++) { if (EnumBlockType.Blank != m_Cells[blocks[i].Y, blocks[i].X + 1].Type) return false; } break; case EnumMoving.Down: for (int i = 0; i < blocks.Length; i++) { if (EnumBlockType.Blank != m_Cells[blocks[i].Y + 1, blocks[i].X].Type) return false; } break; case EnumMoving.Rotate: return CanRotate(); default: break; } return true; }
public ShapeMovingEventArgs(EnumMoving direction) { m_Direction = direction; }
/// <summary> /// move current shape. /// </summary> /// <param name="theDirection">the moving direction</param> public bool MoveCurShape(EnumMoving theDirection) { if (this.Status != EnumGameStatus.Running) return false; if (EnumMoving.DirectDown == theDirection) { while (this.MoveCurShape(EnumMoving.Down)) { } return true; } if (this.CanMove(theDirection)) { m_curShape.Move(theDirection); } else if (EnumMoving.Down == theDirection) { // can not be moving down if (null != m_curShape) { DestroyCurShape(); CheckLines(); //if (null != this.NextShapeRequested) // this.NextShapeRequested(this, new EventArgs()); } if (Defeated()) { this.Status = EnumGameStatus.Defeated; RePaint(); } else CreateNextShape(); return false; } return true; }