我是个初学者,刚接触C#,我看了一些教程,然后就做了个小球游戏,下面是编码:namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int y = 4; int x = 4;
private void timer1_Tick(object sender, EventArgs e)
{
radioButton1 .Top =radioButton1 .Top +y;
radioButton1.Left = radioButton1.Left + x;
if (radioButton1.Top > 250 || radioButton1.Top <= 0)
y=-y;
if (radioButton1.Left > 275 || radioButton1.Left <= 0)
x =-x;
} private void Form1_MouseClick(object sender, MouseEventArgs e)
{
if (timer1.Enabled == false)
timer1.Enabled = true;
else
timer1.Enabled = false;
if (radioButton1.Top > 92 & radioButton1.Top < 174)
if (radioButton1.Left > 94 & radioButton1.Left < 193)
MessageBox.Show("继续下一关");
} }
}
但是,我想下一关后小球的速度会变快一点,问过别人,说要用到timer.Interval,但是不知道怎么运用,求帮忙~~
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int y = 4; int x = 4;
private void timer1_Tick(object sender, EventArgs e)
{
radioButton1 .Top =radioButton1 .Top +y;
radioButton1.Left = radioButton1.Left + x;
if (radioButton1.Top > 250 || radioButton1.Top <= 0)
y=-y;
if (radioButton1.Left > 275 || radioButton1.Left <= 0)
x =-x;
} private void Form1_MouseClick(object sender, MouseEventArgs e)
{
if (timer1.Enabled == false)
timer1.Enabled = true;
else
timer1.Enabled = false;
if (radioButton1.Top > 92 & radioButton1.Top < 174)
if (radioButton1.Left > 94 & radioButton1.Left < 193)
MessageBox.Show("继续下一关");
} }
}
但是,我想下一关后小球的速度会变快一点,问过别人,说要用到timer.Interval,但是不知道怎么运用,求帮忙~~
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int y = 4; int x = 4;
private void timer1_Tick(object sender, EventArgs e)
{
radioButton1 .Top =radioButton1 .Top +y;
radioButton1.Left = radioButton1.Left + x;
if (radioButton1.Top > 250 || radioButton1.Top <= 0)
y=-y;
if (radioButton1.Left > 275 || radioButton1.Left <= 0)
x =-x;
} private void Form1_MouseClick(object sender, MouseEventArgs e)
{
if (timer1.Enabled == false)
timer1.Enabled = true;
else
timer1.Enabled = false;
if (radioButton1.Top > 92 & radioButton1.Top < 174)
if (radioButton1.Left > 94 & radioButton1.Left < 193)
MessageBox.Show("继续下一关");
} }
}
int a;在timer事件中加上代码:
a++;
timer.interval-=a*10我个人对自己回答的评价:没有废话,直击要害!
timer.interval-=a*10 这个不对啊,总是出错,说:值“0”不是 Interval 的有效值。Interval 必须大于 0。
timer1.Interval = (int)Math.Ceiling(timer1.Interval * 0.95);