C_Sharp 板


LINE

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







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Tech_Job站內搜尋

TOP