namespace game
{
public partial class Form1 : Form
{
int xdd1 = 0;//定义lbl1图片x方向的增量
int ydd1 = 0;//定义lbl1图片y方向的增量
int xdd2 = 0;//定义lbl2图片x方向的增量
int ydd2 = 0;//定义lbl2图片y方向的增量
int xdd3 = 0;//定义lbl3图片x方向的增量
int ydd3 = 0;//定义lbl3图片y方向的增量
int xdd4 = 0;//定义lbl4图片x方向的增量
int ydd4 = 0;//定义lbl4图片y方向的增量
int times = 0;//声明一个变量 public Form1( )
{
InitializeComponent();
} //鼠标按下事件
Point p = new Point();//用对象表示鼠标的坐标
Point cp = new Point();//用对象表示图片的坐标
private void lblclick_MouseDown(object sender, MouseEventArgs e)
{
p.X = Cursor.Position.X;//鼠标的横坐标
p.Y = Cursor.Position.Y;//鼠标的纵坐标
cp.X = lblclick.Location.X;//lblclick的横坐标
cp.Y = lblclick.Location.Y;//lblclick的纵坐标
timer1.Enabled = true;//启用timer
} //黄图片随鼠标移动而移动
private void lblclick_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button.Equals(MouseButtons.Left)) // 点左键移动
{
lblclick.Location = new Point(Cursor.Position.X - (p.X - cp.X), Cursor.Position.Y - (p.Y - cp.Y));
}
}
//timer事件
int mod = 1;
private void timer1_Tick(object sender, EventArgs e)
{
times++;
if (times % mod == 0)
{
Random ran = new Random();//产生随机数
xdd1 = ran.Next(20) ;
ydd1 = ran.Next(40) ;
xdd2 = ran.Next(-20,-10) ;
ydd2 = ran.Next(20) ;
xdd3 = ran.Next(30) ;
ydd3 = ran.Next(-30,-10) ;
xdd4 = ran.Next(-40,-10) ;
ydd4 = ran.Next(-30,-10) ; mod = ran.Next(100,400) ;
}
//四个木块自己移动
if (lbl1.Location.X <= 1)
{
xdd1 = 10;
ydd1 = 0;
}
if (lbl1.Location.Y <= 1)
{
xdd1 = 0;
ydd1 = 2;
}
if (lbl1.Location.X >= 351)
{
xdd1 = -5;
ydd1 = 0;
}
if (lbl1.Location.Y >= 358)
{
xdd1 = 0;
ydd1 = -2;
}
lbl1.Location = new Point(lbl1.Location.X + xdd1, lbl1.Location.Y + ydd1);
if (lbl2.Location.X <= 1)
{
xdd2 = 7;
ydd2 = 0;
}
if (lbl2.Location.Y <= 1)
{
xdd2 = 0;
ydd2 = 6;
}
if (lbl2.Location.X >= 382)
{
xdd2 = -8;
ydd2 = 0;
}
if (lbl2.Location.Y >= 384)
{
xdd2 = 0;
ydd2 = -2;
}
lbl2.Location = new Point(lbl2.Location.X + xdd2, lbl2.Location.Y + ydd2);
if (lbl3.Location.X <= 1)
{
xdd3 = 4;
ydd3 = 0;
}
if (lbl3.Location.Y <= 1)
{
xdd3 = 0;
ydd3 = 8;
}
if (lbl3.Location.X >=410)
{
xdd3 = -6;
ydd3 = 0;
}
if (lbl3.Location.Y >= 374)
{
xdd3 = 0;
ydd3 = -2;
}
lbl3.Location = new Point(lbl3.Location.X + xdd3, lbl3.Location.Y + ydd3);
if (lbl4.Location.X <= 1)
{
xdd4 = 6;
ydd4 = 0;
}
if (lbl4.Location.Y <= 1)
{
xdd4 = 0;
ydd4 = 2;
}
if (lbl4.Location.X >= 317)
{
xdd4 = -5;
ydd4 = 0;
}
if (lbl4.Location.Y >= 420)
{
xdd4 = 0;
ydd4 = -8;
}
lbl4.Location = new Point(lbl4.Location.X + xdd4, lbl4.Location.Y + ydd4);
} //判断游戏结束的
public void endgame()
{
if (((label1.Location.X - lblclick.Location.X <= 100 | lblclick.Location.X - lbl1.Location.X <= 52) && (lbl1.Location.Y - lblclick.Location.Y <= 90 | lblclick.Location.Y - lbl1.Location.Y <= 49)) | ((lbl2.Location.X - lblclick.Location.X <= 69 | lblclick.Location.X - lbl2.Location.X <= 52) && (lbl2.Location.Y - lblclick.Location.Y <= 64 | lblclick.Location.Y - lbl2.Location.Y <= 49)) | ((lbl3.Location.X - lblclick.Location.X <= 41 | lblclick.Location.X - lbl3.Location.X <= 52) && (lbl3.Location.Y - lblclick.Location.Y <= 73 | lblclick.Location.Y - lbl3.Location.Y <= 49)) | ((lbl4.Location.X - lblclick.Location.X <= 134 | lblclick.Location.X - lbl4.Location.X <= 52) && (lbl4.Location.Y - lblclick.Location.Y <= 28 | lblclick.Location.Y - lbl4.Location.Y <= 49)) | (lblclick.Location.X <= 51 | lblclick.Location.X >= 349 | lblclick.Location.Y <= 49 | lblclick.Location.Y >= 349))
{
timer1.Enabled = false;//游戏结束
}
}
}
}
{
public partial class Form1 : Form
{
int xdd1 = 0;//定义lbl1图片x方向的增量
int ydd1 = 0;//定义lbl1图片y方向的增量
int xdd2 = 0;//定义lbl2图片x方向的增量
int ydd2 = 0;//定义lbl2图片y方向的增量
int xdd3 = 0;//定义lbl3图片x方向的增量
int ydd3 = 0;//定义lbl3图片y方向的增量
int xdd4 = 0;//定义lbl4图片x方向的增量
int ydd4 = 0;//定义lbl4图片y方向的增量
int times = 0;//声明一个变量 public Form1( )
{
InitializeComponent();
} //鼠标按下事件
Point p = new Point();//用对象表示鼠标的坐标
Point cp = new Point();//用对象表示图片的坐标
private void lblclick_MouseDown(object sender, MouseEventArgs e)
{
p.X = Cursor.Position.X;//鼠标的横坐标
p.Y = Cursor.Position.Y;//鼠标的纵坐标
cp.X = lblclick.Location.X;//lblclick的横坐标
cp.Y = lblclick.Location.Y;//lblclick的纵坐标
timer1.Enabled = true;//启用timer
} //黄图片随鼠标移动而移动
private void lblclick_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button.Equals(MouseButtons.Left)) // 点左键移动
{
lblclick.Location = new Point(Cursor.Position.X - (p.X - cp.X), Cursor.Position.Y - (p.Y - cp.Y));
}
}
//timer事件
int mod = 1;
private void timer1_Tick(object sender, EventArgs e)
{
times++;
if (times % mod == 0)
{
Random ran = new Random();//产生随机数
xdd1 = ran.Next(20) ;
ydd1 = ran.Next(40) ;
xdd2 = ran.Next(-20,-10) ;
ydd2 = ran.Next(20) ;
xdd3 = ran.Next(30) ;
ydd3 = ran.Next(-30,-10) ;
xdd4 = ran.Next(-40,-10) ;
ydd4 = ran.Next(-30,-10) ; mod = ran.Next(100,400) ;
}
//四个木块自己移动
if (lbl1.Location.X <= 1)
{
xdd1 = 10;
ydd1 = 0;
}
if (lbl1.Location.Y <= 1)
{
xdd1 = 0;
ydd1 = 2;
}
if (lbl1.Location.X >= 351)
{
xdd1 = -5;
ydd1 = 0;
}
if (lbl1.Location.Y >= 358)
{
xdd1 = 0;
ydd1 = -2;
}
lbl1.Location = new Point(lbl1.Location.X + xdd1, lbl1.Location.Y + ydd1);
if (lbl2.Location.X <= 1)
{
xdd2 = 7;
ydd2 = 0;
}
if (lbl2.Location.Y <= 1)
{
xdd2 = 0;
ydd2 = 6;
}
if (lbl2.Location.X >= 382)
{
xdd2 = -8;
ydd2 = 0;
}
if (lbl2.Location.Y >= 384)
{
xdd2 = 0;
ydd2 = -2;
}
lbl2.Location = new Point(lbl2.Location.X + xdd2, lbl2.Location.Y + ydd2);
if (lbl3.Location.X <= 1)
{
xdd3 = 4;
ydd3 = 0;
}
if (lbl3.Location.Y <= 1)
{
xdd3 = 0;
ydd3 = 8;
}
if (lbl3.Location.X >=410)
{
xdd3 = -6;
ydd3 = 0;
}
if (lbl3.Location.Y >= 374)
{
xdd3 = 0;
ydd3 = -2;
}
lbl3.Location = new Point(lbl3.Location.X + xdd3, lbl3.Location.Y + ydd3);
if (lbl4.Location.X <= 1)
{
xdd4 = 6;
ydd4 = 0;
}
if (lbl4.Location.Y <= 1)
{
xdd4 = 0;
ydd4 = 2;
}
if (lbl4.Location.X >= 317)
{
xdd4 = -5;
ydd4 = 0;
}
if (lbl4.Location.Y >= 420)
{
xdd4 = 0;
ydd4 = -8;
}
lbl4.Location = new Point(lbl4.Location.X + xdd4, lbl4.Location.Y + ydd4);
} //判断游戏结束的
public void endgame()
{
if (((label1.Location.X - lblclick.Location.X <= 100 | lblclick.Location.X - lbl1.Location.X <= 52) && (lbl1.Location.Y - lblclick.Location.Y <= 90 | lblclick.Location.Y - lbl1.Location.Y <= 49)) | ((lbl2.Location.X - lblclick.Location.X <= 69 | lblclick.Location.X - lbl2.Location.X <= 52) && (lbl2.Location.Y - lblclick.Location.Y <= 64 | lblclick.Location.Y - lbl2.Location.Y <= 49)) | ((lbl3.Location.X - lblclick.Location.X <= 41 | lblclick.Location.X - lbl3.Location.X <= 52) && (lbl3.Location.Y - lblclick.Location.Y <= 73 | lblclick.Location.Y - lbl3.Location.Y <= 49)) | ((lbl4.Location.X - lblclick.Location.X <= 134 | lblclick.Location.X - lbl4.Location.X <= 52) && (lbl4.Location.Y - lblclick.Location.Y <= 28 | lblclick.Location.Y - lbl4.Location.Y <= 49)) | (lblclick.Location.X <= 51 | lblclick.Location.X >= 349 | lblclick.Location.Y <= 49 | lblclick.Location.Y >= 349))
{
timer1.Enabled = false;//游戏结束
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货