C#/C#언어

다양한 상황 만들기 연습

minquu 2021. 3. 10. 00:01
반응형

SCV 생성

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study01
{
    class Program
    {
        static void Main(string[] args)
        {


            string commandNmae = "커멘드센터";
            int commandHp = 1500;
            string scvName = "SCV";
            int scvHp = 45;

            Console.WriteLine("{0}가 생성되었습니다.", commandNmae);
            Console.WriteLine("{0} ({1} / {2})", commandNmae, commandHp, commandHp);

            for (int i = 0; i < 10; i++)
            {
                if (i < 5)
                    Console.WriteLine("{0}_{1}가 생성되었습니다. ({2} / {3})", scvName, i, scvHp, scvHp);


            }
        }
    }
}

 

저글링 사망

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study01
{
    class Program
    {
        static void Main(string[] args)
        {

            string unitNameMarine = "마린";
            int marineDamage = 2;
            int marineMaxHp = 10;
            int marineHp = marineMaxHp;
            string unitNameZergling = "저글링";
            int zerglingDamage = 1;
            int zerglingMaxHp = 5;
            int zerglingHp = zerglingMaxHp;


            zerglingHp -= marineDamage;
            var per = (float)zerglingHp / zerglingMaxHp * 100f;
            Console.WriteLine("{0}이 {1}을 공격({2})했습니다. ({3} / {4}) {5}%", unitNameMarine, unitNameZergling, marineDamage, zerglingHp, zerglingMaxHp, per);
            zerglingHp -= marineDamage;
            var per1 = (float)zerglingHp / zerglingMaxHp * 100f;
            Console.WriteLine("{0}이 {1}을 공격({2})했습니다. ({3} / {4}) {5}%", unitNameMarine, unitNameZergling, marineDamage, zerglingHp, zerglingMaxHp, per1);
            zerglingHp = 0;
            var per2 = (float)zerglingHp / zerglingMaxHp * 100f;
            Console.WriteLine("{0}이 {1}을 공격({2})했습니다. ({3} / {4}) {5}%", unitNameMarine, unitNameZergling, marineDamage, zerglingHp, zerglingMaxHp, per2);

            if (zerglingHp <= 0)
            {

                Console.WriteLine("{0}이 죽었습니다.", unitNameZergling);
            }


        }
    }
}

 

 

서플라이디폿만들기

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study02
{
    class Program
    {
        static void Main(string[] args)
        {



            int mineral = 90;
            int gas = 200;
            string unitSCV = "SCV";
            int maxPopulation = 10;
            int population = 0;
            int supplyDemandMineral = 100;

            Console.WriteLine("미네랄 : {0}", mineral);
            Console.WriteLine("가스 : {0}", gas);
            Console.WriteLine("{0}가 생성되었습니다.", unitSCV);

            population++;
            Console.WriteLine("인구수 : {0} / {1}", population, maxPopulation);
            Console.WriteLine("서플라이디폿 정보");
            Console.WriteLine("필요 미네랄 : {0}", supplyDemandMineral);
            Console.WriteLine("{0}가 서플라이디폿을 건설을 시도 합니다.", unitSCV);

            if (mineral >= supplyDemandMineral)
            {

                Console.WriteLine("{0}가 서플라이디폿을 건설합니다.", unitSCV);

            }
            else
            {

                Console.WriteLine("미네랄이 부족합니다.");

            }


            mineral += 8;
            Console.WriteLine("{0}가 미네랄을 캤습니다. +8", unitSCV);
            Console.WriteLine("미네랄 : {0}", mineral);
            mineral += 8;
            Console.WriteLine("{0}가 미네랄을 캤습니다. +8", unitSCV);
            Console.WriteLine("미네랄 : {0}", mineral);
            Console.WriteLine("{0}가 서플라이디폿을 건설을 시도 합니다.", unitSCV);

            if (mineral >= supplyDemandMineral)
            {
                mineral -= 100;
                Console.WriteLine("미네랄 : {0}", mineral);
                for (int i = 0; i < 100; i += 5)
                    Console.WriteLine("{0}가 서플라이디폿을 건설합니다. {1}%", unitSCV, i + 5);

                Console.WriteLine("서플라이디폿이 완성 되었습니다.");
                maxPopulation += 8;
                Console.WriteLine("인구수 : {0} / {1}", population, maxPopulation);
            }
            else
            {

                Console.WriteLine("미네랄이 부족합니다.");

            }

        }

    }
}

 

 

 

반응형

'C# > C#언어' 카테고리의 다른 글

4일차_수업내용  (0) 2021.03.11
4일차_클래스 예제연습  (0) 2021.03.11
3일차 _ 메서드 연습 예제  (0) 2021.03.10
3일차_수업_매서드(ReadLine)  (0) 2021.03.10
2일차_수업내용  (0) 2021.03.09