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灯, 水草

请输入看板名称,例如:WOW站内搜寻

TOP