PlantWar/Models/GameObject.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace PlantWar.Models
{
    /// <summary>
    /// 这是所有游戏对象的父类,封装着所有子类所共有的成员
    /// </summary>
    public abstract class GameObject
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="speed"></param>
        /// <param name="life"></param>
        /// <param name="dir"></param>
        public GameObject(int x, int y, int width, int height, int speed, int life, Direction dir)
        {
            this.X = x;
            this.Y = y;
            this.Width = width;
            this.Height = height;
            this.Speed = speed;
            this.Life = life;
            this.Dir = dir;
        }
        public GameObject(int x, int y)
        {
            this.X = x;
            this.Y = y;
        }
        #region 公共属性: 横纵坐标、宽度、高度、速度、生命值、方向
        public int X { get; set; }
        public int Y { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
        public int Speed { get; set; }
        public int Life { get; set; }
        public Direction Dir { get;set;}
        #endregion

        //每个游戏对象在使用GDI+对象绘制自己到窗体的时候,绘制的方式都各不一样、。
        //所以我们需要在父类中提供一个绘制对象的抽象函数
        public abstract void Draw(Graphics g);

        //提供一个用于碰撞检测的函数 返回当前游戏对象的矩形
        public Rectangle GetRectangle()
        {
            return new Rectangle(this.X, this.Y, this.Width, this.Height);
        }

        public virtual void Move()
        {
后面还有 50 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。