欢迎来到天天文库
浏览记录
ID:9383310
大小:102.50 KB
页数:18页
时间:2018-04-29
《俄罗斯方块c 实现代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、俄罗斯方块C#代码实现usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.ComponentModel;usingSystem.Drawing;namespaceERSBlock.Controls{publicclassBlockPanel:ContainerControl{#region私有成员privateGraphicsGra{get{returnthis.CreateGraphics()
2、;}}privateintrowCount;privateBlockblock;privateTimertmDown;privateintcolumnCount;privateBlockCell[,]cells;#endregion#region私有接口privateIDrawCelldrawer;#endregion#region公有属性publicintRowCount{get{returnrowCount;}set{rowCount=value;this.Height=rowCount*CellWidth;}}publicintColumnCount{get{ret
3、urncolumnCount;}set{columnCount=value;this.Width=columnCount*CellWidth;}}publicintCellWidth{get;set;}publicintDelay{get;set;}#endregionpublicBlockPanel(){Initial();}#region初始化方法privatevoidInitial(){//this.BorderStyle=BorderStyle.FixedSingle;this.BackColor=Color.Gray;tmDown=newTimer();tmDo
4、wn.Interval=1000;tmDown.Tick+=newEventHandler(tmDown_Tick);Paint+=newPaintEventHandler(BlockPanel_Paint);drawer=Factory.CreateIDrawCell();}#endregion#region画//////把一个行的Cell重画一下//////privatevoidDrawLine(intindex){ClearLine(index);for(inti=0;i5、olumnCount;i++){DrawCell(i,index);}}//////重画一个Cell/////////privatevoidDrawCell(intx,inty){BlockCellcell=cells[x,y];if(cell!=null){cell.X=x;cell.Y=y;drawer.DrawCell(Gra,cell,CellWidth);}else{Gra.FillRectangle(newPen(BackColor6、).Brush,x*CellWidth,y*CellWidth,CellWidth,CellWidth);}}//////清除一行//////privatevoidClearLine(intindex){Gra.FillRectangle(newPen(BackColor).Brush,0,index*CellWidth,columnCount*CellWidth,CellWidth);}privatevoidClearBlock(){foreach(variteminblock.7、Cells){Gra.FillRectangle(newPen(BackColor).Brush,item.X*CellWidth,item.Y*CellWidth,CellWidth,CellWidth);}}privatevoidShowBlock(){foreach(variteminblock.Cells){Penpen=newPen(item.BackColor);drawer.DrawCell(Gra,item,CellWidth);//Gra.FillRectangle(pen.Brush,item.X*Cell
5、olumnCount;i++){DrawCell(i,index);}}//////重画一个Cell/////////privatevoidDrawCell(intx,inty){BlockCellcell=cells[x,y];if(cell!=null){cell.X=x;cell.Y=y;drawer.DrawCell(Gra,cell,CellWidth);}else{Gra.FillRectangle(newPen(BackColor
6、).Brush,x*CellWidth,y*CellWidth,CellWidth,CellWidth);}}//////清除一行//////privatevoidClearLine(intindex){Gra.FillRectangle(newPen(BackColor).Brush,0,index*CellWidth,columnCount*CellWidth,CellWidth);}privatevoidClearBlock(){foreach(variteminblock.
7、Cells){Gra.FillRectangle(newPen(BackColor).Brush,item.X*CellWidth,item.Y*CellWidth,CellWidth,CellWidth);}}privatevoidShowBlock(){foreach(variteminblock.Cells){Penpen=newPen(item.BackColor);drawer.DrawCell(Gra,item,CellWidth);//Gra.FillRectangle(pen.Brush,item.X*Cell
此文档下载收益归作者所有