골드를 사용하여 체력을 회복하는 휴식기능을 구현하였습니다.
Character 클래스 - 회복기능 구현
캐릭터 클래스에 체력 회복을 위한 함수를 구현하였습니다.
//체력 얻음, 최대치를 넘지 못함
public void HealedHealth(float health)
{
float temp = HealthPoint + health;
HealthPoint = (temp > maxHealth) ? maxHealth : temp;
}
해당 함수는 회복량을 매개변수로 받으며, 최대체력을 넘는 회복을 시도할경우 체력을 최대체력값으로 변경합니다.
메인함수
마지막 케이스인 5번을 구현하였습니다.
이외의 입력 시도시 default로 처리하여 아무런 행동을 하지 않고 반복문의 시작점으로 돌아갈 예정입니다.
case 5:
{
//휴식기능
InnSelecter();
break;
}
휴식기능을 당담하는 함수입니다.
//휴식기능 함수
private static void InnSelecter()
{
Console.Clear();
TextCreater("[여관]");
TextCreater("골드를 사용하여 체력을 회복할 수 있습니다.");
Console.WriteLine();
string text = "500G 를 사용하여 체력 50을 회복합니다." + "(소지금 : " + playerChar.PlayerGold + "G)";
TextCreater(text);
Console.WriteLine();
TextCreater("1. 휴식하기\n0. 나가기");
Console.WriteLine();
TextCreater("행동을 입력해주세요");
if (InputInt(Console.ReadLine()) == 1)
{
Console.Clear();
TextCreater("[휴식하기]");
float health = playerChar.HealthPoint;
playerChar.HealedHealth(50);
Console.Write("Z");
Thread.Sleep(1000);
Console.Write("Z");
Thread.Sleep(1000);
Console.Write("Z");
Thread.Sleep(1000);
Console.Clear();
TextCreater("[회복 완료]");
TextCreater("충분한 휴식으로 체력이 회복되었습니다.");
Console.WriteLine();
text = "체력 : " + health + " -> " + playerChar.HealthPoint;
TextCreater(text);
Console.ReadLine();
Console.Clear();
}
else
{
Console.Clear();
}
}
회복을 선택할 때 출력해줄 텍스트 내용들입니다.
Console.Clear();
TextCreater("[여관]");
TextCreater("골드를 사용하여 체력을 회복할 수 있습니다.");
Console.WriteLine();
string text = "500G 를 사용하여 체력 50을 회복합니다." + "(소지금 : " + playerChar.PlayerGold + "G)";
TextCreater(text);
Console.WriteLine();
TextCreater("1. 휴식하기\n0. 나가기");
Console.WriteLine();
TextCreater("행동을 입력해주세요");
1번을 골라 회복을 선택했을 경우의 작동 코드입니다.
이외의 내용을 고르면 반복문의 시작점으로 돌아갑니다.
Console.Clear();
TextCreater("[휴식하기]");
float health = playerChar.HealthPoint;
playerChar.HealedHealth(50);
Console.Write("Z");
Thread.Sleep(1000);
Console.Write("Z");
Thread.Sleep(1000);
Console.Write("Z");
Thread.Sleep(1000);
Console.Clear();
TextCreater("[회복 완료]");
TextCreater("충분한 휴식으로 체력이 회복되었습니다.");
Console.WriteLine();
text = "체력 : " + health + " -> " + playerChar.HealthPoint;
TextCreater(text);
Console.ReadLine();
Console.Clear();
회복 연출을 보여주며 회복 전 체력을 저장하고 체력을 회복합니다.
연출이 종료되면 체력이 얼마나 회복되었는지를 보여줍니다.
체력 회복시 회복된 체력이 최대체력 수치를 넘지 않습니다.
회복의 구현을 마쳤습니다.
마지막으로 게임을 저장하고, 종료한뒤 다시 실행하면 내용을 불러오는 기능을 구현하는 과제만이 남았는데, 해당 기능을 구현할 때 캐릭터 정보와 상점 아이템 정보를 저장하고 불러와야하기 때문에 어떻게 구현할 지 고민을 해봐야하는 상태입니다.
'내일배움캠프 > 프로젝트' 카테고리의 다른 글
팀프로젝트 진행 - UGS 연결 (0) | 2024.11.27 |
---|---|
개인프로젝트 - 텍스트 RPG : 저장,불러오기 구현 (0) | 2024.09.24 |
개인프로젝트 - 텍스트RPG : 던전기능 구현 (0) | 2024.09.24 |
개인프로젝트 - 텍스트RPG : 상점 구현 (0) | 2024.09.23 |
개인프로젝트 - 텍스트 RPG : 장비 착용 구현 (0) | 2024.09.23 |