作者frozen770401 (大熊)
看板C_Sharp
标题[问题] 关於TIMER的用法
时间Tue Jun 22 09:22:28 2010
namespace 琏条邃猟镑涌膊눊{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int x1;
int y1;
int score =0;
private void Form1_Load(object sender, EventArgs e)
{
}
private void Mouse_MLR(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Middle)
{
timer2.Enabled = true;
}
else if (e.Button == MouseButtons.Left)
{
timer1.Enabled = true;
}
else if (e.Button == MouseButtons.Right)
{
timer3.Enabled = true;
}
}
█
int a=0;
private void timer1_Tick(object sender, EventArgs e)
{
if (a > 2)
{
a = 0;
timer1.Enabled = false;
pictureBox1.Image = imageList1.Images[0];
pictureBox2.Left = x1;
pictureBox2.Top = y1;
label1.Text = x1.ToString();
label2.Text = y1.ToString();
if ((x1 <= 350) && (y1 >= 324&&y1<=406))
{
MessageBox.Show("旅叶鈭蘡");
score = score + 1;
label3.Text = "猟镑筝涝蝚갢 + score.ToString() + "甈ꄢ;
}
else
MessageBox.Show("瘝奨鲉旅叶嚗脢);
}
else
{
a++;
pictureBox1.Image = imageList1.Images[3];
}
█ }
int b=0;
private void timer2_Tick(object sender, EventArgs e)
{
if (b > 2)
{
b = 0;
timer2.Enabled = false;
pictureBox1.Image = imageList1.Images[0];
if ((x1 <= 350) && (y1 >= 406&&y1<=488))
{
MessageBox.Show("旅叶鈭蘡");
score = score+1;
label3.Text = "猟镑筝涝蝚갢 + score.ToString() + "甈ꄢ;
}
else
MessageBox.Show("瘝奨鲉旅叶嚗脢);
}
else
{
b++;
pictureBox1.Image = imageList1.Images[1];
}
}
int c;
private void timer3_Tick(object sender, EventArgs e)
{
if (c > 2)
{
c = 0;
timer3.Enabled = false;
pictureBox1.Image = imageList1.Images[0];
if ((x1 <= 350) && (y1 >= 488&&y1<=570))
{
MessageBox.Show("旅叶鈭蘡");
score = score + 1;
label3.Text = "猟镑筝涝蝚갢 + score.ToString() + "甈ꄢ;
}
else
MessageBox.Show("瘝奨鲉旅叶嚗脢);
}
else
{
c++;
pictureBox1.Image = imageList1.Images[2];
}
}
█ int move;
private void button1_Click(object sender, EventArgs e)
{
Random rnd = new Random();
move= rnd.Next(1,4);
pb1.Enabled = true;
x1 = 749;
y1 = 1;
ball();
}
private void ball( {
switch (move)
{
case 1: pb1.Enabled = true;
pb2.Enabled = false;
pb3.Enabled = false;
break;
case 2: pb2.Enabled = true;
pb1.Enabled = false;
pb3.Enabled = false;
break;
case 3: pb3.Enabled = true;
pb2.Enabled = false;
pb1.Enabled = false;
break;
}
}
█
private void pb1_Tick(object sender, EventArgs e)
{
if (x1 < 0)
{
x1 = 749;
y1 = 1;
pb1.Enabled = false;
}
else
{
x1 = x1 - 12;
y1 = y1 + 8;
pictureBox2.Left = x1;
pictureBox2.Top = y1;
label1.Text = x1.ToString();
label2.Text = y1.ToString();
}
}
private void pb2_Tick(object sender, EventArgs e)
{
if (x1 < 0)
{
x1 = 749;
y1 = 1;
pb2.Enabled = false;
}
else
{
x1 = x1 - 12;
y1 = y1 + 10;
pictureBox2.Left = x1;
pictureBox2.Top = y1;
label1.Text = x1.ToString();
label2.Text = y1.ToString();
}
}
private void pb3_Tick(object sender, EventArgs e)
{
if (x1 < 0)
{
x1 = 749;
y1 = 1;
pb3.Enabled = false;
}
else
{
x1 = x1 - 12;
y1 = y1 + 12;
pictureBox2.Left = x1;
pictureBox2.Top = y1;
label1.Text = x1.ToString();
label2.Text = y1.ToString();
}
}
}
不好意思 小弟是新手
请各位多多包涵
我朋友最近寄给我这个棒球打击游戏的程式
不过这个程式真的很阳春 连反击都没有= =
叫我学学看TIMER的用法
可是我身边有的书籍都是比较低阶的
都翻烂了也没看到TIMER的介绍
在网路上找资料又都看得懵懵懂懂
所以想请问这边的朋友关於TIMER的用法和这个程式的一些问题
我有问题的部分都有用色块上下包围
先解释一下他里面的程式
PICTUREBOX1是打击的姿势
imagelist只有[0]是还没挥击的动作
其他[1]~[3]都是挥击出去的动作
PICTUREBOX2则是棒球
第一个我想请问的是TIMER1_TICK那边
为什麽上面已经宣告a=0
可是下面判断式会有a>2?
是因为TIMER_TICK会过一段时间就重复执行一次吗?
所以a会因为else的a++而变成会>2吗?
如果是这样那TIMER_TICK重复执行的时间怎麽算?
而且如果执行a>2的部分为什麽需要把计时器关掉呢(timer1.Enabled = false;)?
第二个问题是BUTTON_CLICK那边
这边是设定球的轨迹的
既然已经乱数决定用哪种轨迹了为什麽还要在里面先开启pb1.Enabled = true呢?
而且SWITCH CASE的部分为什麽不是只要开启一个计时器就好
还要把其他两个计时器关掉?
第三个问题又回到第一个TIMER1的部分
我想问为什麽他挥击动作的图片会放在ELSE的部分
而回到原来打击姿势却是放在if的部分?
这部分不是判断打到的位置吗= =?
以上就是我的问题
可能有点多而且有点蠢
请各位多多包涵
先谢谢耐心看完的朋友
不好意思给你们添麻烦了
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.169.175.49
1F:→ scottzz:Time_Tick Interval时间在该控制项属性中可以设定,设定 06/22 09:32
2F:→ scottzz:1000毫秒表示每秒执行一次 06/22 09:32
3F:推 horngsh:学个Timer还要看这麽长程式, 是在帮你还是害你? 唉.. 06/22 09:35
4F:→ remmurds:我觉得你朋友根本是来乱的... 06/22 10:48
5F:→ frozen770401:哈哈 先谢谢各位回应 我朋友本来就爱这样 就除了重点 06/22 11:34
6F:→ frozen770401:还喜欢加些有的没的 06/22 11:35
7F:→ frozen770401:嗯...刚刚又想到一个问题 如果要让球会因为打击到而 06/22 11:36
8F:→ frozen770401:改变方向 这样要如何修改呢? 06/22 11:36