This article shares the specific code for C# to implement typing games for your reference. The specific content is as follows
Ideas:
1. There is a game interface, I use panel as the game interface
2. Start generating letters
The letters in the typing game are constantly generated, so use the timer to generate letters.
All generated letters are set to facilitate searching
3. Letters Where
Letters fall is a continuous action, so it is also done in the timer
In the timer, iterate through foreach and find the letters through tags to drop the letters
4. Generate bullets
Generate bullets by getting keyboard events
5. Bullets and letters
Code:
private void Form1_Load(object sender, EventArgs e) { this. = ; (); (); = 1000; = 100; = "feiji"; = new Size(30, 40); = ; = "airplane"; = ; = ; = new Point( / 2 - / 2, - ); (fj); } Label fj = new Label(); Random r = new Random(); private void timer1_Tick(object sender, EventArgs e) { Label zm = new Label(); = "zimu"; = ((char)(97, 123)).ToString(); = new Font("", (20, 30)); = true; = new Point((0, - ), 0); = ((255), (255), (255)); (zm); } private void timer2_Tick(object sender, EventArgs e) { foreach (Control item in ) { if (() == "zimu"||()=="zzm") { += 5; if ( >= ) { (); } }else if (() == "zidan") { -= 9; foreach (Control con in ) { if (() == "zzm") { if ( + >= ) { (); (); SoundPlayer ply = new SoundPlayer(); = ".../.../Sound/"; (); } } } } } } private void Form1_KeyPress(object sender, KeyPressEventArgs e) { foreach (Control item in ) { if (() == "zimu") { if ( == ()) { Label zd = new Label(); = "zidan"; = new Size(20, 20); = "zzm"; = ; = new Point( + / 2 - / 2, - ); = + / 2 - / 2; (zd); return; } } } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.