c#/수업 과제

메서드 연습4

yeeendy 2023. 1. 3. 23:58
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study01
{
    class App
    {
        float nextExp = 115f;
        float myExp = 89.5f;
        int maxLevel = 2;
        int level = 1;
        float maxExp = 115f;
        public App()
        {
            Console.WriteLine("App");

            GetExp(19f);
            GetExp(33.14f);
            GetExp(33.14f);
        }
        void GetExp(float num)
        {


            if (level >= maxLevel)
            {
                Console.WriteLine("최대 레벨에 도달했습니다.");
            }
            else
            {
                if (myExp + num < nextExp)
                {
                    Console.WriteLine("경험치({0})를 획득했습니다.  ({1:0.00}/{2}) {3:0}%", num, myExp + num, nextExp, (myExp + num) / nextExp * 100);
                }
                else if (myExp + num >= maxExp)
                {
                    Console.WriteLine("경험치({0})를 획득했습니다.  ({1}/{2}) {3}%", num, maxExp, nextExp, 100);
                    Console.WriteLine("레벨업을 했습니다.");
                    level = level + 1;
                    Console.WriteLine("{0}레벨이 되었습니다.", level);
                }
            }
        }
        //경험치(19)를 획득 했습니다.    (108.50/115) 94%
        //경험치(33.14)를 획득 했습니다.    (115/115) 100%
        //레벨업을 했습니다. 
        //2레벨이 되었습니다.   
        //최대 레벨에 도달 했습니다.



    }
}

'c# > 수업 과제' 카테고리의 다른 글

뿔버섯  (0) 2023.01.04
주황버섯  (0) 2023.01.04
메서드 연습3  (0) 2023.01.03
메서드 연습2  (0) 2023.01.03
메서드 연습1  (0) 2023.01.03