C#프로그래밍
메딕이 마린 힐
노재두내
2023. 7. 24. 11:44
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LearnDotnet
{
internal class Medic
{
//맴버변수
int hp;
float heal;
float moveSpeed;
//생성자
public Medic(int hp, float heal, float moveSpeed)
{
this.hp = hp;
this.heal = heal;
this.moveSpeed = moveSpeed;
Console.WriteLine("메딕이 생성되었습니다.");
}
//메서드
public void MoveStop()
{
Console.WriteLine("메딕이 정지햇습니다.");
}
//걷기
public void Move()
{
Console.WriteLine("메딕이 움직였습니다.");
}
//치료
public void Heal(Marine marine)
{
Console.WriteLine("{0}을 치료했습니다",marine);
marine.Healmarine(this, this.heal);
}
//사망
public void Die()
{
Console.WriteLine("메딕이 사망했습니다.");
}
//상태출력
public void PrintProperties()
{
Console.WriteLine("생명력:{0}", this.hp);
Console.WriteLine("초당 치료량:{0}", this.heal) ;
Console.WriteLine("이동속도:{0}", this.moveSpeed);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LearnDotnet
{
internal class Marine
{
//맴버변수 : 객체의 생명주기동안 유지된다.
int hp;
int damage;
float moveSpeed;
int x;
int y;
//생성자
public Marine(int hp,int damage, float moveSpeed , int x, int y)
{
this.hp = hp; //매개변수의 값을 맴버변수에 할당
this.damage = damage;
this.moveSpeed = moveSpeed;
this.x = x;
this.y = y;
Console.WriteLine("마린이 생성되었습니다");
Console.WriteLine("위치:({0},{1})", this.x, this.y);
Console.WriteLine("생명력:{0}",this.hp);
Console.WriteLine("공격력:{0}", this.damage);
Console.WriteLine("이동속도:{0}", this.moveSpeed);
}
public void Move(int x, int y)// 이동 목표 좌표
{
//(5,0) ->(x,y)
Console.WriteLine("({0},{1})-> ({2},{3})로 이동했습니다.",this.x,this.y,x,y);
this.x = x;
this.y = y;
}
//왼족, 오른쪽 , 위 , 아래
//생명력을 반환하는 메서드
public int GetHp()
{
//반환하고 싶은 값
return this.hp;
}
public int GetDamage()
{
return this.damage;
}
public float GetMoveSpeed()
{
return this.moveSpeed;
}
//저글링을 공격하다
public void Attack(Zergling target)
{
Console.WriteLine("{0}을 공격했습니다.", target);
target.HitDamage(this,this.damage);//공격력 만큼 피해를 받는 메서드
}
//피해를 받는 메서드
public void HitDamage(int damage)
{
this.hp -= damage;
Console.WriteLine("피해를 받았습니다 {0}", this.hp);
}
public void Healmarine(Medic medic, float heal)
{
this.hp += (int)heal;
if(this.hp>=40)
{
Console.WriteLine("마린이 치료받았습니다.현재 hp: {0}", 40);
}
else
{
Console.WriteLine("마린이 치료받았습니다.guswo hp :{0}", this.hp);
}
}
public void PrintProperties()
{
Console.WriteLine("생명력:{0}", this.hp);
Console.WriteLine("공격력:{0}", this.damage);
Console.WriteLine("이동속도:{0}", this.moveSpeed);
Console.WriteLine("위치{0},{1}",this.x, this.y);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LearnDotnet
{
internal class App
{
//생성자
public App()
{
Marine marine= new Marine(40, 6, 1.8f, 5, 0);
marine.HitDamage(3);
Medic medic = new Medic(60, 5.8f, 1.8f);
medic.Heal(marine);
}
}
}