[問題] 關於TIMER的用法
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
→
06/22 09:32, , 1F
06/22 09:32, 1F
→
06/22 09:32, , 2F
06/22 09:32, 2F
推
06/22 09:35, , 3F
06/22 09:35, 3F
→
06/22 10:48, , 4F
06/22 10:48, 4F
→
06/22 11:34, , 5F
06/22 11:34, 5F
→
06/22 11:35, , 6F
06/22 11:35, 6F
→
06/22 11:36, , 7F
06/22 11:36, 7F
→
06/22 11:36, , 8F
06/22 11:36, 8F
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章