닫기

커뮤니티

EA SPORTS FC ONLINE에 대해 이야기 나누세요.
ㄱㄷㅂrank091 맨시티는레전드11.24(월)조회 252비추천 0

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("애완동물 기르기 게임에 오신걸 환영합니다");
        Console.Write("애완동물 이름을 정해주세요 : ");
        string pet_name = Console.ReadLine();

        Pet pet = new Pet(pet_name);

        while (true)
        {
            Console.WriteLine("\n 액션을 선탁하세요");
            Console.WriteLine("1. 애완동물 상태 확인");
            Console.WriteLine("2. 먹이 주기");
            Console.WriteLine("3. 놀아주기 ");
            Console.WriteLine("4. 게임종료");

            string choice = Console.ReadLine();
            switch(choice)
            {
                case "1":
                    pet.ShowStatus();
                    break;
                case "2":
                    pet.Feed();
                    break;

                case "3":
                    pet.Play();
                    break;

                case "4":
                    Console.WriteLine("게임을 종료합니다 안녕히가세요");
                    return;
                default:
                    Console.WriteLine("잘못된 입력입니다. 다시 선택해주세요");
                    break;
              
            }
        }
    }
}

public class Pet
{
    public string Name;
    private int health;
    private int happiness;
    private int hunger;
   
    public Pet(string name)
    {
        Name = name;
        health = 100;
        happiness = 50;
        hunger = 50;
    }
    public void ShowStatus()
    {
        Console.WriteLine($"\n[{Name}의 상태]");
        Console.WriteLine($"체력:{health}");
        Console.WriteLine($"행복도:{happiness}");
        Console.WriteLine($"배부름:{hunger}");
    }
    public void Feed ()
    {
        Console.WriteLine($"\n{Name}에게 먹이를 줍니다");
        happiness += 5;
        hunger += 10;
        Console.WriteLine($"{Name}이(가) 만족해합니다.배부름:{hunger}");
    }
    public void Play()
    {
        Console.WriteLine($"\n{Name}와(과) 놀아줍니다");
        health -= 5;
        happiness += 10;
        hunger -= 15;
        Console.WriteLine($"{Name}이(가) 즐거워합니다. 행복도:{happiness}, 체력:{health}, 배부름:{hunger}");
    }
}

0 0
댓글 0
0/200