'C#/실습'에 해당되는 글 45건

  1. 2019.10.02 10.02 버거세트
  2. 2019.10.02 10.02 커피상점
  3. 2019.10.01 10.01 커맨드센터에서 SCV1,2를 만들고 공격하기
  4. 2019.10.01 10.01 여러 class를 이용해 햄버거 세트 만들기
  5. 2019.09.27 워크래프트 캐릭생성하기
  6. 2019.09.26 switch 문
  7. 2019.09.24 09.24 최대공약수 구하기
  8. 2019.09.23 09.23 상점 구매하기 및 판매하기

10.02 버거세트

C#/실습 2019. 10. 2. 17:29

예제:

코드:

 

1
2
3
4
5
6
7
8
9
10
class App
    {
        public App()
        {
            Burger burger = new Burger("더블치즈버거");
            Drink drink = new Drink("콜라");
            Side side = new Side("감자칩");
            new Set(burger, drink, side);                       
        }
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
9
class Burger
    {
        public string name;
        public Burger(string name)
        {
            this.name = name;
            Console.WriteLine(this.name + "이(가) 생성되었습니다.");
        }
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
9
class Drink
    {
        public string name;
        public Drink(string name)
        {
            this.name = name;
            Console.WriteLine(this.name + "이(가) 생성되었습니다.");
        }
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
9
class Side
    {
        public string name;
        public Side(string name)
        {
            this.name = name;
            Console.WriteLine(this.name + "이(가) 생성되었습니다.");
        }
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Set
    {
        Burger burger;
        Drink drink;
        Side side;
        public Set(Burger burger, Drink drink, Side side)
        {
            this.burger = burger;
            this.drink = drink;
            this.side = side;
            Console.WriteLine(this.burger.name + "세트가 생성되었습니다.");
            Console.WriteLine(this.burger.name + "세트의 구성품은 " + this.burger.name + this.drink.name + this.side.name + " 입니다.");
        }
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
:

10.02 커피상점

C#/실습 2019. 10. 2. 17:24

예제:

커피상점을 만들어 그 커피상점은 커피, 슬리브, 빨대를 만든다.

커피상점이 만든 커피, 슬리브, 빨대를 손님에게 준다.

주는 기능은 커피상점이 갖고있다.

예제:

코드:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System;
namespace _10._02_lvl3_CoffeShop
{
    class App
    {
        public App()
        {
            CoffeeShop coffeeShop = new CoffeeShop("스타벅스");
            Coffee coffee1 = coffeeShop.GetCoffee("아메리카노");
            sleeve sleeve1 = coffeeShop.Getsleeve("LONDON 로고 슬리프");
            straw straw1 = coffeeShop.Getstraw("친환경 종이 빨대");
        }
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
 
namespace _10._02_lvl3_CoffeShop
{
    class CoffeeShop
    {
        public string name;       
        public CoffeeShop(string name)
        {
            this.name = name;
            Console.WriteLine(this.name + "이(가) 생성되었습니다.");
        }
        public Coffee GetCoffee(string coffee)
        {
            Coffee coffee1 = new Coffee(coffee);
            return coffee1;
        }
        public sleeve Getsleeve(string sleeve)
        {
            sleeve sleeve1 = new sleeve(sleeve);
            return sleeve1;
 
        }
        public straw Getstraw(string straw)
        {
            straw straw1 = new straw(straw);
            return straw1;
 
        }
        public void Give(Coffee coffee, sleeve sleeve, straw straw)
        {
            Console.WriteLine($"{coffee.name}에 {sleeve.name}(을)를 껴서 {straw.name}를 꼽고 손님에게 드렸습니다.");
 
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
9
10
11
12
    class Coffee
    {
        public string name;
        public Coffee(string name)
        {
            this.name = name;
            Console.WriteLine(this.name + "이(가) 만들어졌습니다.");
 
        }
    }
 
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
9
10
11
class sleeve
    {
        public string name;
        public sleeve(string name)
        {
            this.name = name;
            Console.WriteLine(this.name + "이(가) 생성되었습니다.");
        }
    }
 
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
9
class straw
    {
        public string name;
        public straw(string name)
        {
            this.name = name;
            Console.WriteLine(this.name + "이(가) 생성되었습니다.");
        }
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
:

10.01 커맨드센터에서 SCV1,2를 만들고 공격하기

C#/실습 2019. 10. 1. 16:49

예제:

코드:

Program.cs:
namespace _10._01_step2
{
    class Program
    {
        static void Main(string[] args)
        {
            new App();//App타입 객체를 생성하고 App()이라는 메소드를 호출한다
        }
    }
}

 

App.cs:

namespace _10._01_step2
{
    class App
    {
        public App()
        {
            CommandCenter commandCenter1 = new CommandCenter();
            Console.WriteLine(commandCenter1 + "가 생성되었습니다.");
            Unit unit1 = commandCenter1.MakeUnit("SCV1");
            Unit unit2 = commandCenter1.MakeUnit("SCV2");
            unit1.Attack(unit2);
        }
    }
}

CommandCenter.cs:

namespace _10._01_step2
{
    class CommandCenter
    {
        int hp;

        public CommandCenter()
        {

        }
        public Unit MakeUnit(string name)
        {
            Unit unit = new Unit();
            unit.name = name;
            Console.WriteLine(unit.name + "이 생성되었습니다.");
            return unit;
        }
    }
}

Unit.cs:

using System;

namespace _10._01_step2
{
    class Unit
    {
        //데이터
        public string name;
        int hp =100;
        int maxHp = 100;
        int damage=5;
        public Unit()
        {

        }
        //메서드
        //이동한다
        public void Move()
        {

        }
        public void Attack(Unit unit)
        {
            Console.WriteLine($"{this.name}이{unit.name}에게 {damage}만큼의 피해를 입혔습니다.");
            unit.GetHit(this.damage);
        }
        public void GetHit(int damage)
        {
            this.hp = this.hp - damage;
            Console.WriteLine($"{this.name}이 {damage}만큼의 피해를 입었습니다.");
            Console.WriteLine(this.hp + "/" + this.maxHp);
        }
    }
}

'C# > 실습' 카테고리의 다른 글

10.02 버거세트  (0) 2019.10.02
10.02 커피상점  (0) 2019.10.02
10.01 여러 class를 이용해 햄버거 세트 만들기  (0) 2019.10.01
워크래프트 캐릭생성하기  (0) 2019.09.27
switch 문  (0) 2019.09.26
:

10.01 여러 class를 이용해 햄버거 세트 만들기

C#/실습 2019. 10. 1. 16:45

세트로 만들지 여부 확인
Set 클라스의 인스턴스를 이용해 메뉴를 한 클라스에 묶는다.

Program.cs:

namespace _10._01_step4
{
    class Program
    {
        static void Main(string[] args)
        {
            new App();
        }
    }
}

App.cs:

using System;


namespace _10._01_step4
{
    class App
    {
        public App()
        {
            BurgerShop burgerShop1 = new BurgerShop();
burgerShop1.name = "McDonalds";
            Console.WriteLine("버거를 입력해주세요: ");
            Burger burger1 = burgerShop1.MakeBurger(Console.ReadLine());
            Console.WriteLine("사이드메뉴를 입력해주세요");
            PotatoChip potatoChip1 = burgerShop1.MakePotatoChip(Console.ReadLine());
            Console.WriteLine("음료를 입력해주세요");
            Drink drink1 = burgerShop1.MakeDrink(Console.ReadLine());
            Console.WriteLine(burger1.name + "이(가) 생성되었습니다.");
            Console.WriteLine(potatoChip1.name + "이 생성되었습니다.");
            Console.WriteLine(drink1.name + "이 생성되었습니다.");
            Console.WriteLine("세트로 만드시겠습니까?(1.예, 2.아니오)");
            string input = Console.ReadLine();
            if (input == "1")
            {
                Set set1 = burgerShop1.MakeSet(burger1, potatoChip1, drink1);
                Console.WriteLine("세트(" + set1.burger.name + "," + set1.drink.name + "," + set1.potatochip.name + ")이 생성되었습니다.");
            }
            else if (input=="2")
            {

            }

        }
    }
}

BurgerShop.cs:

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

namespace _10._01_step4
{
    class BurgerShop
    {
        public string name;
        public BurgerShop()
        {

        }
        public Burger MakeBurger(string name)
        {
            Burger burger = new Burger();
            burger.name = name;
            return burger;
        }
        public PotatoChip MakePotatoChip(string name)
        {
            PotatoChip potatoChip = new PotatoChip();
            potatoChip.name = name;
            return potatoChip;
        }
        public Drink MakeDrink(string name)
        {
            Drink drink = new Drink();
            drink.name = name;
            return drink;
        }
        public Set MakeSet(Burger burger, PotatoChip potatochip, Drink drink)
        {
            Set newSet = new Set();
            newSet.burger = burger;
            newSet.potatochip = potatochip;
            newSet.drink = drink;
            return newSet;
        }
    }
}

Burger.cs:

namespace _10._01_step4
{
    class Burger
    {
        public string name;
        public Burger()
        {
            
        }
    }
}

Drink.cs:

namespace _10._01_step4
{
    class Drink
    {
        public string name;
        public Drink()
        {

        }
    }
}

PotatoChip.cs:

namespace _10._01_step4
{
    class PotatoChip
    {
        public string name;
        public PotatoChip()
        {

        }
    }
}

Set.cs:

namespace _10._01_step4
{
    class Set
    {
        public Burger burger;
        public PotatoChip potatochip;
        public Drink drink;
        public Set()
        {

        }
    }
}

'C# > 실습' 카테고리의 다른 글

10.02 커피상점  (0) 2019.10.02
10.01 커맨드센터에서 SCV1,2를 만들고 공격하기  (0) 2019.10.01
워크래프트 캐릭생성하기  (0) 2019.09.27
switch 문  (0) 2019.09.26
09.24 최대공약수 구하기  (0) 2019.09.24
:

워크래프트 캐릭생성하기

C#/실습 2019. 9. 27. 17:04

진영

얼라이언스, 호드 

 

종족 

얼라이언스 

인간, 드워프 

 

호드 

오크, 언데드 

 

직업 

인간 : 흑마법사, 사제 

드워프 : 수도사, 사냥꾼 

오크 : 죽음의 기사, 전사 

언데드 : 마법사, 도적, 

 

[얼라이언스, 호드 ] 진영을 선택해 주세요. 얼라이언스 

[인간, 드워프 ] 종족을 선택해주세요:인간 

[흑마법사, 사제] 직업을 선택해주세요. 사제 

얼라이언스, 인간, 사제 입니다.

 

코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _09._27_step4
{
    class Program
    {
        enum Team { alliance, horde }
        enum Races { human, dwarf, orc, undead, }
        enum Classes { warlock, priest, monk, hunter, death_knight, warrior, mage, rogue }
 
        static void Main(string[] args)
        {
            int inputint;
            Console.WriteLine("[1,얼라이언스] [2,호드]");
            Console.WriteLine("진영을 선택해주세요: ");
            inputint = int.Parse(Console.ReadLine());
            Team choosenTeam = (Team)(inputint - 1);
            switch (choosenTeam)
            {
                case Team.alliance:
                    
                    { 
                        Console.WriteLine("[1,인간] [2,드워프]");
                        Console.WriteLine("종족을 선택해주세요:");
                        inputint = int.Parse(Console.ReadLine());
                        Races choosenRace = (Races)(inputint - 1);
                        switch (choosenRace)
                        {
                            case Races.human:
                                { 
                                    Console.WriteLine("[1,흑마법사] [2,프리스트]");
                                    Console.WriteLine("직업을 선택해주세요: ");
                                    inputint = int.Parse(Console.ReadLine());
                                    Classes choosenClass = (Classes)(inputint - 1);
                                    switch (choosenClass)
                                    {
                                        case Classes.warlock:
                                            Console.WriteLine("나의 캐릭터:");
                                            Console.WriteLine($"진영: {choosenTeam}, 종족: {choosenRace}, 직업: {choosenClass}");
                                            break;
                                        case Classes.priest:
                                            Console.WriteLine("나의 캐릭터:");
                                            Console.WriteLine($"진영: {choosenTeam}, 종족: {choosenRace}, 직업: {choosenClass}");
                                            break;
                                    }
                                    break;
                                }
 
                            case Races.dwarf:
                                { 
                                    Console.WriteLine("[1,수도사] [2,사냥꾼]");
                                    Console.WriteLine("직업을 선택해주세요: ");
                                    inputint = int.Parse(Console.ReadLine());
                                    Classes choosenClass = (Classes)(inputint + 1);
                                    switch (choosenClass)
                                    {
                                        case Classes.monk:
                                            Console.WriteLine("나의 캐릭터:");
                                            Console.WriteLine($"진영: {choosenTeam}, 종족: {choosenRace}, 직업: {choosenClass}");
                                            break;
                                        case Classes.hunter:
                                            Console.WriteLine("나의 캐릭터:");
                                            Console.WriteLine($"진영: {choosenTeam}, 종족: {choosenRace}, 직업: {choosenClass}");
                                            break;
                                    }
                                    break;
                                }
                        }
                        break;
                    }
                    
 
                case Team.horde:
                    { 
                        Console.WriteLine("[1,오크] [2,언데드]");
                        Console.WriteLine("종족을 선택해주세요:");
                        inputint = int.Parse(Console.ReadLine());
                        Races choosenRace = (Races)(inputint + 1);
                        switch (choosenRace)
                        {
                            case Races.orc:
                                { 
                                    Console.WriteLine("[1,죽음의 기사] [2,전사]");
                                    Console.WriteLine("직업을 선택해주세요: ");
                                    inputint = int.Parse(Console.ReadLine());
                                    Classes choosenClass = (Classes)(inputint + 3);
                                    switch (choosenClass)
                                    {
                                        case Classes.death_knight:
                                            Console.WriteLine("나의 캐릭터:");
                                            Console.WriteLine($"진영: {choosenTeam}, 종족: {choosenRace}, 직업: {choosenClass}");
                                            break;
                                        case Classes.warrior:
                                            Console.WriteLine("나의 캐릭터:");
                                            Console.WriteLine($"진영: {choosenTeam}, 종족: {choosenRace}, 직업: {choosenClass}");
                                            break;
                                    }
                                    break;
                                }
                            case Races.undead:
                                { 
                                    Console.WriteLine("[1,마법사] [2,도적]");
                                    Console.WriteLine("직업을 선택해주세요: ");
                                    inputint = int.Parse(Console.ReadLine());
                                    Classes choosenClass = (Classes)(inputint + 5);
                                    switch (choosenClass)
                                    {
                                        case Classes.mage:
                                            Console.WriteLine("나의 캐릭터:");
                                            Console.WriteLine($"진영: {choosenTeam}, 종족: {choosenRace}, 직업: {choosenClass}");
                                            break;
                                        case Classes.rogue:
                                            Console.WriteLine("나의 캐릭터:");
                                            Console.WriteLine($"진영: {choosenTeam}, 종족: {choosenRace}, 직업: {choosenClass}");
                                            break;
                                    }
                                    break;
                                }
                        }
                        break;
                    }
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
:

switch 문

C#/실습 2019. 9. 26. 13:14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _09._26_step1
{
    class Program
    {
        static void Main(string[] args)
        {
            string itemname = "장검";
            /*switch (itemname)
            {
                case "장검":
                    Console.WriteLine("장검을 선택했습니다.");
                    break;
                case "단검":
                    Console.WriteLine("단검을 서낵했습니다.");
                    break;
                default:
                    Console.WriteLine("{0}을 선택할 수 없습니다.", itemname);
                    break;
            }
            */
            /*if (itemname == "장검")
            {
                Console.WriteLine("장검을 선택했습니다");
            }
            else if (itemname == "단검")
            {
                Console.WriteLine("단검을 선택했습니다");
            }
            else
            {
                Console.WriteLine("{0}을 선택했습니다.", itemname);
            }*/
            string input = Console.ReadLine();
            switch(input)
            {
                case "1":
                    Console.WriteLine("안녕하세요");
                    break;
                case "2":
                    Console.WriteLine("반갑습니다");
                    break;
                default:
                    Console.WriteLine("감사합니다.");
                    break;
            }
            Console.WriteLine("성적을 입력하세요");
            string score = Console.ReadLine();
            switch (score)
            {
                case "a":
                    Console.WriteLine("90~100");
                    break;
                case "b":
                    Console.WriteLine("80~89");
                    break;
                case "c":
                    Console.WriteLine("70~79");
                    break;
                case "d":
                    Console.WriteLine("60~69");
                    break;
                case "f":
                    Console.WriteLine(0);
                    break;
            }
            Console.WriteLine("달 입력");
            string month = Console.ReadLine();
            switch (month)
            {
                case "1":
                case "3":
                case "5":
                case "7":
                case "8":
                case "10":
                case "12":
                    Console.WriteLine(31);
                    break;
                case "4":
                case "6":
                case "9":
                case "11":
                case "2":
                    Console.WriteLine(30);
                    break;
                default:
                    Console.WriteLine(-1);
                    break;
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

'C# > 실습' 카테고리의 다른 글

10.01 여러 class를 이용해 햄버거 세트 만들기  (0) 2019.10.01
워크래프트 캐릭생성하기  (0) 2019.09.27
09.24 최대공약수 구하기  (0) 2019.09.24
09.23 상점 구매하기 및 판매하기  (0) 2019.09.23
09.20 줄넘기  (0) 2019.09.20
:

09.24 최대공약수 구하기

C#/실습 2019. 9. 24. 17:29

예제:

두수의 최대공약수구하기

코드:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Collections.Generic;
 
namespace _09_24_step4
{
    class Program
    {
        static void Main(string[] args)
        {
            int num1 = int.Parse(Console.ReadLine());
            int num2 = int.Parse(Console.ReadLine());
            int sum = 0;
            for (int i = 1; i < num1 || i<num2; i++)
            {
                if (num1 % i == 0 && num2 % i == 0) //공약수
                {
                    sum = i;
                }                         
            }
            Console.WriteLine(sum);
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

'C# > 실습' 카테고리의 다른 글

워크래프트 캐릭생성하기  (0) 2019.09.27
switch 문  (0) 2019.09.26
09.23 상점 구매하기 및 판매하기  (0) 2019.09.23
09.20 줄넘기  (0) 2019.09.20
09.20 for문을 이용한 던전게임  (0) 2019.09.20
:

09.23 상점 구매하기 및 판매하기

C#/실습 2019. 9. 23. 15:57

예제.

1.구매하기 기능과 판매하기 기능

구매및 판매

1.1 보유 금화 및 상점에 있는 아이템 종류, 가격및 수량 설정

상점페이지

1.2 구입하고자 아이템 종류와 수량 설정기능과 상점의 재고 상태 고려

1.3 보유 금화보다 많은 아이템 구매시:

1.4 상점의 재고량 보다 많은 아이템 구매시:

1.5 재고가 없는 아이템 구매시:

1.6 상점에 없는 아이템 선택시:

 

코드:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax05
{
    class Program
    {
        static void Main(string[] args)
        {
 
            string a = "장검";
            string b = "단검";
            string c = "활";
            string d = "도끼";
            int shopa = 5;//아이템 수량
            int shopb = 6;
            int shopc = 7;
            int shopd = 8;
            int a1 = 800;//아이템 가격
            int a2 = 550;
            int a3 = 760;
            int a4 = 810;
            int wallet = 5000;
            int ha1 = 0//보유 개수
            int ha2 = 0;
            int ha3 = 0;
            int ha4 = 0;
            while (true)
            {
            Restart:
                Console.WriteLine("1. 상품 구매하기");
                Console.WriteLine("2. 상품 판매하기");
                string choice = Console.ReadLine();
                if (choice == "1")//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@구매하기 시작
                {
                    Console.WriteLine("*** 상점 ***");
                    Console.WriteLine($"금화: {wallet}");
                    Console.WriteLine($"1. 장검: {a1}원, 보유 {shopa}개");
                    Console.WriteLine($"2. 단검: {a2}원, 보유 {shopb}개.");
                    Console.WriteLine($"3. 활: {a3}원, 보유{shopc}개.");
                    Console.WriteLine($"4. 도끼: {a4}원, 보유 {shopd}개.");
                    Console.Write("상점에서 구입 하고자 하는 아이템을 입력해주세요: ");
                    string input = Console.ReadLine();
                    if (input == "장검")
                    {
                        if (shopa >= 1)
                        {
                            if (wallet >= a1)
                            {
                                Console.WriteLine("------------------");
                                Console.Write("구입하고자 하는 갯수를 입력해주세요: ");
                                string ba1 = Console.ReadLine();
                                int ba1n = Convert.ToInt32(ba1);
                                if (shopa >= ba1n)
                                {
                                    if (wallet >= a1 * ba1n)
                                    {
                                        Console.WriteLine($"{input}을 {ba1n}개 구입했습니다. (-{a1 * ba1n})");
                                        wallet = wallet - (a1 * ba1n);
                                        ha1 = ha1 + ba1n;
                                        shopa = shopa - ba1n;
                                    }
                                    else
                                    {
                                        Console.WriteLine("금화가 부족합니다.");
                                    }
                                    Console.WriteLine("------------------");
                                }
                                else
                                {
                                    Console.WriteLine("재고가 부족합니다.");
                                }
                            }
                            else
                            {
                                Console.WriteLine("금화가 부족합니다.");
                                Console.WriteLine("------------------");
                            }
                        }
                        else
                        {
                            Console.WriteLine("매진 되었습니다.");
                            Console.WriteLine("------------------");
                        }
                    }
                    else if (input == "단검")
                    {
                        if (shopb >= 1)
                        {
                            if (wallet >= a2)
                            {
                                Console.WriteLine("------------------");
                                Console.Write("구입하고자 하는 갯수를 입력해주세요: ");
                                string ba2 = Console.ReadLine();
                                int ba2n = Convert.ToInt32(ba2);
                                if (shopb >= ba2n)
                                {
                                    if (wallet >= a2 * ba2n)
                                    {
                                        Console.WriteLine($"{input}을 {ba2n}개 구입했습니다. (-{a2 * ba2n})");
                                        wallet = wallet - (a2 * ba2n);
                                        ha2 = ha2 + ba2n;
                                        shopb = shopb - ba2n;
                                    }
                                    else
                                    {
                                        Console.WriteLine("금화가 부족합니다.");
                                    }
                                    Console.WriteLine("------------------");
                                }
                                else
                                {
                                    Console.WriteLine("재고가 부족합니다.");
                                }
                            }
                            else
                            {
                                Console.WriteLine("금화가 부족합니다.");
                                Console.WriteLine("------------------");
                            }
                        }
                        else
                        {
                            Console.WriteLine("매진 되었습니다.");
                            Console.WriteLine("------------------");
                        }
                    }
                    else if (input == "활")
                    {
                        if (shopc >= 1)
                        {
                            if (wallet >= a3)
                            {
                                Console.WriteLine("------------------");
                                Console.Write("구입하고자 하는 갯수를 입력해주세요: ");
                                string ba3 = Console.ReadLine();
                                int ba3n = Convert.ToInt32(ba3);
                                if (shopc >= ba3n)
                                {
                                    if (wallet >= a3 * ba3n)
                                    {
                                        Console.WriteLine($"{input}을 {ba3n}개 구입했습니다. (-{a3 * ba3n})");
                                        wallet = wallet - (a3 * ba3n);
                                        ha3 = ha3 + ba3n;
                                        shopc = shopc - ba3n;
                                    }
                                    else
                                    {
                                        Console.WriteLine("금화가 부족합니다.");
                                    }
                                    Console.WriteLine("------------------");
                                }
                                else
                                {
                                    Console.WriteLine("재고가 부족합니다.");
                                }
                            }
                            else
                            {
                                Console.WriteLine("금화가 부족합니다.");
                                Console.WriteLine("------------------");
                            }
                        }
                        else
                        {
                            Console.WriteLine("매진 되었습니다.");
                            Console.WriteLine("------------------");
                        }
                    }
                    else if (input == "도끼")
                    {
                        if (shopd >= 1)
                        {
                            if (wallet >= a4)
                            {
                                Console.WriteLine("------------------");
                                Console.Write("구입하고자 하는 갯수를 입력해주세요: ");
                                string ba4 = Console.ReadLine();
                                int ba4n = Convert.ToInt32(ba4);
                                if (shopd >= ba4n)
                                {
                                    if (wallet >= a4 * ba4n)
                                    {
                                        Console.WriteLine($"{input}을 {ba4n}개 구입했습니다. (-{a4 * ba4n})");
                                        wallet = wallet - (a4 * ba4n);
                                        ha4 = ha4 + ba4n;
                                        shopd = shopd - ba4n;
                                    }
                                    else
                                    {
                                        Console.WriteLine("금화가 부족합니다.");
                                    }
                                    Console.WriteLine("------------------");
                                }
                                else
                                {
                                    Console.WriteLine("재고가 부족합니다.");
                                }
                            }
                            else
                            {
                                Console.WriteLine("금화가 부족합니다.");
                                Console.WriteLine("------------------");
                            }
                        }
                        else
                        {
                            Console.WriteLine("매진 되었습니다.");
                            Console.WriteLine("------------------");
                        }
                    }
                    else
                    {
                        Console.WriteLine("------------------");
                        Console.WriteLine($"해당상품 (\"{input}\")(은)는 없습니다.");
                        Console.WriteLine("------------------");
                    }
                }// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 구매하기끝
                else if (choice == "2")
                {
                    Console.WriteLine($"금화: {wallet}");
                    Console.WriteLine("------------------");
                    Console.WriteLine("보유 목록:");
                    if (ha1 > 0)
                    {
                        Console.WriteLine($"{a} X {ha1}");
                    }
                    if (ha2 > 0)
                    {
                        Console.WriteLine($"{b} X {ha2}");
                    }
                    if (ha3 > 0)
                    {
                        Console.WriteLine($"{c} X {ha3}");
                    }
                    if (ha4 > 0)
                    {
                        Console.WriteLine($"{d} X {ha4}");
                    }
                    Console.Write("판매할 아이템을 입력해주세요: ");
                    string input = Console.ReadLine();
                    if (input == "장검")
                    {
                        if (ha1 >= 1)
                        {
                            Console.WriteLine("------------------");
                            Console.WriteLine("------------------");
                            Console.Write("판매할 수량을 입력해주세요: ");
                            string sa1 = Console.ReadLine();
                            int nsa1 = Convert.ToInt32(sa1);
                            if (ha1 >= nsa1)
                            {
                                ha1 = ha1 - nsa1;
                                Console.WriteLine($"{input}을 {nsa1}개 판매했습니다. (+{a1 * nsa1})");
                                wallet = wallet + (a1 * nsa1);
                                shopa = shopa + nsa1;
                            }
                            else
                            {
                                Console.WriteLine("더 이상 판매 할 수 없습니다.");
                            }
                        }
                        else
                        {
                            Console.WriteLine("더 이상 판매 할 수 없습니다.");
                        }
 
                    }
                    else if (input == "단검")
                    {
                        if (ha2 >= 1)
                        {
                            Console.WriteLine("------------------");
                            Console.WriteLine("------------------");
                            Console.Write("판매할 수량을 입력해주세요: ");
                            string sa2 = Console.ReadLine();
                            int nsa2 = Convert.ToInt32(sa2);
                            if (ha2 >= nsa2)
                            {
                                ha2 = ha2 - nsa2;
                                Console.WriteLine($"{input}을 {nsa2}개 판매했습니다. (+{a2 * nsa2})");
                                wallet = wallet + (a2 * nsa2);
                                shopb = shopb + nsa2;
                            }
                            else
                            {
                                Console.WriteLine("더 이상 판매 할 수 없습니다.");
                            }
                        }
                        else
                        {
                            Console.WriteLine("더 이상 판매 할 수 없습니다.");
                        }
                    }
                    else if (input == "활")
                    {
                        if (ha3 >= 1)
                        {
                            Console.WriteLine("------------------");
                            Console.WriteLine("------------------");
                            Console.Write("판매할 수량을 입력해주세요: ");
                            string sa3 = Console.ReadLine();
                            int nsa3 = Convert.ToInt32(sa3);
                            if (ha3 >= nsa3)
                            {
                                ha3 = ha3 - nsa3;
                                Console.WriteLine($"{input}을 {nsa3}개 판매했습니다. (+{a3 * nsa3})");
                                wallet = wallet + (a3 * nsa3);
                                shopc = shopc + nsa3;
                            }
                            else
                            {
                                Console.WriteLine("더 이상 판매 할 수 없습니다.");
                            }
 
                        }
                        else
                        {
                            Console.WriteLine("더 이상 판매 할 수 없습니다.");
                        }
                    }
                    else if (input == "도끼")
                    {
                        if (ha4 >= 1)
                        {
                            Console.WriteLine("------------------");
                            Console.WriteLine("------------------");
                            Console.Write("판매할 수량을 입력해주세요: ");
                            string sa4 = Console.ReadLine();
                            int nsa4 = Convert.ToInt32(sa4);
                            if (ha4 >= nsa4)
                            {
                                ha4 = ha4 - nsa4;
                                Console.WriteLine($"{input}을 {nsa4}개 판매했습니다. (+{a4 * nsa4})");
                                wallet = wallet + (a4 * nsa4);
                                shopd = shopd + nsa4;
                            }
                            else
                            {
                                Console.WriteLine("더 이상 판매 할 수 없습니다.");
                            }
 
                        }
                        else
                        {
                            Console.WriteLine("더 이상 판매 할 수 없습니다.");
                        }
 
                    }
                    else
                    {
                        Console.WriteLine("------------------");
                        Console.WriteLine($"해당상품 (\"{input}\")(은)는 없습니다.");
                        Console.WriteLine("------------------");
                    }
 
                }//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@판매 하기 끝
                else
                {
                    Console.WriteLine("잘못된 메뉴입니다.");
                    goto Restart;
 
                }
                Console.WriteLine($"금화: {wallet}");
                Console.WriteLine("------------------");
                Console.WriteLine("보유 목록:");
                if (ha1 > 0)
                {
                    Console.WriteLine($"{a} X {ha1}");
                }
                if (ha2 > 0)
                {
                    Console.WriteLine($"{b} X {ha2}");
                }
                if (ha3 > 0)
                {
                    Console.WriteLine($"{c} X {ha3}");
                }
                if (ha4 > 0)
                {
                    Console.WriteLine($"{d} X {ha4}");
                }
                Console.WriteLine("------------------");
                Console.WriteLine();
                Console.WriteLine();
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

'C# > 실습' 카테고리의 다른 글

switch 문  (0) 2019.09.26
09.24 최대공약수 구하기  (0) 2019.09.24
09.20 줄넘기  (0) 2019.09.20
09.20 for문을 이용한 던전게임  (0) 2019.09.20
09.20 과일입력, 숫자입력, 문자열에 따옴표입력  (0) 2019.09.20
: