/// <summary> /// Type 01 /// OOOO /// </summary> /// <returns></returns> protected Shape CreateShape_01() { Shape shape = new Shape(); Block[] blocks = new Block[4]; int x, y; x = m_nInitX; y = m_nInitY; blocks[0] = new Block(x++, y); blocks[1] = new Block(x++, y); blocks[2] = new Block(x++, y); blocks[3] = new Block(x, y); shape.Blocks = blocks; return shape; }
/// <summary> /// Draw a block /// </summary> /// <param name="graph"></param> /// <param name="block">block instance</param> protected void DrawBlock(Graphics graph, Block block, int imageIndex) { Image blockImage; string sResName; //if (block.GameType == EnumBlockType.Blank) // return; sResName = block.Type.ToString().ToLower(); #if DEBUG // TODO: remove me if (m_skin.SkinPath.Contains("web20")) imageIndex = 1; #endif blockImage = m_skin.GetImage(sResName, imageIndex); if (null != blockImage) graph.DrawImage(blockImage, block.X * BlockWidth, block.Y * BlockHeight, BlockWidth, BlockHeight); }
/// <summary> /// Check whether current block can rotate. /// </summary> /// <returns>true if can, otherwise false</returns> protected bool CanRotate() { if (null == m_curShape) return false; // the blocks of current shape Block[] oriBlocks = m_curShape.Blocks; if (oriBlocks.Length <= 0) return false; // temp blocks Block[] tarBlocks = new Block[oriBlocks.Length]; Block origin = oriBlocks[(int)(oriBlocks.Length + 1) / 2]; // rotated temp blocks int x, y; for (int i = 0; i < tarBlocks.Length; i++) { x = oriBlocks[i].Y - origin.Y + origin.X; y = origin.X - oriBlocks[i].X + origin.Y; tarBlocks[i] = new Block(x, y); } // check if it's valid. for (int i = 0; i < tarBlocks.Length; i++) { if (EnumBlockType.Blank != m_Cells[tarBlocks[i].Y, tarBlocks[i].X].Type) return false; } return true; }
/// <summary> /// Draw a block /// </summary> /// <param name="graph"></param> /// <param name="block">block instance</param> protected void DrawBlock(Graphics graph, Block block) { DrawBlock(graph, block, 0); }
public void Initialize() { m_Cells = new Block[Rows, Columns]; for (int i = 0; i < Rows; i++) { for (int j = 0; j < Columns; j++) { m_Cells[i, j] = new Block(j, i, EnumBlockType.Blank); if (i == 0 || i == Rows - 1 || j == 0 || j == Columns - 1) { m_Cells[i, j].Type = EnumBlockType.Wall; } } } for (int i = 2; i < Columns - 1; i++) { m_Cells[Rows - 2, i].Type = EnumBlockType.RoadBlock; } this.Size = new Size(BlockWidth * Columns, BlockHeight * Rows); this.TabStop = false; this.m_curShape = null; this.m_nextShape = null; this.Status = EnumGameStatus.Ready; this.RePaint(); CreateNextShape(); }