c#简单的金山打字游戏,也是飞机大战的雏形,是c#练习基础的项目

效果图如下

大致思路:

创建游戏区 :设置所需属性

创建字母生成:随机大小和字母

字母下落

创建飞机:添加事件,飞机跟随字母移动

创建子弹:子弹上升,碰到字母消失

其余小细节自己需要处理

注意:为了不使项目那么突兀,加了一个小的移动动画:

字母跟随鸟的移动创建字母

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 金山打字
{public partial class Form1 : Form{public Form1(){InitializeComponent();}Panel lb = new Panel();Random r = new Random();//字母生成Timer zm = new Timer();//字母下落Timer xq = new Timer();//动画移动Timer move = new Timer();//创建鸟盒子PictureBox bird = new PictureBox();//创建飞机PictureBox plan = new PictureBox();//创建动画计时器Timer fly = new Timer();//创建的得分的labelLabel df = new Label();  int x = 0;//实例化血条Label xt = new Label();Label xt1 = new Label();int dl = 0;private void Form1_Load(object sender, EventArgs e){this.WindowState = FormWindowState.Maximized;this.Text = "金山打字";this.BackgroundImage = Image.FromFile(@"../../img/2.jpg");this.BackgroundImageLayout = ImageLayout.Stretch;//游戏区域lb.Width = 1300;lb.Height = 780;lb.BackColor = Color.Brown;this.Controls.Add(lb);//开始游戏Label ks = new Label();ks.Size = new Size(120, 20);ks.BackColor = Color.White;ks.Location = new Point(1380, 100);ks.Tag = "ksyx";ks.Text = "开始游戏";ks.Font = new Font("", 15);ks.AutoSize = true;this.Controls.Add(ks);ks.Click += Ks_Click;//创建暂停按钮Label zt = new Label();zt.Size = new Size(120, 20);zt.BackColor = Color.White;zt.Location = new Point(1380, 150);zt.Tag = "ztyx";zt.Text = "暂停游戏";zt.Font = new Font("", 15);zt.AutoSize = true;this.Controls.Add(zt);zt.Click += Zt_Click;//得分栏df.Size = new Size(130, 20);df.Location = new Point(1380, 210);df.Tag = "dfl";df.Text = "得分:0分";df.Font = new Font("", 15);df.AutoSize = true;this.Controls.Add(df);//血条xt.Size = new Size(130, 20);xt.Location = new Point(1380, 280);xt.BackColor = Color.White;xt1.Size = new Size(130, 20);xt1.Location = new Point(1380, 280);xt1.BackColor = Color.Red;xt.Tag = "xt";xt.Tag = "xt1";this.Controls.Add(xt);this.Controls.Add(xt1);//字母计时器zm.Interval = 700;zm.Tick += Zm_Tick;//动画图片bird.Tag = "b";bird.Size = new Size(140, 120);bird.Location = new Point(0, 0);bird.Image = imageList1.Images[0];lb.Controls.Add(bird);//动画事件fly.Interval = 80;fly.Tick += Fly_Tick;//动画移动move.Interval = 20;move.Tick += Move_Tick;//字母下落控制xq.Interval = 20;xq.Tick += Xq_Tick;//飞机plan.Tag = "plan";plan.Size = new Size(80,80);plan.Location = new Point(lb.Width / 2 - plan.Width / 2, lb.Height - plan.Height);plan.Image = Image.FromFile(@"../../img/YP03.png");plan.SizeMode = PictureBoxSizeMode.StretchImage;lb.Controls.Add(plan);}//暂停事件private void Zt_Click(object sender, EventArgs e){zm.Stop();fly.Stop();xq.Stop();move.Stop();}//开始事件private void Ks_Click(object sender, EventArgs e){zm.Start();fly.Start();xq.Start();move.Start();}int xuetiao = 130;//下落private void Xq_Tick(object sender, EventArgs e){foreach (Control item in lb.Controls){if (item.GetType().Name== "Label"){item.Top += 3;}if (item.Top>=lb.Height){item.Dispose();xuetiao -= 10;xt.Width = xuetiao;dl++;if (xt.Width==0){zm.Stop();fly.Stop();xq.Stop();move.Stop();MessageBox.Show("Game over!!");}}//子弹上升if (item.GetType().Name == "PictureBox"){if (item.Tag.ToString() == "zd"){item.Top -= 3;foreach (Control bz in lb.Controls){if (bz.Tag.ToString() == "bj"){if (item.Top <= bz.Top + bz.Height && item.Left + item.Width / 2 == bz.Width / 2 + bz.Left){bz.Dispose();item.Dispose();x += 10;df.Text = x.ToString() + "分";PictureBox xg = new PictureBox();xg.Size = new Size(50, 50);xg.Location = new Point(item.Left + item.Width / 2 - xg.Width / 2, item.Top + item.Height - xg.Height);xg.Tag = 0;xg.Image = imageList2.Images[0];lb.Controls.Add(xg);Timer bofang = new Timer();bofang.Interval = 70;bofang.Tag = xg;bofang.Tick += Bofang_Tick;bofang.Start();}}}}}}}private void Bofang_Tick(object sender, EventArgs e){Timer bf =(Timer)sender;PictureBox pictureBox = (PictureBox)bf.Tag;pictureBox.Image = imageList2.Images[(int)pictureBox.Tag];pictureBox.Tag = (int)pictureBox.Tag + 1;if ((int)pictureBox.Tag>=32){bf.Dispose();pictureBox.Dispose();}}//动画移动事件private void Move_Tick(object sender, EventArgs e){bird.Left += 3;if (bird.Left>lb.Width){bird.Left = -bird.Width;}}//动画事件int index=0;private void Fly_Tick(object sender, EventArgs e){index++;bird.Image = imageList1.Images[index];if (index>=10){index  = -1;}}//字母下落控制private void Zm_Tick(object sender, EventArgs e){if (bird.Left>=0&&bird.Left<=lb.Width-bird.Width){Label xl = new Label();xl.Text = ((char)r.Next(97, 123)).ToString();xl.Font = new Font("", r.Next(15, 30));xl.Tag = "xl";xl.AutoSize = true;xl.ForeColor = Color.FromArgb(r.Next(255), r.Next(255), r.Next(255));xl.Top = bird.Height;xl.Left = bird.Left + bird.Width / 2 - xl.Width / 2;lb.Controls.Add(xl);}}private void Form1_KeyPress(object sender, KeyPressEventArgs e){foreach (Control item in lb.Controls){if (item.GetType().Name== "Label"){if (item.Text==e.KeyChar.ToString()&&item.Tag.ToString()=="xl"){plan.Left = item.Left + item.Width / 2 - plan.Width / 2;item.Tag = "bj";//创建子弹PictureBox bullet = new PictureBox();bullet.Tag = "zd";bullet.Size = new Size(8, 30);bullet.Image = Image.FromFile(@"../../img/zd.png");bullet.Location = new Point(plan.Left + plan.Width / 2 - bullet.Width / 2, plan.Top - bullet.Height);bullet.SizeMode = PictureBoxSizeMode.StretchImage;lb.Controls.Add(bullet);return;}}}}}
}

c#简易的金山打字游戏相关推荐

  1. 金山打字游戏c语言代码,一天练习一个小C/C++程序(一) 控制台版“金山打字”游戏...

    今天练习了一个C语言小程序,控制台版的简易"金山打字"小游戏. 效果图: 代码: #include #include #include #include void printfSp ...

  2. 一天练习一个小C/C++程序(一) 控制台版“金山打字”游戏

    今天练习了一个C语言小程序,控制台版的简易"金山打字"小游戏. 效果图: 代码: #include<stdio.h> #include<stdlib.h> ...

  3. 原生面向对象的简单金山打字游戏

    金山打字小游戏 1.介绍及效果图 这是一个练习打字的游戏,当游戏开始后,界面从顶部不断落下内容为随机字母的方块,当按下相对应的按键时,就会清除对应方块 2.思路 1.如何确定难度? 2.方块如何生成? ...

  4. 金山打字通2008完整版包含金山打字游戏,网上唯一的

    金山打字通2008 官方正式完整版,网上唯一的,其他都是不完整的.2007,2009版为虚假,官方未出此版. [概括介绍] 金山打字通是一款学习打字软件具有英文打字.拼音打字.五笔打字.打字游戏等功能 ...

  5. 【Unity2d】带你制作一款类似于金山打字的小游戏

    博主大概08年开始接触电脑游戏,当时玩的是我哥的电脑,那时候家里没网,只可以玩电脑上自带的单机游戏,比如扫雷.蜘蛛纸牌等等,当然还有红色警戒.冰封王座.星际争霸.帝国崛起等等,这些大概是我哥当时在大学 ...

  6. java swing游戏编程高仿金山打字教程-拯救苹果

    原文:java swing游戏编程高仿金山打字教程-拯救苹果 源代码下载地址:http://www.zuidaima.com/share/1786650901515264.htm 这几天学习了一下ja ...

  7. 17.js实现金山打字

    效果图 1 <!DOCTYPE html>2 <html>3 <head>4 <meta charset="UTF-8">5 < ...

  8. 官方金山打字通2009

    官方金山打字通2009 软件类别:国产软件/教育教学 运行环境: Win98/2000/XP/2003/Vista 软件语言:简体中文 开发作者: 金山软件公司 官方网站:http://www.syy ...

  9. 金山打字通2008下载-金山打字通2008正式版-金山打字通2008完整版

    金山打字通2008下载:金山打字通2008正式版集成金山打字通2008以及金山打字游戏2008两个版本于一身.主要由英文打字.拼音打字.五笔打字.打字游戏等六部分组成.所有练习用词汇和文章都分专业和通 ...

最新文章

  1. [CF413D]2048
  2. fft快速傅利叶变的C实现
  3. 典型案例道出“服务台”的价值
  4. mysql怎么可视化连接_IDEA连接MySQL可视化工具连接操作
  5. 从头开始学一个android activity
  6. WordPress主题-果核剥壳站长开发CorePress v2.6
  7. 学习笔记(04):MySQL数据库运维与管理-02-二进制日志及其管理
  8. 做完自动化测试,但别让不会汇报毁了你...
  9. 公布几个流氓软件分析报告——哇哇资讯精灵
  10. QT 与webkit(wke) 交互
  11. 女性每天喝酸奶的好处是什么?
  12. 软件测试缺陷指标,如何对缺陷进行分析,都分析哪些指标?
  13. vue.js中文官网下载vue.js失败了?
  14. Python爬取新冠肺炎疫情实时数据(丁香园)
  15. 我的世界服务器领地系统,我的世界服务器怎么创建领地
  16. Javascript(JS) leetcode 200. 岛屿数量
  17. Python-matplotlib画图要点【大总结】
  18. MaskRCNN-Benchmark框架Assertion 't ** 0 t ** n_classes' failed可能的原因
  19. 央视影音 服务器暂时无法连接服务器,cbox不能播放怎么办 cbox故障解决方法【步骤】...
  20. NOI:7213 垃圾炸弹

热门文章

  1. 51单片机之数码管静态显示
  2. 《解构产品经理》读书笔记
  3. 树莓派4b在miniconda下安装kivy,示例报错‘ImportError...libstdc++.so.6: version ‘GLIBCXX_3.4.29‘ not found‘解决办法
  4. 【二维码】二维码生成
  5. 【个人收藏】一些比较有用的链接
  6. ES2019新增功能
  7. Jedis的使用示范
  8. 1159 Palindrome
  9. Linux的上传和下载文件到Window_scp指令
  10. PHP对接网络游戏防沉迷实名认证系统