One . Programming ideas
1. Simple interface implementation ;
2. Generation of letters , And location determination ;
3. Automatic drop of letters ;
4. Aircraft generation and location determination ;
5. The formation of bullets ;
6. When the bullet is in the same position as the letter , Letters disappear ;
7. Explode when letters disappear , And explosive sound ;
Two . Programming focus
1. Control the generation of letters , And automatic fall ;
2. Determination of aircraft position ;
3. The formation and location of bullets ;
4. Explosion effect and explosion sound effect ;
Three . code implementation
1. Division of interface layout , Mainly game area and control area ; // Instantiation timer Timer timer1 = new Timer(); Timer timer2 =
new Timer(); // Because some controls apply globally, we declare globally Panel panel1 = new Panel();// Generate game area // Generate aircraft controls
PictureBox picture = new PictureBox(); private void Form1_Load(object sender,
EventArgs e) { this.KeyPreview = true;// Always let the form get focus this.Text = " Xiaoqiang, who can't type ";
// Set up game area panel1.Size = new Size(700, 430);// Set game area size panel1.BorderStyle =
BorderStyle.Fixed3D;// Set border panel1.Location = new Point(10,10);// Set initial position this.
Controls.Add(panel1);// Add game area to the form timer1.Tick += Timer1_Tick1;//timer1 Click event timer1
.Interval = 1000;// time interval timer2.Tick += Timer2_Tick1; timer2.Interval = 100; }
2. Control generation letters ; // To set a random number for a series of letters Random p = new Random(); private void Timer1_Tick1(
object sender, EventArgs e) { Label zimu = new Label();// instantiation label For storing letters zimu.
Text= ((char)p.Next(97, 123)).ToString();// Randomly generate lowercase letters zimu.Font = new Font(" Tahoma ", p
.Next(25, 35));// Font settings for letters zimu.ForeColor = Color.FromArgb(p.Next(255), p.Next(255
), p.Next(255));// Set random color of letters zimu.Left = p.Next(panel1.Width - zimu.Width);// Set location
zimu.AutoSize = true;// Adaptive size zimu.Tag = "zimu";// Mark panel1.Controls.Add(zimu)
; } 3. Control generation " aircraft "( Beginners can write in the window loading event ); // Set aircraft properties picture.Size = new Size(100, 100);
picture.BackgroundImage = Image.FromFile("../../image/BP03.png");// Where to reference pictures
picture.BackgroundImageLayout = ImageLayout.Stretch;// Set picture layout to stretch // Set picture location picture
.Left = panel1.Width / 2 - picture.Width / 2; picture.Top = panel1.Height -
picture.Height; picture.Tag = "feiji";// Mark panel1.Controls.Add(picture);
4. Realize the fall of letters ; private void Timer2_Tick1(object sender, EventArgs e) { foreach (
Control item in panel1.Controls)// Ergodic search device zimu control { if (item.Tag.ToString() ==
"zimu" || item.Tag.ToString() == "anxia")//tag For what we want zimu { item.Top += 8;
// Control its descent 10 Pixels } } } 5. Realize the movement of the aircraft by clicking the corresponding letter key on the keyboard ; Here we need a keyboard click event , We use code that can be entered at load time :

private void Form1_KeyPress(object sender, KeyPressEventArgs e) { foreach (
Control item in panel1.Controls)// Ergodic search device zimu control { if (item.Text == e.KeyChar.
ToString() && item.Tag.ToString() == "zimu")// Press the corresponding keyboard letter zimu { picture.Left =
item.Left + item.Width / 2 - picture.Width / 2;// Set aircraft movement } } } 6. To generate bullets , And determine the location ;
private void Form1_KeyPress(object sender, KeyPressEventArgs e) { foreach (
Control item in panel1.Controls)// Ergodic search device zimu control { if (item.Text == e.KeyChar.
ToString() && item.Tag.ToString() == "zimu")// Press the corresponding keyboard letter zimu { item.Tag = "anxia"
;// Change the tag picture.Left = item.Left + item.Width / 2 - picture.Width / 2;
// Set aircraft movement PictureBox zd = new PictureBox();// A container for bullets zd.Size = new Size(20,20);
// Can't change order , Must have size to use zd.Left = picture.Left + picture.Width / 2 - zd.Width / 2;
// Set the position of the bullet zd.BackgroundImage = Image.FromFile("../../image/01.jpg");// Set up pictures of bullets zd
.BackgroundImageLayout = ImageLayout.Stretch;// Set picture stretch zd.Top = picture.Top-50;
// Set the height of the bullet zd.Tag = "zidan"; panel1.Controls.Add(zd); return;// Prevent the same letter from firing multiple bullets at a time } }
} 7. Bullets collide with letters to release letter resources ; private void Timer2_Tick1(object sender, EventArgs e) {
foreach (Control item in panel1.Controls)// Ergodic search device zimu control { if (item.Tag.ToString()
== "zimu" || item.Tag.ToString() == "anxia")//tag For what we want zimu { item.Top += 8;
// Control its descent 10 Pixels if (item.Top >= panel1.Height)// To avoid multiple bullets , Release the first letter when it falls { item.
Dispose();// Release resources } } if (item.Tag.ToString() == "zidan") { item.Top -= 10;
// Bullet up 8 pixel foreach (Control zimu in panel1.Controls) { if (zimu.Tag.ToString() ==
"anxia")// After the change, you can know whether it is the letter pressed { if (item.Top <= zimu.Top + zimu.Height && item.
Left+ item.Width / 2 == zimu.Left + zimu.Width / 2)// Judge its height { item.Dispose();
// Release resources zimu.Dispose();// Release resources } } } } } 8. Setting of explosion sound effect ; if (item.Top <= zimu.Top +
zimu.Height && item.Left + item.Width / 2 == zimu.Left + zimu.Width / 2)// Judge its height
{ // Set explosion sound effect string bz = "../../music/1.wav";// The path of sound effect SoundPlayer baozha = new
SoundPlayer(bz);// Control sound playback baozha.Play();// Play sound item.Dispose(); zimu.Dispose(); }
9. Realization of explosion effect ; // Set explosion effect // Written in No 8 step zimu.Dispose after { PictureBox bomd = new PictureBox();
bomd.Tag = "bomd"; bomd.Size = new Size(20, 20); bomd.Image = imageList1.Images[
0];// Store exploded pictures bomd.Tag = 0; bomd.Left = zimu.Left + zimu.Width / 2 - bomd.Width /
2; bomd.Top = zimu.Top + zimu.Height / 2 - bomd.Height / 2; panel1.Controls.Add(
bomd); Timer bom = new Timer();// Timer for exploded pictures bom.Start(); bom.Interval = 50; bom.
Tick+= Bom_Tick;//timer event bom.Tag = bomd;// Package it and drop it directly to the next reference } private void Bom_Tick
(object sender, EventArgs e) { Timer bom = (Timer)sender;// event source PictureBox
photo=(PictureBox)bom.Tag;// Convert to picturebox type photo.Image = imageList1.Images[(int
)photo.Tag];// Choose a photo photo.Tag = (int)photo.Tag + 1;// Photo plus 1 if ((int)photo.Tag>31)
{ bom.Dispose(); photo.Dispose(); } } Four . design sketch

Technology
©2019-2020 Toolsou All rights reserved,
iPhone 12 price , Configure full exposure : Cut it off 64GB, Battery 2227mAh start Python read Excel A column | Transfer deposit jsonVue Transfer parameters and receiving of page Jump el-select Get selected label value python Short circuit logic in Element-UI Implementation of secondary packaging TreeSelect Tree drop-down selection component TypeScript Data types in is enough ToastUtils Use of element-ui Of el-date-picker Component get value el-select At the same time label and value value