C#实现的打飞机游戏(课程设计)
前言
相信大家一定玩过打飞机小游戏,但是你们会自己手写一个C#打飞机的小游戏吗,让我们来看看吧
开发环境
开发环境:Windows10 64位
Visual Studio 2019
截图
核心源码
爆炸对象
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;namespace PlaneGame
{/// <summary>/// 爆炸动画的对象/// </summary>public class Boom{//小飞机爆炸的图片数组public Image[] imgs0 = { Properties.Resources.enemy0_down11,Properties.Resources.enemy0_down2,Properties.Resources.enemy0_down3,Properties.Resources.enemy0_down4};//中飞机爆炸的图片动画public Image[] imgs1 = { Properties.Resources.enemy1_down11,Properties.Resources.enemy1_down2,Properties.Resources.enemy1_down3,Properties.Resources.enemy1_down4};//大飞机爆炸的图片数组public Image[] imgs2 ={Properties.Resources.enemy2_down11,Properties.Resources.enemy2_down2,Properties.Resources.enemy2_down3,Properties.Resources.enemy2_down4,Properties.Resources.enemy2_down5,Properties.Resources.enemy2_down6};/*** 敌机在哪里死亡,爆炸就在哪里产生*/public Enemy enemyPlane { get; set; }public Image[] imgs { get; set; }public int Width { get; set; }public int Height { get; set; }public Boom(Enemy enemyPlane){this.enemyPlane = enemyPlane;//图片根据飞机的类型确定以后if (this.enemyPlane.Type==0){this.imgs = this.imgs0;}else if (this.enemyPlane.Type==1){this.imgs = this.imgs1;}else if(this.enemyPlane.Type==2){this.imgs = this.imgs2;}this.Width = this.imgs[0].Width;this.Height = this.imgs[0].Height;}/// <summary>/// 绘画游戏对象/// </summary>/// <param name="g"></param>public void Draw(Graphics g){for (int i = 0; i < this.imgs.Length; i++){g.DrawImage(this.imgs[i],this.enemyPlane.X,this.enemyPlane.Y,this.Width,this.Height);}//当爆炸动画播放完成以后,就要移除自己DataUtil.boomList.Remove(this);}}
}
子弹
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;namespace PlaneGame
{/// <summary>/// 玩家飞机的子弹/// </summary>public class Bullet:GameObject{public Bullet(int x,int y):base(x,y,Properties.Resources.bullet1){}/// <summary>/// 子弹移动的方法/// </summary>public void Move(){//玩家的子弹是向上运行的 所以它的纵坐标应该是减小的this.Y = this.Y - 40;if (this.Y<0){//说明这颗子弹已经跑到屏幕外边去了,我们要在内存当中移除它DataUtil.bulletList.Remove(this);}}//但是继承下来的Draw不能够满足我们的方法//在c#里面,所有的虚方法都可以被重写public override void Draw(Graphics g){this.Move();base.Draw(g); //调父类方法}}
}
敌军
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;namespace PlaneGame
{/// <summary>/// 敌人的飞机/// </summary>public class Enemy{public int X { get; set; }public int Y { get; set; }public Image img { get; set; }public int Width { get; set; }public int Height { get; set; }//还应该有一个特殊的属性叫type 0代表小飞机,1代表中飞机,2代表大飞机public int Type { get; set; }public int Speed { get; set; } //飞机的移动速度public int Life { get; set; } //飞机的生命值public int Score { get; set; } //当前的飞向值多少分public Enemy(int x,int y,int type){this.X = x;this.Y = y;this.Type = type;//飞机的图片它没有固定下来,它是根据我们飞机的类型来决定的if (this.Type==0){//小飞机this.img = Properties.Resources.enemy0;this.Speed = 5;this.Life = 1;this.Score = 10;}else if (this.Type==1){//中飞机this.img = Properties.Resources.enemy1;this.Speed = 3;this.Life = 2;this.Score = 30;}else if (this.Type==2){//大飞机this.img = Properties.Resources.enemy2;this.Speed = 2;this.Life = 4;this.Score = 50;}this.Width = this.img.Width;this.Height = this.img.Height;}/// <summary>/// 敌人飞机移动的方法/// </summary>public void Move(){this.Y = this.Y + this.Speed;//当飞机移动到屏幕外边的时候,应该让自己消失if (this.Y>850){//把自己移除掉DataUtil.enemyList.Remove(this);}}//把自己画出来public void Draw(Graphics g){this.Move();g.DrawImage(this.img, this.X, this.Y, this.Width, this.Height);}/// <summary>/// 获取游戏对象的矩形/// </summary>/// <returns>矩形</returns>public Rectangle getRectangle(){return new Rectangle(this.X,this.Y,this.Width,this.Height);}/// <summary>/// 是否死亡/// </summary>/// <returns></returns>public bool IsDie(){this.Life--;if (this.Life<=0){//你死了//播放死亡音乐System.Media.SoundPlayer sound = new System.Media.SoundPlayer(Properties.Resources.enemy0_down1);sound.Play();//播放爆炸动画Boom b = new Boom(this);DataUtil.boomList.Add(b);//计算得分DataUtil.Score += this.Score; //在原来的得分之上,加上现在的得分DataUtil.enemyList.Remove(this); //把自己移除return true;}else{//说明你被打了,但是你是一个残血的状态 要更改飞机的图片if (this.Type==1){//说明是中飞机this.img = Properties.Resources.enemy1_hit;}else if (this.Type==2){//说明是大飞机this.img = Properties.Resources.enemy2_hit;}return false;}}}
}
玩家的飞机
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;namespace PlaneGame
{/// <summary>/// 玩家飞机的对象/// </summary>public class Hero:GameObject{public Hero(int x,int y):base(x,y,Properties.Resources.hero1){DataUtil.IsTowBullet = false; //默认情况下,它不是双排子弹 DataUtil.IsSuperBullet = false; //默认情况下,它不是超级子弹this.Width = this.img.Width / 2;this.Height = this.img.Height / 2;}/// <summary>/// 玩家飞机发射子弹的方式/// </summary>public void Fire(){if (DataUtil.IsTowBullet){//说明要发双排子弹Bullet b_left = new Bullet(this.X, this.Y);Bullet b_right = new Bullet(this.X, this.Y);//修正左边子弹的位置b_left.X = b_left.X + this.Width / 4 - b_left.Width / 2;//修正右边子弹的位置b_right.X = b_right.X + this.Width / 4 * 3 - b_right.Width / 2;DataUtil.bulletList.Add(b_left);DataUtil.bulletList.Add(b_right);}else if (DataUtil.IsSuperBullet){Bullet b = new Bullet(this.X, this.Y);b.X = b.X - 20 + this.Width / 2 - b.Width / 2 ;b.img = Properties.Resources.bullet3;b.Height = this.Height;b.Width = this.Width + 20;DataUtil.bulletList.Add(b);}else{//玩家飞机发射的子弹是有很多个的Bullet b = new Bullet(this.X, this.Y);//修正子弹的坐标b.X = b.X + this.Width / 2 - b.Width / 2;//用集全去装所有的玩家飞机子弹DataUtil.bulletList.Add(b);}}}
}
原文链接
https://gitee.com/shadow22/aircraft_wars
推荐阅读
《JAVA学生管理系统》
《C#图书管理系统》
《C#酒店管理系统》
C#实现的打飞机游戏(课程设计)相关推荐
- Java拼图游戏总结,Java拼图游戏课程设计报告
Java拼图游戏课程设计报告 JavaJava 程序设计与应用开发 课程设计报告程序设计与应用开发 课程设计报告 设计题目 拼图大作战 学生姓名 学生班级 学生学号 指导教师 完成时间2016 年 0 ...
- c语言经典案例 俄罗斯方块,C语言实现俄罗斯方块经典游戏课程设计
C语言实现俄罗斯方块经典游戏课程设计 计算机实习报告 一.功能说明 1.1总体功能说明 本工程用C++语言实现了俄罗斯方块经典游戏. 俄罗斯方块游戏特点:俄罗斯方块的基本规则是通过键盘控制移动.旋转和 ...
- java课程设计拼图_java拼图游戏课程设计报告
java拼图游戏课程设计报告 砾寸椒涩藕矾糯陋捕炬洁困喘港划舟逃豺涌锤芳喜胺递龚乏埔跺摩实阿信颊立蹲稿船纽臃瘪自康嘱脖究绢术拱虑犹犀棉宜炙转鸦半甘哨疗墓暑蛊渤幽峭咀豺虫拘召饭莽畜穗篷姿钟逻捞跨瀑拿丈土 ...
- 推箱子android课程设计,推箱子游戏课程设计精选.doc
推箱子游戏课程设计精选 目 录 Ⅰ 摘要 Ⅱ 前言 Ⅲ 功能描述 Ⅳ 配置要求 Ⅴ 总体设计 一.功能模块设计 二.数据结构设计 三.函数功能描述 四.代码实现 Ⅵ 参考文献 Ⅰ 摘 要 推箱子游戏是 ...
- c语言课时设计猜坐标游戏,c语言小游戏课程设计报告.docx
c语言小游戏课程设计报告 中国地质大学 本科生课程论文封面 课程名称c语言课程设计 教师姓名陈喆老师 本科生姓名周宜诺 本科生学号XX 本科生专业土地资源管理 所在院系公共管理学院 类别: 日期: 课 ...
- 猜数字小c语言游戏课程任务书,猜数字游戏课程设计.doc
猜数字游戏课程设计.doc 1(c/c程序设计课程设计)设 计 说 明 书猜数字游戏的设计与实现学 生 姓 名学 号班 级成 绩指 导 教 师计算机科学与技术系2010 年 7 月 9 日C/C程序设 ...
- python贪吃蛇的实验报告_贪吃蛇游戏课程设计实验报告
DOC 可编辑修改 -------- 为你整理各种最新最全办公范文 -------- 双击可以删除 爱心 --- 用心 --- 恒心 贪吃蛇游戏课程设计实验报告 辽 宁 科 技 大 学 课程设计说明书 ...
- Python程序设计,pygame飞机大战课程设计
*飞机大战游戏设计 摘 要:根据课程要求,以及面向对象程序设计的编程思想,在Windows操作系统环境下,运用PyCharm编译程序,以Python语言为开发语言,最终实现飞机大战游戏相应的游戏操作功 ...
- 【Python飞机大战课程设计及源代码】
摘 要:根据课程要求,以及面向对象程序设计的编程思想,在Windows操作系统环境下,运用PyCharm编译程序,以Python语言为开发语言,最终实现飞机大战游戏相应的游戏操作功能.Python是一 ...
- android游戏课程设计,Miuka「游戏化课程设计」图卡18|好课程如何讲故事的
从[故事隐喻][游戏旅途][重要关卡][进化蜕变]四个维度对课程进行叙事描述. 可以利用这个思路为课程设计故事脚本,来描述学员会在课程中经历什么. 案例1:手账小行星,用了星球探索这个主题 故事设定: ...
最新文章
- 微信小程序web-view使用
- 查询存储过程所需参数
- 在简历中应用STAR法则
- 正则化方法/防止过拟合提高泛化能力的方法:L1和L2 regularization、数据集扩增、dropout
- FPGA嵌入式处理器的选择策略
- 这难道不是.NET5的bug? 在线求锤?
- 使用Mockito测试Spring组件
- mybatis if test 判断参数_什么?你还在if判断参数?Spring Boot 注解进行参数校验真香...
- linux 引导管理器,linux系统引导管理器GRUB
- Reactive(2) 响应式流与制奶厂业务
- Linux 网卡驱动学习(二)(网络驱动接口小结)
- python读取文件_一日一技:使用Python读取Excel文件
- 【转载】强大的MongoDB数据库管理工具
- php全局变量global和$GLOBALS
- the android emulator process,Android studio报错:The emulator process for AVD (xxx) was killed
- 干货 | 一文弄懂机器学习中偏差、方差
- 球缺体积和球冠表面积的计算公式及应用
- 怎么设置计算机桌面一键关机,图文详解如何设置电脑定时开关机
- 【智能手环APP for Android 】01 百度地图展示行动轨迹
- 《麦肯锡方法》读书笔记1
热门文章
- mybatis 的大于号 小于号 大于等于 小于等于
- 【NeoVim Coc.nvim】禁用从文档内提取字段的补全选项(禁用带有“yank”的补全选项)
- 关于光模块用单模光纤和多模光纤小知识
- 斗鱼直播弹幕python_调用斗鱼API爬取直播间弹幕信息(用户昵称及弹幕内容)
- [轻音乐] - 理查德·克莱德曼专辑[8CD]
- 【最全】应用程序无法正常启动0xc000007b,解决方案
- python猜拳小游戏_Python入门猜拳小游戏
- Android中视频播放以及解码
- [Android]利用金山词霸API实现英汉互译APP
- ubuntu 通过ssh链接ARM板 及 IMX6使用调试串口通信