加载中...

c#:继承

写一个例子
基类敌人类(hp speed 方法 :move ai )派生出来两个类
boos类
type1enemy类


using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test_05_继承
{
    internal class Program
    {
      static void Main(string[] args)
       {
            Boss boss1= new Boss(100,10000,20);//创建boss类
           boss1.Print();*
       }
   }
}
----------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test_05_继承
{
    internal class Enemy
    {
        protected int hp;
        protected int speed;

        public void AI() 
        {
            Console.WriteLine("AI");
        }
        public void Move()
        {
            Console.WriteLine("Move");
        }
    }
}
-----------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test_05_继承
{
    internal class Tpye1Enemy:Enemy
    {
    }
}
posted @ 2024-07-25 22:04  神乐羊  阅读(15)  评论(0)    收藏  举报