C#简易飞机大战

本文详细介绍了如何使用C#编程语言开发一款简易的飞机大战游戏,涵盖了游戏的基本框架搭建、飞机和子弹的移动逻辑、碰撞检测以及得分系统的设计。通过实例代码解析,帮助读者理解C#在游戏开发中的应用。
摘要由CSDN通过智能技术生成

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 飞机
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //游戏区
        Panel game = new Panel();
        //控制区
        Panel kz = new Panel();
        //随机
        Random r = new Random();
        //飞机盒子
        PictureBox plane = new PictureBox();
        //小火苗1
        PictureBox fire1 = new PictureBox();
        //小火苗2
        PictureBox fire2 = new PictureBox();
        //敌机timer
        Timer djplane = new Timer();
        //敌机下落
        Timer djtop = new Timer();
        //子弹计时器
        Timer zdt = new Timer();
        // 得分label
        Label lab = new Label();
        // 记录分数
        int score = 0;
        // lab进度条背景
        Label HSback = new Label();
        // lab进度条
        Label HSjindu = new Label();
        // 记录血量
        int xt = 100;
        //开始游戏
        Label start = new Label();
        //实例化声音
        SoundPlayer sound = new SoundPlayer();
        private void Form1_Load(object sender, EventArgs e)
        {
            //form1位置
            this.Size = new Size(1100, 700);
            this.Left = Screen.PrimaryScreen.Bounds.Width / 2 - this.Width / 2;
            this.Top = Screen.PrimaryScreen.Bounds.Height / 2 - this.Height / 2;
            this.BackColor = Color.Cyan;


            //游戏区位置
            game.Size = new Size(800, 600);
            game.BackColor = Color.White;
            game.Location = new Point(30, 30);
            this.Controls.Add(game);
            //控制区
            kz.Size = new Size(200, 600);
            kz.BackColor = Color.White;
            kz.Location = new Point(game.Left + game.Width + 30, 30);
            this.Controls.Add(kz);
            //开始游戏
           
            start.Font = new Font("", 20);
            start.AutoSize = true;
            start.Text = "开始游戏";
            start.Location = new Point(40, 50);
            start.Click += Start_Click;
            kz.Controls.Add(start);
            //暂停游戏
            Label stop = new Label();
            stop.Font = new Font("", 20);
            stop.AutoSize = true;
       
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值