C#/수업 내용

2021-08-19 연습문제

JSH1 2021. 8. 19. 16:59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace hello_world
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("[1.공격, 2.스킬, 3.도망]: ");
            int choice = Convert.ToInt32(Console.ReadLine());

            if (choice == 1)
                Console.WriteLine("공격을 시도합니다.");
            else if (choice == 2)
                Console.WriteLine("스킬을 시전합니다.");
            else if (choice == 3)
                Console.WriteLine("도망을 시도합니다.");
            else
                Console.WriteLine("잘못된 선택지입니다.");
        }
    }
}


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

namespace hello_world
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("갈 수 있는 곳은 안내실, 승강기, 공원 입니다.");
            string choice = Console.ReadLine();

            if (choice == "안내실")
                Console.WriteLine("안내실로 이동하기 시작했다.");
            else if (choice == "승강기")
                Console.WriteLine("승강기는 작동을 멈춘 거 같다.");
            else if (choice == "공원")
                Console.WriteLine("공원으로 이동하기 시작했다.");
            else
                Console.WriteLine("잘못된 선택지입니다.");
        }
    }
}


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

namespace hello_world
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("아이템 목록: 도끼, 활, 창");
            string choice = Console.ReadLine();

            if (choice == "도끼")
                Console.WriteLine("도끼를 장착했습니다.");
            else if (choice == "활")
                Console.WriteLine("활을 장착했습니다.");
            else if (choice == "창")
                Console.WriteLine("창을 장착했습니다.");
            else
                Console.WriteLine("{0}은 없는 아이템입니다.", choice);
        }
    }
}


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

namespace hello_world
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("배럭");
            Console.WriteLine("[M:마린], [B:파이어뱃], [G:고스트]");
            Console.Write("생산하려는 유닛의 단축키를 입력하세요: ");
            
            ConsoleKeyInfo info = Console.ReadKey();
            Console.WriteLine("");

            if (info.Key.ToString() == "M")
                Console.WriteLine("마린을 생산합니다.");
            else if (info.Key.ToString() == "B")
                Console.WriteLine("파이어뱃을 생산합니다.");
            else if (info.Key.ToString() == "G") 
                Console.WriteLine("자원이 부족합니다.");
            else
                Console.WriteLine("{0}는 단축키에 없습니다.", info.Key.ToString());
        }
    }
}


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

namespace hello_world
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 10;
            bool select = false;

            while(!select)
            {
                Console.WriteLine("주문하려는 갯수: {0}", count);
                Console.WriteLine("+ 누르면 갯수 1개 증가");
                Console.WriteLine("- 누르면 갯수 1개 감소");
                Console.WriteLine("\n");
                Console.Write("주문하려면 Enter를 눌러주세요: ");
                ConsoleKeyInfo info = Console.ReadKey();
                Console.WriteLine("\n==================================");

                if (info.KeyChar == '+')
                    count++;
                else if (info.KeyChar == '-')
                    count--;
                else if (info.Key.ToString() == "Enter")
                    break;

            }
            Console.WriteLine("{0}개 주문했습니다.", count);
        }
    }
}


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

namespace hello_world
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("게임을 종료 하시겠습니까? (1.종료, 2.취소): ");
            ConsoleKeyInfo info = Console.ReadKey();
            Console.WriteLine("");

            if (info.KeyChar == '1')
                Console.WriteLine("게임을 종료합니다.");
            else if (info.KeyChar == '2')
                Console.WriteLine("취소합니다.");
            else
                Console.WriteLine("잘못된 명령어입니다.");
        }
    }
}


 

'C# > 수업 내용' 카테고리의 다른 글

2021-08-20 오전  (0) 2021.08.20
[C#] Random  (0) 2021.08.20
[C#] else if  (0) 2021.08.19
[C#] if  (0) 2021.08.19
[C#] 논리 연산자  (0) 2021.08.19