스토리지

과제 2 본문

Unity/수업과제

과제 2

ljw4104 2021. 3. 9. 18:23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace study00
{
    class Class1
    {
        /* 테란 vs 프로토스
         * 프로토스 상대진영에 전진게이트를 설치 
         * 테란 배럭 생성
         */
        static void Main(string[] args)
        {
            int terranMineral, protossMineral;
            terranMineral = protossMineral = 100;

            Console.WriteLine("커맨더센터가 생성되었습니다.");
            int terranPeople = 0;
            int maxTerranPeople = 10;
            for (int i = 0; i < 4; i++)
            {
                if (terranPeople > maxTerranPeople)
                {
                    Console.WriteLine("서플라이 디팟을 건설하세요.");
                }
                else
                {
                    Console.WriteLine("SCV_{0}가 생성되었습니다.", i + 1);
                    terranPeople++;
                }
            }

            Console.WriteLine("넥서스가 생성되었습니다.");
            int protossPeople = 0;
            int maxProtossPeople = 10;
            for (int i = 0; i < 4; i++)
            {
                if (protossPeople > maxProtossPeople)
                {
                    Console.WriteLine("파일런을 건설하세요.");
                }
                else
                {
                    Console.WriteLine("PROBE_{0}가 생성되었습니다.", i + 1);
                    protossPeople++;
                }
            }

            int requirePylon = 100;
            if(protossMineral >= requirePylon)
            {
                Console.WriteLine("파일런을 건설합니다.");
                protossMineral -= requirePylon;

                for(int i = 10; i <= 100; i += 10)
                {
                    Console.WriteLine("파일런 건설중 {0}%", i);
                }
                Console.WriteLine("파일런 건설 완료.");
            }
            else
            {
                while(protossMineral < requirePylon)
                {
                    Console.WriteLine("프로브가 미네랄을 채취합니다. +8");
                    protossMineral += 8;
                }
            }

            int requireBarrack = 150;
            while(terranMineral < requireBarrack)
            {
                Console.WriteLine("SCV가 미네랄을 채취합니다. +8");
                terranMineral += 8;
            }

            Console.WriteLine("배럭을 건설합니다.");
            terranMineral -= requireBarrack;
            for (int i = 10; i <= 100; i += 5)
            {
                Console.WriteLine("배럭 건설중 {0}%", i);
            }
            Console.WriteLine("배럭 건설 완료.");

            int requireGateway = 150;
            while (protossMineral < requireGateway)
            {
                Console.WriteLine("프로브가 미네랄을 채취합니다. +8");
                protossMineral += 8;
            }

            Console.WriteLine("게이트웨이을 건설합니다.");
            protossMineral -= requireGateway;
            for (int i = 10; i <= 100; i += 5)
            {
                Console.WriteLine("게이트웨이 건설중 {0}%", i);
            }
            Console.WriteLine("게이트웨이 건설 완료.");
        }
    }
}

 

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

namespace study00
{
    class Class1
    {
        /* 
         * 뮤탈 하나 vs 마린 & 메딕 (모든 유닛 공업 등 업그레이드 안되어 있다고 판단)
         * 메딕은 자힐이 안되므로 메딕사망 후 마린 사망.
         * 아카데미는 없음 (스팀팩 x)
         */
        static void Main(string[] args)
        {
            int mutaliskHp = 120;
            const int mutaliskAttack = 9;

            int marineHp = 40;
            const int marineAttack = 6;

            int medicHp = 60;
            int medicEnergy = 50;
            int maxMedicEnergy = 200;
            int medicHeal = 2;
            int medicHealEnergy = 5;

            bool turn = false;
            while (true)
            {
                if (mutaliskHp <= 0)
                {
                    mutaliskHp = 0;
                    Console.WriteLine("뮤탈리스크 사망");
                    break;
                }
                else if (marineHp <= 0)
                {
                    Console.WriteLine("마린 사망");
                    break;
                }

                if (turn)
                {
                    if(medicHp > 0)
                        Console.WriteLine("뮤탈이 마린과 메딕을 공격합니다.");
                    else
                        Console.WriteLine("뮤탈이 마린을 공격합니다.");
                    marineHp -= mutaliskAttack;
                    medicHp -= mutaliskAttack;

                    if(marineHp < 0)
                    {
                        marineHp = 0;
                    }
                    if(medicHp < 0)
                    {
                        medicHp = 0;
                    }
                    Console.WriteLine("마린 체력 : {0}, 메딕 체력 : {1}", marineHp, medicHp);

                    if (marineHp > 0 && medicHp > 0 && medicEnergy > medicHealEnergy)
                    {
                        Console.WriteLine("마린이 힐을 받습니다.");
                        while(medicEnergy > medicHealEnergy)
                        {
                            marineHp += medicHeal;
                            medicEnergy -= medicHealEnergy;
                            if(marineHp < 40)
                            {
                                marineHp = 40;
                                break;
                            }
                        }
                        Console.WriteLine("메딕 에너지 ({0}/{1})", medicEnergy, maxMedicEnergy);
                        Console.WriteLine("마린 체력 : {0}, 메딕 체력 : {1}", marineHp, medicHp);
                    }
                }
                else
                {
                    Console.WriteLine("마린이 뮤탈을 공격합니다.");
                    
                    mutaliskHp -= marineAttack;
                    Console.WriteLine("뮤탈 체력 : {0}", mutaliskHp);
                }

                Console.WriteLine();
                turn = !turn;
            }

        }
    }
}

 

 

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

namespace Study00
{
    class Program
    {
        /*
         * 테란의 배틀크루저가 마지막 남은 해처리를 공격함
         * 그 해처리에서는 스커지가 계속 생산되어 배틀크루저를 공격함.
         * 스커지는 배틀크루저만 공격하고 배틀크루저(공 1업)는 해처리만 공격함.
         * 스커지는 2마리씩 공격한다고 가정함.
         * 인구수는 자원에서 취급하지 않음
         */
        static void Main(string[] args)
        {
            int scourgeAttack = 110;
            int battleCruiserAttack = 28;
            int yamatoGunAttack = 260;
            int requireScourgeMineral = 25;
            int requireScourgeGas = 75;

            int terranMineral = 400;
            int terranGas = 300;
            int zergMineral = 200;
            int zergGas = 200;

            int numScourge = 0;
            int numLarva = 3;

            int hatcheryHp = 1250;
            int battleCruiserHp = 500;
            int battleCruiserEnergy = 100;
            int maxBattleCruiserEnergy = 200;
            int requireYamatoGun = 200;
            int energyPerTurn = 5;

            int numSCV = 9;
            int numDrone = 9;

            bool turn = default;
            while (true)
            {
                if(battleCruiserHp <= 0)
                {
                    Console.WriteLine("저그 승리");
                    break;
                }
                if(hatcheryHp <= 0)
                {
                    Console.WriteLine("테란 승리");
                    break;
                }
                if (turn)
                {
                    // 테란차례
                    Console.WriteLine("배틀크루저가 해처리를 공격합니다.");
                    if(requireYamatoGun == battleCruiserEnergy)
                    {
                        Console.WriteLine("야마토 건 발사.");
                        hatcheryHp -= yamatoGunAttack;
                        battleCruiserEnergy = 0;
                    }
                    else
                    {
                        hatcheryHp -= battleCruiserAttack;
                    }
                    
                    if(battleCruiserEnergy < maxBattleCruiserEnergy)
                    {
                        battleCruiserEnergy += energyPerTurn;
                        if (battleCruiserEnergy > maxBattleCruiserEnergy)
                            battleCruiserEnergy = maxBattleCruiserEnergy;
                    }
                }
                else
                {
                    //저그차례
                    //스커지가 한마리도 없을때는 스커지 생산만 가능
                    if(numScourge == 0)
                    {
                        Console.WriteLine("스커지가 없기때문에 스커지를 생산합니다.");
                        while(zergMineral >= requireScourgeMineral && zergGas >= requireScourgeGas)
                        {
                            if(numLarva > 0)
                            {
                                numLarva--;
                                numScourge += 2;
                                zergMineral -= requireScourgeMineral;
                                zergGas -= requireScourgeGas;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("스커지가 배틀크루저를 공격합니다.");
                        while (numScourge / 2 > 0)
                        {
                            battleCruiserHp -= scourgeAttack;
                            numScourge -= 2;
                        }

                        numLarva += 3 - numLarva;
                    }
                    Console.WriteLine("스커지 마릿수 : {0}", numScourge);
                }
                terranMineral += (numSCV - 3) * 8;
                terranGas += (numSCV - 6) * 3;
                zergMineral += (numDrone - 3) * 8;
                zergGas += (numDrone - 6) * 3;
				
                if (battleCruiserHp < 0) battleCruiserHp = 0;
                if (hatcheryHp < 0) hatcheryHp = 0;
                Console.WriteLine("배틀크루저 체력 : {0}, 해처리 체력 : {1}", battleCruiserHp, hatcheryHp);
                Console.WriteLine();
                turn = !turn;
            }
        }
    }
}

 

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

namespace Study01
{
    class Program
    {
        /*
         * 강화 시뮬레이션 (메이플스토리의 스타포스)
         * 초기 자금은 200억으로 시작.
         * 장비의 레벨은 150제로 하며
         * 강화 비용은 
         * 9성까지 1000 + L^3(S+1) / 25 (S는 현재 강화단계)
         * 14성까지 1000 + L^3 * ((S+1)^2.7) / 400
         * 22성까지 1000 + L^3*((S+1)^2.7) / 200 으로 한다.
         * 0강부터 22강까지 존재.
         * 연속 2번으로 실패했을 시에 다음 것은 무조건 성공하는 실패보정이 있음.
         * 
         * 12성부터는 파괴확률이 존재함.
         * 아이템 파괴시 그대로 프로그램 종료.
         * 10성, 15성, 20성에서는 실패해도 단계가 하락되지 않는 대신에 실패보정이 없음.
         */
        static double IntRound(double value, int digit)
        {
            double Temp = Math.Pow(10.0, digit);
            return Math.Round(value * Temp) / Temp;
        }

        static void Main(string[] args)
        {
            var weaponLevel = 150;
            var money = 20000000000;
            var level = 0;
            int[] destroyProbability = new int[]
            {
                1,1,1,2,2,2,3,3,7,7
            };
            int[] probability = new int[] {95,90,85,85,80,75,70,65,60,55,
                45,35,30,30,30,30,30,30,30,30,30,30
            };
            Random r = new Random();

            Console.Write("초기 자금 : ");
            Console.WriteLine(string.Format("{0:n0}", money));
            Console.WriteLine();

            int successNum = 0;
            int failNum = 0;

            int failCount = 0;
            while (level < 22)
            {
                double cost;
                if (level < 10)
                {
                    cost = 1000 + (Math.Pow(weaponLevel, 3) * (level + 1)) / 25;
                }
                else if (level < 15)
                {
                    cost = 1000 + (Math.Pow(weaponLevel, 3) * Math.Pow((level + 1), 2.7)) / 400;
                }
                else
                {
                    cost = 1000 + (Math.Pow(weaponLevel, 3) * Math.Pow((level + 1), 2.7)) / 200;
                }

                cost = IntRound(cost, -2);

                int prob = r.Next(1, 101);
                if (cost > money)
                {
                    Console.WriteLine("소유금액 없음");
                    break;
                }

                Thread.Sleep(300);
                money -= (long)cost;
                if ((failCount == 2 && (level != 10 || level != 15 || level != 20)) || probability[level] >= prob)
                {
                    if (failCount == 2)
                    {
                        Console.Write("★실패보정 들어감.");
                    }
                    Console.WriteLine("강화 성공 : {0} -> {1}", level, ++level);
                    successNum++;
                    failCount = 0;
                }
                else
                {
                    if (level >= 12 && prob < destroyProbability[level - 12] + probability[level])
                    {
                        Thread.Sleep(2000);
                        Console.WriteLine("장비가 파괴되었습니다.({0}강), 확률 : {1}%", level, destroyProbability[level - 12]);
                        break;
                    }

                    if (level < 11 || level == 15 || level == 20)
                    {
                        Console.WriteLine("강화 실패 : {0}", level);
                    }
                    else
                    {
                        Console.WriteLine("강화 실패 : {0} -> {1}", level, --level);
                        failCount++;
                    }
                    failNum++;
                }
            }
            Console.WriteLine();
            Console.Write("사용금액 : ");
            Console.WriteLine(string.Format("{0:n0}", 100000000000 - money));
            Console.WriteLine("{0}성까지의 성공횟수 : {1}, 실패횟수 : {2}", level, successNum, failNum);
        }
    }
}

 

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

namespace Study00
{
    class Program
    {
        /*
         * 러시안 룰렛
         * 포트리스처럼 대포를 쏨
         * 두 대포는 랜덤한 데미지를 가짐
         */
        static void Main(string[] args)
        {
            Random r = new Random();

            int aHp = 100;
            int bHp = 100;

            int aDamage;
            int bDamage;

            while (true)
            {
                if (aHp == 0 && bHp == 0)
                {
                    Console.WriteLine("공멸");
                    break;
                }
                else if (aHp == 0)
                {
                    Console.WriteLine("B의 승리");
                    break;
                }
                else if (bHp == 0)
                {
                    Console.WriteLine("A의 승리");
                    break;
                }

                aDamage = r.Next(1, 11);
                bDamage = r.Next(1, 11);

                aHp -= bDamage;
                bHp -= aDamage;

                if (aHp < 0) aHp = 0;
                if (bHp < 0) bHp = 0;
                Console.WriteLine("A의 체력 : {0}, B의 체력 : {1}", aHp, bHp);
            }
        }
    }
}

 

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

namespace Study00
{
    class Program
    {
        /*
         * 러시안 룰렛
         * 계속 돌아가며 방아쇠를 잡아당김
         * 확률은 1/7
         */
        static void Main(string[] args)
        {
            Random r = new Random();
            bool[] probability = new bool[7];
            int ranIndex = r.Next(0, 7);
            probability[ranIndex] = true;

            bool turn = false;
            int i = 0;
            while (true)
            {
                if (!turn)
                {
                    Console.WriteLine("방아쇠를 당깁니다.");
                    if (probability[i])
                    {
                        Console.WriteLine("당신은 사망하였습니다.");
                        break;
                    }
                    Console.WriteLine("당신은 생존하였고 상대방에게 턴을 넘겼습니다.");
                    i++;
                    turn = !turn;
                }
                else
                {
                    Console.WriteLine("방아쇠를 당깁니다.");
                    if (probability[i])
                    {
                        Console.WriteLine("상대방은 사망하였습니다.");
                        break;
                    }
                    Console.WriteLine("상대방은 생존하였고 당신에게 턴을 넘겼습니다.");
                    i++;
                    turn = !turn;
                }
            }
        }
    }
}

 

 

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

namespace Study00
{
    class Program
    {
        /*
         * 속업된 저글링이 몇마리 와야 커맨드센터가 파괴될까?
         * 초기엔 4마리로 공격함.
         */
        static void Main(string[] args)
        {
            int zerglingAttack = 5;
            int zerglingNum = 4;
            int commandHp = 1500;

            int timer = 0;
            int zerglingSpeed = 200;
            bool isFast = false;
            while (commandHp > 0)
            {
                if(timer % zerglingSpeed == 0)
                {
                    Console.WriteLine("커맨드센터 : {0}", commandHp);
                    commandHp -= zerglingNum * zerglingAttack;
                }

                timer += 10;

                if (timer % zerglingSpeed / 4 == 0)
                    zerglingNum++;

                if(!isFast && commandHp > 0 && ((float)commandHp / (float)1500f * 100 < 50))
                {
                    zerglingSpeed /= 3;
                    if (zerglingSpeed == 0) zerglingSpeed = 1;
                    Console.WriteLine("저글링 속업 완료.");
                    isFast = !isFast;
                }
            }

            Console.WriteLine("커맨드 센터 부서짐, 시간 : {0}", timer);
        }
    }
}

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

과제 6  (0) 2021.03.16
과제 5  (0) 2021.03.14
과제 4  (0) 2021.03.12
과제3  (0) 2021.03.10
과제 1  (0) 2021.03.09
Comments