c#/수업 내용

marine과 medic

yeeendy 2023. 1. 5. 12:20
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study04
{
    class App
    {
        //생성자
        public App()
        {
            Console.WriteLine("App");

            Marine marine0 = new Marine("marine0", 60, 5);
            marine0.Hit(35);
            Medic medic0 = new Medic("medic0", 5.86f, 50);
            medic0.Heal(marine0);

            Console.WriteLine("{0}, hp: {1}/{2}", marine0.name, marine0.hp, marine0.maxHp);
            Console.WriteLine("{0}, energy: {1}/{2}", medic0.name, medic0.energy, medic0.maxEnergy);
        
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study04
{
    class Medic
    {
        public string name;
        public int maxEnergy = 200;
        public int energy;
        public float heal;
        //생성자
        public Medic(string name, float heal, int energy)
        {
            this.name = name;
            this.energy = energy;
            this.heal = heal;
        }
        public void Heal(Marine target)
        {
            target.hp = target.hp + (int)this.heal;
            this.energy = this.energy - 5;
            //Console.WriteLine(this); //medic
            //Console.WriteLine(target); //marine
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study04
{
    
    class Marine
    {
        //속성,맴버 변수
        public int maxHp;
        public string name;
        public int damage;
        public int hp;
        //생성자 메서드
        public Marine(string name, int maxHp, int damage)
        {
            this.name = name;
            this.maxHp = maxHp;
            this.hp = this.maxHp;
            this.damage = damage;
            Console.WriteLine("{0}이 생성되었습니다.({1}/{2})", this.name, this.hp, this.maxHp);
            Console.WriteLine("공격력:{0}", this.damage);
        }
        //맴버 메서드
        public void Attack(Marine target)
        {
            //Console.WriteLine(this);
            //Console.WriteLine(target);
            Console.WriteLine("{0}이(가){1}를 공격 했습니다.", this.name, target.name);
            //target.hp = target.hp - this.damage;
            //Console.WriteLine("{0} 체력 : ({1}/{2})", target.name, target.hp, target.maxHp);
            target.Hit(this.damage);
        }
        public void Hit(int damage)
        {
            Console.WriteLine("피해({0})를 받았습니다.", damage);
            this.hp=this.hp - damage;
            Console.WriteLine("{0}체력 : {1}/{2}", this.name, this.hp, this.maxHp);
        }
        public void Move()
        {
            Console.WriteLine("이동했습니다.");
        }
    }
    
}

'c# > 수업 내용' 카테고리의 다른 글

값을 반환하기(ex, 총알 , 코인, 템플러 머지)  (0) 2023.01.06
Siege Tank  (0) 2023.01.05
마인  (0) 2023.01.04
고블린 사냥  (0) 2023.01.03
별찍기2  (0) 2023.01.03