| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3346 人关注过本帖
标题:C#版的俄罗斯方块方块
只看楼主 加入收藏
eastsnake
Rank: 1
等 级:新手上路
帖 子:127
专家分:0
注 册:2005-3-8
收藏
 问题点数:0 回复次数:22 
C#版的俄罗斯方块方块
C#版的俄罗斯方块方块,
右移时有时有bug,懒得修改了,算是增加难度
每到100分是,会有炸弹落下,
欢迎大家传播


————————————————————————————————
欢迎喜欢编写小游戏的网友交流,请教C#编写联机(网络)游戏,如何传送数据,如联机斗地主?
ZFY6ywgF.rar (8.51 KB) C#版的俄罗斯方块方块

搜索更多相关主题的帖子: 俄罗斯方块 
2005-04-04 11:28
eastsnake
Rank: 1
等 级:新手上路
帖 子:127
专家分:0
注 册:2005-3-8
收藏
得分:0 
源代码如下,没加注释,希望网友修正右移bug
————————————————————————————————
欢迎喜欢编写小游戏的网友交流,请教C#编写联机(网络)游戏,如何传送数据,如联机斗地主?

程序员是男孩,语言是女孩; 每个男孩都希望能交往更多的女孩; 但是却没有一个男孩真正了解一个女孩; 男孩总是不能专心一个女孩,而女孩却总是在变~
2005-04-05 10:33
eastsnake
Rank: 1
等 级:新手上路
帖 子:127
专家分:0
注 册:2005-3-8
收藏
得分:0 

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Drawing.Drawing2D;

namespace 俄罗斯方块 { /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Timer timer1; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private System.Windows.Forms.MenuItem menuItem3; private System.Windows.Forms.MenuItem menuItem4; private System.Windows.Forms.MenuItem menuItem5; private System.Windows.Forms.MenuItem menuItem6; private System.Windows.Forms.MenuItem menuItem7; private System.Windows.Forms.MenuItem menuItem8; private System.Windows.Forms.MenuItem menuItem9; private System.Windows.Forms.MenuItem menuItem10; private System.ComponentModel.IContainer components; private int ROWS=24,COLS=10,hight=15,x=10,y=60; private bool [,] blockmoveable=new bool[24,10]; private bool [,] blockfill=new bool[24,10]; private Color [,] blockcolor=new Color[24,10]; private System.Windows.Forms.Label label1; private bool pause=false; private System.Windows.Forms.MenuItem menuItem11; private System.Windows.Forms.Label label2; private int score=0;

public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent();

// // TOD 在 InitializeComponent 调用后添加任何构造函数代码 // }

/// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); }

#region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.menuItem3 = new System.Windows.Forms.MenuItem(); this.menuItem4 = new System.Windows.Forms.MenuItem(); this.menuItem5 = new System.Windows.Forms.MenuItem(); this.menuItem6 = new System.Windows.Forms.MenuItem(); this.menuItem7 = new System.Windows.Forms.MenuItem(); this.menuItem8 = new System.Windows.Forms.MenuItem(); this.menuItem9 = new System.Windows.Forms.MenuItem(); this.menuItem10 = new System.Windows.Forms.MenuItem(); this.label1 = new System.Windows.Forms.Label(); this.menuItem11 = new System.Windows.Forms.MenuItem(); this.label2 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // timer1 // this.timer1.Interval = 300; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // mainMenu1 // this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1, this.menuItem5, this.menuItem9}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2, this.menuItem3, this.menuItem4}); this.menuItem1.Text = "游戏"; // // menuItem2 // this.menuItem2.Index = 0; this.menuItem2.Text = "开始"; this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); // // menuItem3 // this.menuItem3.Enabled = false; this.menuItem3.Index = 1; this.menuItem3.Text = "暂停"; this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click); // // menuItem4 // this.menuItem4.Index = 2; this.menuItem4.Text = "退出"; this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click); // // menuItem5 // this.menuItem5.Index = 1; this.menuItem5.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem6, this.menuItem7, this.menuItem8}); this.menuItem5.Text = "等级"; // // menuItem6 // this.menuItem6.Index = 0; this.menuItem6.Text = "容易"; this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click); // // menuItem7 // this.menuItem7.Index = 1; this.menuItem7.Text = "一般"; // // menuItem8 // this.menuItem8.Index = 2; this.menuItem8.Text = "高级"; this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click); // // menuItem9 // this.menuItem9.Index = 2; this.menuItem9.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem10, this.menuItem11}); this.menuItem9.Text = "帮助"; // // menuItem10 // this.menuItem10.Index = 0; this.menuItem10.Text = "关于"; this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click); // // label1 // this.label1.Location = new System.Drawing.Point(216, 0); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(72, 16); this.label1.TabIndex = 0; this.label1.Text = "奖金"; // // menuItem11 // this.menuItem11.Index = 1; this.menuItem11.Text = "帮助"; this.menuItem11.Click += new System.EventHandler(this.menuItem11_Click); // // label2 // this.label2.Location = new System.Drawing.Point(200, 40); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(80, 104); this.label2.TabIndex = 1; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(296, 417); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.Menu = this.mainMenu1; this.Name = "Form1"; this.Text = "俄罗斯方块bug版"; this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown); this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false);

} #endregion

/// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); }

private void menuItem10_Click(object sender, System.EventArgs e) { MessageBox.Show("俄罗斯方块1.0\n作者:佘东"); }

private void Form1_Load(object sender, System.EventArgs e) { } private void InitializeBlock() { int i, j; for(i=0;i<ROWS;i++) for(j=0;j<COLS;j++) { blockmoveable[i,j]=false; blockfill[i,j]=false; blockcolor[i,j]=Color.Black; } } private void DrawBlock(int i,int j) { Graphics g=this.CreateGraphics(); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; Pen pen1=new Pen(Color.Black,2); SolidBrush bh=new SolidBrush(Color.Black); pen1.Color=blockcolor[i,j]; bh.Color=blockcolor[i,j]; // g.DrawRectangle(pen1,x+j*hight,y+i*hight,hight-3,hight-3); // g.FillRectangle(bh,x+j*hight,y+i*hight,hight-3,hight-3); g.DrawEllipse(pen1,x+j*hight,y+i*hight,hight-3,hight-3); g.FillEllipse(bh,x+j*hight,y+i*hight,hight-3,hight-3);

}


程序员是男孩,语言是女孩; 每个男孩都希望能交往更多的女孩; 但是却没有一个男孩真正了解一个女孩; 男孩总是不能专心一个女孩,而女孩却总是在变~
2005-04-05 10:35
eastsnake
Rank: 1
等 级:新手上路
帖 子:127
专家分:0
注 册:2005-3-8
收藏
得分:0 
private void EraseBlock(int i,int j) { Graphics g=this.CreateGraphics(); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; Pen pen1=new Pen(Color.Black,2); SolidBrush bh=new SolidBrush(Color.Black); g.DrawRectangle(pen1,x+j*hight,y+i*hight,hight-2,hight-2); g.FillRectangle(bh,x+j*hight,y+i*hight,hight-2,hight-2); // g.DrawEllipse(pen1,x+j*hight,y+i*hight,hight,hight); // g.FillEllipse(bh,x+j*hight,y+i*hight,hight,hight);

} private void menuItem2_Click(object sender, System.EventArgs e) { menuItem3.Enabled=true; if(pause) { pause=false; timer1.Enabled=true; return; } Graphics g=this.CreateGraphics(); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; Pen pen1=new Pen(Color.Black,2); SolidBrush bh=new SolidBrush(Color.Black);; g.DrawRectangle(pen1,x,y,hight*COLS,hight*ROWS); g.FillRectangle(bh,x,y,hight*COLS,hight*ROWS); InitializeBlock(); timer1.Enabled=true; CreatNewBlock(); }

private void timer1_Tick(object sender, System.EventArgs e) { bool flag; if(GameOver()) { timer1.Enabled=false; MessageBox.Show("请于明早九点至中国银行领取"+score.ToString()+"元奖金\n"+"密码为左上所示","打劫"); score=0; timer1.Interval=300; label1.Text="再玩一盘"; return; } flag=CanBlockMoveDown(); if(flag) { MoveBlockDown(); // KillFullLine(); } else { KillFullLine(); for(int i=0;i<ROWS;i++) for(int j=0;j<COLS;j++) blockmoveable[i,j]=false; CreatNewBlock(); } } private bool CanBlockMoveDown() { int i,j; bool Flag=true;

for(i = 2; i < ROWS; i++) for(j = 0; j < COLS; j++) { if (blockmoveable[i,j]==true) { if (i==ROWS-1) {Flag=false;break;} if( blockfill[i+1,j]==true&&blockmoveable[i+1,j]==false ) Flag=false; } // if(!Flag) break; } return (Flag); } private bool CanBlockMoveRight() { int i,j; bool Flag=true;

for(i = 2; i < ROWS; i++) for(j = 0; j < COLS; j++) { if (blockmoveable[i,j]==true) { if (j==COLS-1) {Flag=false;break;} if( blockfill[i,j+1]==true&&blockmoveable[i,j+1]==false ) Flag=false; } } return (Flag); } private bool CanBlockMoveLeft() { int i,j; bool Flag=true;

for(i = 2; i < ROWS; i++) for(j = 0; j < COLS; j++) { if (blockmoveable[i,j]==true) { if (j==0) {Flag=false;break;} if( blockfill[i,j-1]==true&&blockmoveable[i,j-1]==false ) Flag=false; } } return (Flag); } private void MoveBlockDown() { int i,j; for(i = ROWS-1;i >= 0;i--) for(j=0;j<COLS;j++) if ( blockmoveable[i,j]==true) { MoveBlockFromSrcToDes(i,j,i+1,j); DrawBlock(i+1,j); EraseBlock(i,j); } } private void MoveBlockRight() { int i,j; for(i = COLS-1;i >= 0;i--) for(j=2;j<ROWS;j++) if ( blockmoveable[j,i]==true) { MoveBlockFromSrcToDes(j,i,j,i+1); DrawBlock(j,i+1); EraseBlock(j,i); } } private void MoveBlockLeft() { int i,j; for(i = 0;i<COLS;i++) for(j=2;j<ROWS;j++) if ( blockmoveable[j,i]==true) { MoveBlockFromSrcToDes(j,i,j,i-1); DrawBlock(j,i-1); EraseBlock(j,i); } } private void MoveBlockFromSrcToDes (int SrcRow, int SrcCol, int DesRow, int DesCol) { blockfill[DesRow,DesCol]=blockfill[SrcRow,SrcCol]; blockmoveable[DesRow,DesCol]=blockmoveable[SrcRow,SrcCol]; blockcolor[DesRow,DesCol]=blockcolor[SrcRow,SrcCol]; blockfill[SrcRow,SrcCol]=false; blockmoveable[SrcRow,SrcCol]=false; blockcolor[SrcRow,SrcCol]=Color.Black; } private bool GameOver() { int i; bool Flag=false; for(i=0;i<COLS;i++) if (blockmoveable[4,i]==false &&blockfill[4,i]==true) Flag=true; return (Flag); } private void CreatNewBlock() { int key; Random rmd=new Random(); if(score/100>0&&score%100==0) { int i,j; for(key=0;key<5;key++) { i=rmd.Next(5); j=rmd.Next(5); blockcolor[i,j]=Color.BlueViolet;blockfill[i,j]=true;blockmoveable[i,j]=true;

} for(i=0;i<ROWS;i++) for(j=0;j<COLS;j++) DrawBlock(i,j); label2.Text="小子,有两手。看看这个怎么样!"; score+=10; return;

}

key=rmd.Next(7); label2.Text=""; switch ( key) { case 0: blockcolor[0,0]=Color.Yellow;blockfill[0,0]=true;blockmoveable[0,0]=true; blockcolor[0,1]=Color.Yellow;blockfill[0,1]=true;blockmoveable[0,1]=true; blockcolor[0,2]=Color.Yellow;blockfill[0,2]=true;blockmoveable[0,2]=true; blockcolor[0,3]=Color.Yellow;blockfill[0,3]=true;blockmoveable[0,3]=true; break; case 1: blockcolor[0,1]=Color.Blue;blockfill[0,1]=true;blockmoveable[0,1]=true; blockcolor[0,2]=Color.Blue;blockfill[0,2]=true;blockmoveable[0,2]=true; blockcolor[1,0]=Color.Blue;blockfill[1,0]=true;blockmoveable[1,0]=true; blockcolor[1,1]=Color.Blue;blockfill[1,1]=true;blockmoveable[1,1]=true; break; case 2: blockcolor[0,0]=Color.Red;blockfill[0,0]=true;blockmoveable[0,0]=true; blockcolor[0,1]=Color.Red;blockfill[0,1]=true;blockmoveable[0,1]=true; blockcolor[0,2]=Color.Red;blockfill[0,2]=true;blockmoveable[0,2]=true; blockcolor[1,0]=Color.Red;blockfill[1,0]=true;blockmoveable[1,0]=true; break; case 3: blockcolor[0,0]=Color.Green;blockfill[0,0]=true;blockmoveable[0,0]=true; blockcolor[0,1]=Color.Green;blockfill[0,1]=true;blockmoveable[0,1]=true; blockcolor[0,2]=Color.Green;blockfill[0,2]=true;blockmoveable[0,2]=true; blockcolor[1,1]=Color.Green;blockfill[1,1]=true;blockmoveable[1,1]=true; break; case 4: blockcolor[0,0]=Color.Brown;blockfill[0,0]=true;blockmoveable[0,0]=true; blockcolor[0,1]=Color.Brown;blockfill[0,1]=true;blockmoveable[0,1]=true; blockcolor[1,1]=Color.Brown;blockfill[1,1]=true;blockmoveable[1,1]=true; blockcolor[1,2]=Color.Brown;blockfill[1,2]=true;blockmoveable[1,2]=true;

break; case 5: blockcolor[0,0]=Color.Orange;blockfill[0,0]=true;blockmoveable[0,0]=true; blockcolor[0,1]=Color.Orange;blockfill[0,1]=true;blockmoveable[0,1]=true; blockcolor[1,0]=Color.Orange;blockfill[1,0]=true;blockmoveable[1,0]=true; blockcolor[1,1]=Color.Orange;blockfill[1,1]=true;blockmoveable[1,1]=true; break; case 6: blockcolor[0,0]=Color.Snow;blockfill[0,0]=true;blockmoveable[0,0]=true; blockcolor[0,1]=Color.Snow;blockfill[0,1]=true;blockmoveable[0,1]=true; blockcolor[0,2]=Color.Snow;blockfill[0,2]=true;blockmoveable[0,2]=true; blockcolor[1,2]=Color.Snow;blockfill[1,2]=true;blockmoveable[1,2]=true; break; } // for(int i=0;i<ROWS;i++) // for(int j=0;j<COLS;j++) // DrawBlock(i,j); } private void KillFullLine() { int i,j, m,n; bool Flag; for(i=ROWS-1;i >= 4;i--) //由游戏区的最下面一行从下至上扫描至游戏区的最上面一行 { Flag=true; //Flag的默认值为真,即假定所扫描的每一行都是可以消去的 for(j=0;j<COLS;j++) if ( blockfill[i,j] == false) //一旦发现某一个方块没有填满 Flag=false; //Flag就赋值为假.也就是说这一行是不能消去的.

if(Flag==true) { for(m=i;m >= 4;m--) //从这个可以消去的行开始,每一行的上面的一行方块由下往上全部向下移动一行 for(n=0;n<COLS;n++) //也就是每一行都被它上面的一行覆盖了. { //最终结果就是将当前行消去了. MoveBlockFromSrcToDes(m - 1, n, m, n);//先将每一行的上面一行一个方块一个方块向下移动

if(blockfill[m,n]==true) //移动后,如果这个方块是被填充了的则把这个方块画出来 DrawBlock(m,n); else EraseBlock(m,n); //没有填充的则要将它涂掉 } i++; //当前这行消去之后,它上面的行落到了它的位置.而这一行有可能也是可以消去的. //所以需要对当前行再一次进行判断,因此i的值不能改变. score+=10; if (score>=500&&timer1.Interval>200) timer1.Interval-=10; else if(score>=1000&&timer1.Interval>100) timer1.Interval-=10; else if(score>=2000&&timer1.Interval>10) timer1.Interval-=10; label1.Text="奖金:"+score.ToString(); for(int l1=4;l1<ROWS;l1++) for(int l2=0;l2<COLS;l2++) { blockmoveable[l1,l2]=false; DrawBlock(l1,l2); } } } } private int JudgeBlock() { int style=0; int i,j; for(i = 2; i < ROWS ; i++) { for(j = 0; j < COLS; j++) {if(blockmoveable[i,j]==true) { if(blockcolor[i,j]==Color.Yellow) style=0; if(blockcolor[i,j]==Color.Blue) style=1; if(blockcolor[i,j]==Color.Red) style=2; if(blockcolor[i,j]==Color.Green) style=3; if(blockcolor[i,j]==Color.Brown) style=4; if(blockcolor[i,j]==Color.Orange) style=5; if(blockcolor[i,j]==Color.Snow) style=6;

} } if (j < COLS) break; } return (style); } private void RotateStyleZero() { int i,j=0, m,n;

/* 这一段for循环的代码是用来寻找当前移动的积木最左上角的那个方块所对应的矩阵中的位置 */

for(i = 2 ; i < ROWS ; i++) { for(j = 0 ;j < COLS ;j++) { if (blockmoveable[i,j] == true) break;; } if ( j < COLS ) break; }

/* @ @ @ @ */ if(j<COLS-1) if(blockmoveable[i,j+1] == true) { /* 判定是否可以旋转积木 */

if (i == 2) return;

if (i >= ROWS -2) return ;

if (blockfill[i-1,j]==true || blockfill[i-1,j+1]==true) return ;

for(m= i + 1 ;m <= i + 2 ; m++) { for (n = j + 1; n <= j + 3; n++ ) { if ( blockfill[m,n] == true ) return ; } } /* 可以则旋转积木,同时更新画面 */

{ MoveBlockFromSrcToDes(i, j, i - 1,j + 1); DrawBlock(i-1,j+1); EraseBlock(i,j);

MoveBlockFromSrcToDes(i,j + 2,i + 1,j + 1); DrawBlock(i + 1, j + 1); EraseBlock(i,j + 2);

MoveBlockFromSrcToDes(i,j + 3, i + 2,j + 1); DrawBlock(i + 2, j + 1); EraseBlock(i,j + 3); } } /* @ @ @ @ */ else { /* 判定是否可以旋转积木 */

if (j >= COLS - 2) return ;

if (j == 0) return ;

if(i<ROWS-1) if (blockfill[i,j-1]==true || blockfill[i+1,j-1]==true) return ;

for(m= i + 1 ;m <= i + 3 ; m++) { for (n = j + 1; n <= j + 2; n++ ) { if ( blockfill[m,n] == true ) return ; } } /* 可以则旋转积木,同时更新画面 */

{ MoveBlockFromSrcToDes( i, j, i + 1,j - 1); DrawBlock(i + 1,j - 1); EraseBlock(i,j);

MoveBlockFromSrcToDes(i + 2,j ,i + 1,j + 1); DrawBlock(i + 1, j + 1); EraseBlock(i + 2,j);

MoveBlockFromSrcToDes( i + 3 , j , i + 1,j + 2); DrawBlock( i + 1, j + 2); EraseBlock( i + 3, j ); } } } private void RotateStyleOne() { int i, j=0; int m ;

/* 这一段for循环的代码是用来寻找当前移动积木的最左上角的那个方块所对应的矩阵中的的位置 */

for(i = 2 ; i < ROWS ; i++) { for(j = 0 ;j < COLS ;j++) { if (blockmoveable[i,j] == true) break; } if ( j < COLS ) break; } /* @ @ @ @ */ /* 当前积木所处的形态 */ if(j<COLS-1) if ( blockmoveable[i,j + 1] == true ) { if( i == 2) return;

if( i >= ROWS - 2) return;

if( blockfill[i - 1, j ] == true) return;

if( blockfill[i - 1,j + 1] == true) return;

if( blockfill[i + 1,j + 1] == true ) return;

for(m = j -1 ; m <= j + 1; m++) if (blockfill[i + 2, m ] == true ) return;

{ MoveBlockFromSrcToDes( i + 1, j ,i -1,j); DrawBlock( i - 1, j); EraseBlock(i + 1, j );

MoveBlockFromSrcToDes( i + 1, j - 1, i + 1,j + 1); DrawBlock( i + 1, j + 1); EraseBlock(i + 1, j - 1); } } /* @ @ @ @ */ /* 当前积木所处的形态 */ else { if ( i >= ROWS -3) return;

if ( j < 1 ) return;

if ( blockfill[ i ,j + 1] == true) return;

if ( blockfill[i + 2, j ] == true) return;

if ( blockfill[i + 2,j - 1] == true) return;

for(m = j ; m <= j + 1; m ++) if (blockfill[i + 3, m ] == true ) return;

{ MoveBlockFromSrcToDes( i, j, i + 2, j); DrawBlock( i + 2, j); EraseBlock( i, j);

MoveBlockFromSrcToDes( i + 2, j + 1, i + 2, j - 1); DrawBlock( i + 2,j - 1); EraseBlock(i + 2,j + 1); }

} }


程序员是男孩,语言是女孩; 每个男孩都希望能交往更多的女孩; 但是却没有一个男孩真正了解一个女孩; 男孩总是不能专心一个女孩,而女孩却总是在变~
2005-04-05 10:36
eastsnake
Rank: 1
等 级:新手上路
帖 子:127
专家分:0
注 册:2005-3-8
收藏
得分:0 

private void RotateStyleTwo() { int i, j=0; int m ; /* 这一段for循环的代码是用来寻找当前移动积木的最左上角的那个方块所对应的矩阵中的的位置 */ for(i = 2 ; i < ROWS ; i++) { for(j = 0 ;j < COLS ;j++) { if (blockfill[i,j] == true) break; } if (j < COLS) break; }

/* @ @ @ @ */ /*当前积木所处的形态*/ if(i<ROWS-1&&j<COLS-1)if( blockmoveable[i,j + 1] == true && blockmoveable[i + 1,j] == true ) { if ( i == 2 ) return; // 叛定积木是不是在最上面一行

if ( blockfill[i + 1,j + 1] == true) return;

if ( blockfill[i - 1,j + 1] == true || blockfill[i - 1,j + 2] == true) return;

if ( blockfill[i + 1,j + 1] == true || blockfill[i + 1,j + 2] == true) return; { MoveBlockFromSrcToDes( i, j, i + 1, j + 1); DrawBlock( i + 1, j + 1); EraseBlock( i, j);

MoveBlockFromSrcToDes(i, j + 2, i - 1, j + 1); DrawBlock( i - 1, j + 1); EraseBlock( i, j + 2);

MoveBlockFromSrcToDes( i + 1, j, i + 1, j + 2); DrawBlock( i + 1, j + 2); EraseBlock( i + 1, j ); } return ; } /* @ @ @ @ */ /*当前积木所处的形态*/ if(i<ROWS-1) if ( blockmoveable[i + 1, j ] == true && blockmoveable[i + 2, j ] == true) { if ( j == 0 ) return;

if ( blockfill[ i ,j - 1] == true || blockfill[i + 1,j - 1] == true ) return;

if ( blockfill[i + 3, j ] == true || blockfill[i + 1,j + 1] == true ) return;

if ( blockfill[ i ,j + 1] == true) return;

for(m = i; m < i + 3; m ++) if(j+2<COLS)if( blockfill[ m ,j + 2] == true) return;

{ MoveBlockFromSrcToDes( i, j, i + 1, j - 1); DrawBlock( i + 1, j - 1); EraseBlock( i, j);

MoveBlockFromSrcToDes( i + 2, j, i + 1, j + 1); DrawBlock ( i + 1, j + 1); EraseBlock( i + 2, j);

MoveBlockFromSrcToDes( i + 2, j + 1, i, j + 1); DrawBlock( i, j + 1); EraseBlock( i + 2, j + 1); } return ; } /* @ @ @ @ */ /*当前积木所处的形态*/ if(i<ROWS-1&&j>0) if ( blockmoveable[i + 1,j - 1] == true ) {

if( i == ROWS - 2) return ;

if(blockfill[ i ,j - 1] == true || blockfill[ i ,j - 2] == true ) return;

if(blockfill[i + 2,j - 1] == true || blockfill[i + 2,j - 2] == true ) return;

if(blockfill[ i ,j - 1] == true) return;

{ MoveBlockFromSrcToDes(i, j, i, j - 2); DrawBlock( i, j - 2); EraseBlock(i, j);

MoveBlockFromSrcToDes(i + 1, j, i, j - 1); DrawBlock( i, j - 1); EraseBlock(i + 1, j);

MoveBlockFromSrcToDes(i + 1, j - 2, i + 2, j - 1); DrawBlock( i + 2, j - 1); EraseBlock(i + 1, j - 2); } return ; }

/* @ @ @ @ */ /*当前积木所处的形态*/ if(i<ROWS-1&&j<COLS-1)if ( blockmoveable[ i ,j + 1]== true && blockmoveable[i + 1,j + 1] == true) { if( j == COLS - 2) return ;

if(blockfill[i + 1, j ] == true || blockfill[i + 2, j ] == true ) return;

if(blockfill[i + 1,j + 2] == true || blockfill[i + 2,j + 2] == true) return;

{ MoveBlockFromSrcToDes(i, j, i + 2, j); DrawBlock( i + 2, j); EraseBlock(i, j);

MoveBlockFromSrcToDes(i, j + 1, i + 1, j); DrawBlock( i + 1, j); EraseBlock(i, j + 1);

MoveBlockFromSrcToDes(i + 2, j + 1, i + 1, j + 2); DrawBlock( i + 1, j + 2); EraseBlock(i + 2, j + 1); } return; } } private void RotateStyleThree() { int i, j=0; /* 这一段for循环的代码是用来寻找当前移动积木的最左上角的那个方块所对应的矩阵中的的位置 */ for(i = 2 ; i < ROWS ; i++) { for(j = 0 ; j < COLS; j++) { if ( blockmoveable[i,j] == true ) break; } if ( j < COLS ) break; } /* @ @ @ @ */ /*当前积木所处的形态*/ if(j<COLS-2) if( blockmoveable[ i ,j + 1] == true && blockmoveable[ i ,j + 2] == true ) { if ( i == 2 ) return; /* 叛定积木是不是在最上面一行*/

if ( blockfill[i + 1, j ] == true ) return;

if ( blockfill[i + 1,j + 2] == true ) return;

if ( blockfill[i - 1,j + 1] == true || blockfill[i - 1,j + 2] == true) return;

{ MoveBlockFromSrcToDes(i, j, i - 1, j + 1); DrawBlock( i - 1, j + 1); EraseBlock(i, j);

} return ; } /* @ @ @ @ */ /*当前积木所处的形态*/ if(i<ROWS-2&&j<COLS-1)if ( blockmoveable[i + 1,j + 1] == true && blockmoveable[i + 2, j ] == true) { if ( j == 0 ) return;

if ( blockfill[ i ,j - 1] == true || blockfill[i + 1,j - 1] == true ) return;

if ( blockfill[i + 2,j + 1] == true ) return;

if ( blockfill[ i ,j + 1] == true) return;

{ MoveBlockFromSrcToDes(i + 2, j, i + 1, j - 1); DrawBlock( i + 1, j - 1); EraseBlock(i + 2, j); } return ; } /* @ @ @ @ */ /*当前积木所处的形态*/ if(i<ROWS-1&&j<COLS-1&&j>0) if ( blockmoveable[i + 1,j - 1] == true && blockmoveable[i + 1,j + 1] == true) { if( i == ROWS - 2) return ;

if(blockfill[ i ,j - 1] == true ) return;

if(blockfill[i + 2, j ] == true || blockfill[i + 2,j - 1]== true ) return;

if(blockfill[ i ,j + 1]== true) return;

{ MoveBlockFromSrcToDes(i + 1, j + 1, i + 2, j); DrawBlock( i + 2, j); EraseBlock(i + 1, j + 1);

} return ; } /* @ @ @ @ */ /*当前积木所处的形态*/ if(i<ROWS-2&&j>0) if ( blockmoveable[i + 2, j ] == true && blockmoveable[i + 1,j - 1] == true) { if( j == COLS - 1) return ;

if( blockfill[ i ,j - 1] == true ) return;

if(blockfill[i + 2,j - 1] == true ) return;

if(blockfill[i + 1,j + 1] == true || blockfill[i + 2,j + 1]== true) return;

{ MoveBlockFromSrcToDes(i, j, i + 1, j + 1); DrawBlock( i + 1, j + 1); EraseBlock(i, j); } return; } } private void RotateStyleFour() { int i, j=0;

/* 这一段for循环的代码是用来寻找当前移动的积木最左上角的那个方块所对应的矩阵中的的位置 */ for(i = 2 ; i < ROWS ; i++) { for(j = 0 ;j < COLS ;j++) { if (blockmoveable[i,j] == true) break; } if ( j < COLS ) break; }

/* @ @ @ @ */ /* 当前积木所处的形态 */ if(j<COLS-1) if ( blockmoveable[ i ,j + 1] == true ) { if( i == 2) return;

if( blockfill[i + 1, j ]== true ) return;

if( blockfill[ i ,j + 2] ==true ) return;

if( blockfill[i - 1,j + 2] == true ) return;

{ MoveBlockFromSrcToDes( i, j ,i, j + 2); DrawBlock( i, j + 2); EraseBlock(i, j );

MoveBlockFromSrcToDes( i + 1, j + 2, i - 1,j + 2); DrawBlock( i - 1, j + 2); EraseBlock(i + 1, j + 2); } } /* @ @ @ @ */ /* 当前积木所处的形态 */ else { if ( j == 1 ) return; if(i<ROWS-2) if ( blockfill[i + 2, j ]== true) return;

if(i<ROWS-2&&j>1)if ( blockfill[i + 2,j - 2] == true || blockfill[i + 1,j - 2]== true ) return;

{ MoveBlockFromSrcToDes( i, j, i + 2, j); DrawBlock( i + 2, j); EraseBlock( i, j);

MoveBlockFromSrcToDes( i + 1, j, i + 1, j - 2); DrawBlock( i + 1,j - 2); EraseBlock(i + 1,j ); }

} } private void RotateStyleSix() { int i, j=0; /* 这一段for循环的代码是用来寻找当前移动积木的最左上角的那个方块所对应的矩阵中的的位置 */

for(i = 2 ; i < ROWS ; i++) { for(j = 0 ;j < COLS ;j++) { if (blockmoveable[i,j] == true) break; } if (j < COLS ) break; } /* @ @ @ @ */ /*当前积木所处的形态*/ if(j<COLS-2)if( blockmoveable[ i ,j + 1] == true && blockmoveable[ i ,j + 2] == true ) { if ( i == 2 ) return; // 判定积木是不是在最上面一行

if ( blockfill[i + 1, j ] == true || blockfill[i + 1,j + 1] == true) return;

if ( blockfill[i - 1,j + 1] == true || blockfill[i - 1,j + 2] == true) return;

{ MoveBlockFromSrcToDes( i, j, i + 1, j + 1); DrawBlock( i + 1, j + 1); EraseBlock( i, j);

MoveBlockFromSrcToDes( i, j + 2, i - 1, j + 1); DrawBlock( i - 1, j + 1); EraseBlock(i, j + 2);

MoveBlockFromSrcToDes( i + 1, j + 2, i - 1, j + 2); DrawBlock( i - 1, j + 2); EraseBlock( i + 1, j + 2 ); } return ; } /* @ @ @ @ */ /*当前积木所处的形态*/ if(i<ROWS-1&&j<COLS-1)if ( blockmoveable[i + 1, j ] == true && blockmoveable[ i ,j + 1] == true) { if ( i == 2 ) return; if ( j == 0 ) return;

if ( blockfill[ i ,j - 1] == true || blockfill[i + 1,j - 1]== true ) return;

if ( blockfill[ i ,j - 1] == true) return;

if ( blockfill[i + 1,j + 1]== true || blockfill[i + 2,j + 1] ==true ) return;

{ MoveBlockFromSrcToDes( i, j, i + 1, j - 1); DrawBlock( i + 1, j - 1); EraseBlock( i, j);

MoveBlockFromSrcToDes( i, j + 1, i, j - 1); DrawBlock ( i, j - 1); EraseBlock( i, j + 1);

MoveBlockFromSrcToDes(i + 2, j , i + 1, j + 1); DrawBlock( i + 1, j + 1); EraseBlock(i + 2, j); } return ; } /* @ @ @ @ */ /*当前积木所处的形态*/ if(i<ROWS-1&&j<COLS-1)if ( blockmoveable[i + 1, j ] == true && blockmoveable[i + 1,j + 1] == true ) { if( i == ROWS - 2) return ;

if( blockfill[i + 2, j ]== true ) return;

if(blockfill[i + 2, j ] == true || blockfill[i + 2,j + 1] == true ) return;

if(blockfill[ i ,j + 1] ==true || blockfill[ i ,j + 2] == true) return;

{ MoveBlockFromSrcToDes(i, j, i + 2, j); DrawBlock( i + 2, j); EraseBlock(i, j);

MoveBlockFromSrcToDes(i + 1, j, i + 2, j + 1); DrawBlock( i + 2, j + 1); EraseBlock(i + 1, j);

MoveBlockFromSrcToDes(i + 1, j + 2, i , j + 1); DrawBlock( i, j + 1); EraseBlock(i + 1, j + 2); } return ; } /* @ @ @ @ */ /*当前积木所处的形态*/ if(i<ROWS-2&&j>0)if ( blockmoveable[i + 1, j ] == true && blockmoveable[i + 2,j - 1] == true) { if( j == COLS - 1) return ;

if(blockfill[ i ,j - 1]==true || blockfill[i + 1,j - 1] == true ) return;

if(blockfill[i + 2,j + 1]== true ) return;

if(blockfill[i + 2,j + 1] == true || blockfill[i + 1,j + 1] == true) return;

{ MoveBlockFromSrcToDes(i, j, i + 1, j - 1); DrawBlock( i + 1, j - 1); EraseBlock(i, j);

MoveBlockFromSrcToDes(i + 2, j - 1, i + 2, j + 1); DrawBlock( i + 2, j + 1); EraseBlock(i + 2, j - 1);

MoveBlockFromSrcToDes(i + 2, j, i + 1, j + 1); DrawBlock( i + 1, j + 1); EraseBlock(i + 2, j); } return; } }

private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { switch(e.KeyValue) { case 39:if(CanBlockMoveRight()) MoveBlockRight();break; case 37:if(CanBlockMoveLeft()) MoveBlockLeft();break; case 40:if(CanBlockMoveDown()) MoveBlockDown();break; case 38:switch(JudgeBlock()) { case 0: RotateStyleZero(); break; case 1: RotateStyleOne(); break; case 2: RotateStyleTwo(); break; case 3: RotateStyleThree(); break; case 4: RotateStyleFour(); break; case 5: break; case 6: RotateStyleSix(); break; } break;

} // KillFullLine(); }

private void menuItem4_Click(object sender, System.EventArgs e) { this.Close(); }

private void menuItem6_Click(object sender, System.EventArgs e) { timer1.Interval=200; }

private void menuItem8_Click(object sender, System.EventArgs e) { timer1.Interval=100; }

private void menuItem3_Click(object sender, System.EventArgs e) { timer1.Enabled=false; menuItem3.Enabled=false; pause=true; }

private void menuItem11_Click(object sender, System.EventArgs e) { MessageBox.Show("<-向左->向右,向上变行\n有时会有点小惊喜!","俄罗斯方块bug版");

} } }


程序员是男孩,语言是女孩; 每个男孩都希望能交往更多的女孩; 但是却没有一个男孩真正了解一个女孩; 男孩总是不能专心一个女孩,而女孩却总是在变~
2005-04-05 10:36
eastsnake
Rank: 1
等 级:新手上路
帖 子:127
专家分:0
注 册:2005-3-8
收藏
得分:0 
以上为完整源代码,毫无保留
欢迎大家加以修改传播
————————————————————————————————
欢迎喜欢编写小游戏的网友交流,请教C#编写联机(网络)游戏,如何传送数据,如联机斗地主?

程序员是男孩,语言是女孩; 每个男孩都希望能交往更多的女孩; 但是却没有一个男孩真正了解一个女孩; 男孩总是不能专心一个女孩,而女孩却总是在变~
2005-04-05 10:37
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
得分:0 
修复bug者上传代码及程序 奖励300分! 加油!!

2005-04-05 10:50
nyzfl
Rank: 1
等 级:新手上路
帖 子:278
专家分:0
注 册:2005-3-21
收藏
得分:0 
不错呀
可是我看不动呀

My-Blog地址:http://fenglin.
2005-04-05 11:43
loveys
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-4-8
收藏
得分:0 
呵呵,要认真研究才行
2005-04-08 22:27
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
请高手注释一下。
2005-04-09 02:43
快速回复:C#版的俄罗斯方块方块
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038539 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved