C#编写一个大字母游戏,详细代码,不懂问博主。。。。

  1 using System;
  2 using System.Drawing;
  3 using System.Windows.Forms;
  4 using System.Media;
  5 
  6 namespace dazimuyouxi_2
  7 {
  8     public partial class Form1 : Form
  9     {
 10         public Form1()
 11         {
 12             InitializeComponent();
 13         }
 14         int i = 0, j = 0;
 15 
 16         private void Form1_Load(object sender, EventArgs e)
 17         {
 18             label1.BackColor = Color.Green;
 19             label2.BackColor = Color.Red;
 20             label1.Text = "分数:" + i;
 21             label2.Text = "错误:" + j;
 22             this.KeyPress += Form1_KeyPress;
 23             this.comboBox1.SelectedIndex = 0;
 24         }
 25         bool istrue = true;
 26         SoundPlayer s = new SoundPlayer("GRAY2WEA.WAV");
 27         private void Form1_KeyPress(object sender, KeyPressEventArgs e)
 28         {
 29 
 30             foreach (Control item in Panel1.Controls)
 31             {
 32                 if (item.Text == e.KeyChar.ToString().ToUpper())
 33                 {
 34                     if (istrue == true)
 35                     {
 36                         item.Tag = "bj";
 37                         feiji.Location = new Point(new Size(item.Left + item.Width / 2 - feiji.Width / 2, feiji.Top));
 38                         Label zd = new Label();
 39                         zd.Size = new Size(40, 40);
 40                         zd.Location = new Point(new Size(feiji.Left + feiji.Width / 2 - zd.Width / 2 + 20, feiji.Top));
 41                         zd.Text = item.Text;
 42                         zd.Tag = "zidan";
 43                         zd.Image = imageList2.Images[0];
 44                         zd.AutoSize = true;
 45                         Panel1.Controls.Add(zd);
 46                         istrue = false;
 47                     }
 48                 }
 49             }
 50         }
 51         Random a = new Random();
 52         private void timer1_Tick(object sender, EventArgs e)
 53         {
 54             Label lab = new Label();
 55             lab.BackColor = Color.Transparent;
 56             lab.Size = new Size(20, 20);
 57             lab.Text = Convert.ToChar(a.Next(65, 91)).ToString();
 58             lab.ForeColor = Color.FromArgb(a.Next(256), a.Next(256), a.Next(256));
 59             lab.Font = new Font("微软雅黑", 20);
 60             lab.Location = new Point(new Size(a.Next(0, Panel1.Width - lab.Width - 10), 0));
 61             lab.AutoSize = true;
 62             lab.Tag = "zimu";
 63             this.Panel1.Controls.Add(lab);
 64         }
 65         private void timer2_Tick(object sender, EventArgs e)
 66         {
 67             foreach (Control item in Panel1.Controls)
 68             {
 69                 if (item.GetType().Name == "Label")
 70                 {
 71                     if (item.Tag.ToString() == "zimu" || item.Tag.ToString() == "bj")
 72                     {
 73                         item.Top += 5;
 74                         if (item.Bottom >= feiji.Top)
 75                         {
 76                             item.Dispose();
 77                             j += 1;
 78                             label2.Text = "错误:" + j;
 79                         }
 80                     }
 81                     if (item.Tag.ToString() == "zidan")
 82                     {
 83                         item.Top -= 20;
 84                         foreach (Control xz in Panel1.Controls)
 85                         {
 86                             if (xz.GetType().Name == "Label")
 87                             {
 88                                 if (xz.Tag.ToString() == "bj")
 89                                 {
 90                                     if (xz.Bottom >= item.Top)
 91                                     {
 92                                         PictureBox pb = new PictureBox();
 93                                         pb.Image = imageList1.Images[0];
 94                                         pb.BackColor = Color.Transparent;
 95                                         pb.Location = item.Location;
 96                                         pb.Tag = 0;
 97                                         pb.Size = new Size(30, 30);
 98                                         pb.SizeMode = PictureBoxSizeMode.StretchImage;
 99                                         //pb.BackColor = Color.Red;
100                                         Panel1.Controls.Add(pb);
101                                         timer3.Start();
102                                         s.Play();
103                                         item.Tag = 0;
104                                         xz.Dispose();
105                                         item.Dispose();
106                                         i += 1;
107                                         label1.Text = "分数:" + i;
108                                         istrue = true;
109                                     }
110                                 }
111                             }
112                         }
113                     }
114                 }
115             }
116         }
117 
118         private void timer3_Tick(object sender, EventArgs e)
119         {
120             foreach (Control item in Panel1.Controls)
121             {
122                 if (item.GetType().Name == "PictureBox" && item.Tag != null)
123                 {
124                     int n = int.Parse(item.Tag.ToString());
125                     n++;
126                     if (n > 26)
127                     {
128                         item.Dispose();
129                         return;
130                     }
131                     ((PictureBox)item).Image = imageList1.Images[n];
132                     ((PictureBox)item).Tag = n;
133                 }
134             }
135         }
136 
137         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
138         {
139             comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
140             if (comboBox1.Text == "长平之战")
141             {
142                 this.BackgroundImage = new Bitmap("2.jpg");
143             }
144             if (comboBox1.Text == "赤壁之战")
145             {
146                 this.BackgroundImage = new Bitmap("3.jpg");
147             }
148             if (comboBox1.Text == "蓝色星球")
149             {
150                 this.BackgroundImage = Image.FromFile("1.jpg");
151             }
152         }
153 
154         private void button1_Click(object sender, EventArgs e)
155         {
156             if (button1.Text == "开始")
157             {
158                 timer1.Start();
159                 timer2.Start();
160                 button1.Text = "暂停";
161             }
162             else
163             {
164                 button1.Text = "开始";
165                 timer1.Stop();
166                 timer2.Stop();
167             }
168         }
169 
170         private void timer4_Tick(object sender, EventArgs e)
171         {
172 
173             foreach (Control item in Panel1.Controls)
174             {
175                 if (item.GetType().Name == "Label" && item.Tag.ToString() == "zidan")
176                 {
177                     item.BackColor = Color.Transparent;
178                     int m = int.Parse(((Label)item).Image.Tag.ToString());
179                     m++;
180                     if (m > 3)
181                     {
182                         item.Dispose();
183                         return;
184                     }
185                     ((Label)item).Image = imageList2.Images[m];
186                     ((Label)item).Image.Tag = m;
187                 }
188             }
189         }
190     }
191 }

 

转载于:https://www.cnblogs.com/wjrelax/p/8068110.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值