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

  1. 2019.10.15 10.15 Dictionary 활용해 업적 보상 UIPanel 만들기
  2. 2019.10.14 10.14 클오클 클랜원 UIPanel 만들기
  3. 2019.10.10 10.10 class를 활용해 인벤토리와 기능 만들기
  4. 2019.10.07 10.07 class 활용해 1955버거 만들기
  5. 2019.10.07 10.07 Class 활용해 BurgerSet 만들기
  6. 2019.10.07 10.07 class 활용해 자동차만들기
  7. 2019.10.02 10.02 컴퓨터 조립
  8. 2019.10.02 10.02 자동차 부품설정

10.15 Dictionary 활용해 업적 보상 UIPanel 만들기

C#/실습 2019. 10. 15. 16:44

 

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

namespace _10._15_step4
{
    class App
    {
        public App()
        {
            Dictionary<int, RewardData> rewardDatas = new Dictionary<int, RewardData>();
            rewardDatas.Add(1, new RewardData("코인", 1000));
            rewardDatas.Add(2, new RewardData("보호구1", 1));
            rewardDatas.Add(3, new RewardData("랜덤박스", 10));
            rewardDatas.Add(4, new RewardData("코인", 1500));
            Dictionary<int, AcheivementData> acheivementDatas = new Dictionary<int, AcheivementData>();
            acheivementDatas.Add(1, new AcheivementData("업적1", "업적1설명", 1));
            acheivementDatas.Add(2, new AcheivementData("업적2", "업적2설명", 2));
            acheivementDatas.Add(3, new AcheivementData("업적3", "업적3설명", 3));
            acheivementDatas.Add(4, new AcheivementData("업적4", "업적4설명", 4));

            UIPanel panel1 = new UIPanel(rewardDatas, acheivementDatas);
            panel1.ShowAchDataByKey(3);
        }
    }
}

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

namespace _10._15_step4
{
    class UIPanel
    {
        public Dictionary<int, AcheivementData> dicAchData;
        public Dictionary<int, RewardData> dicRewData;
        public UIPanel(Dictionary<int, RewardData> rewardDatas, Dictionary<int, AcheivementData> achDatas)
        {
            this.dicAchData = achDatas;
            this.dicRewData = rewardDatas;
        }
        public RewardData SearchRewardDataByKey(int id)
        {
            return dicRewData[id];
        }
        public void ShowAchDataByKey(int id)
        {
            Console.WriteLine($"ID 번호{id}를 가진 업적데이터를 출력합니다.");
            Console.WriteLine(dicAchData[id].achName);
            Console.WriteLine(dicAchData[id].achDesc);
            Console.WriteLine(SearchRewardDataByKey(dicAchData[id].rewardDataId).name);
            Console.WriteLine(SearchRewardDataByKey(dicAchData[id].rewardDataId).amount);
        }
    }
}


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

namespace _10._15_step4
{
    class AcheivementData
    {
        public string achName;
        public string achDesc;
        public int rewardDataId;
        public AcheivementData( string name, string desc, int rewardData)
        {
            this.achName = name;
            this.achDesc = desc;
            this.rewardDataId = rewardData;
        }
    }
}


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

namespace _10._15_step4
{
    class RewardData
    {        
        public string name;
        public int amount;
        public RewardData( string name, int amount)
        {
            this.name = name;
            this.amount = amount;
        }
    }
}

 

:

10.14 클오클 클랜원 UIPanel 만들기

C#/실습 2019. 10. 14. 15:32

 

 

 

 

:

10.10 class를 활용해 인벤토리와 기능 만들기

C#/실습 2019. 10. 10. 13:31

예제:

코드:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class App
    {
        public App()
        {
            Item item1 = new Item(1"장검");
            Item item2 = new Item(2"단검");
            Item item3 = new Item(3"활");
            Inventory inventory = new Inventory();
            inventory.AddItem(item1);
            inventory.AddItem(item2);
            inventory.AddItem(item3);
            inventory.DisplayInventoryItemNames();
            inventory.FindItemByName("장검");
            inventory.RemoveItemByName("장검");
            inventory.DisplayInventoryItemNames();
            inventory.FindIndexOfItemByName("활");
 
 
        }
    }
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
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
class Inventory
    {
        public Item[] items = new Item[10];
        int itemIndex = 0;
        public Inventory()
        {
 
        }
        public void AddItem(Item item)        
        {
            items[itemIndex] = item;
            itemIndex++;
        }
        public Item FindItemByName(string name)
        {
            foreach(Item item in items)
            {
                if (item != null && item.name == name)
                {
                    Console.WriteLine(item.name+"을 찾았습니다.");
                    return item;
                }
            }
            Console.WriteLine("아이템을 찾을 수 없습니다.");
            return null;
        }
        public void RemoveItemByName(string name)
        {
            for (int i = 0; i<items.Length; i++)
            {
                if (items[i] != null && items[i].name == name)
                {
                    items[i] = null;
                    Console.WriteLine($"인벤토리에서 {name}을 삭제했습니다.");
                    return;
                }
            }
            Console.WriteLine("아이템을 찾을 수 없습니다.");
        }
        public void DisplayInventoryItemNames()
        {
            string name=null;
            Console.WriteLine("보유목록: ");
            for (int i = 0; i<items.Length; i++)
            {
                if (items[i] != null)
                {
                    name = items[i].name;                    
                    Console.WriteLine(items[i].name);
                }
            }
            if (name==null)
            {
                Console.WriteLine("아이템이 없습니다.");
            }
        }
        public int FindIndexOfItemByName(string name)
        {                        
            foreach (Item item in items)
            {
                if(item!=null && item.name==name)
                {                    
                    Console.WriteLine($"{name}의 아이디는 {item.id}입니다.");
                    return item.id;
                }
            }                        
            Console.WriteLine("해당 아이템을 찾을 수 없습니다.");
            return 0;            
        }
    }
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
class Item
    {
        public int id;
        public string name;
        public Item(int id, string name)
        {
            this.id = id;
            this.name = name;
        }
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

:

10.07 class 활용해 1955버거 만들기

C#/실습 2019. 10. 7. 17:04

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class App
    {
        public App()
        {
            Patty patty = new Patty();
            patty.SetPatty("순쇠고기패티");
            Lettuce lettuce = new Lettuce();
            lettuce.SetLettuce("신선함");
            Cheeze cheeze = new Cheeze();
            cheeze.SetCheeze("모짜렐라");
            Burger burger = new Burger();
            burger.SetBurger(patty, lettuce, cheeze);
            var P = burger.GetPatty();
            var L = burger.GetLettuce();
            var C = burger.GetCheeze();
            Console.WriteLine($"1955버거의 구성품은 {P},{L},{C}입니다.");
        }
    }
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
class Burger
    {
        Patty patty;
        Lettuce lettuce;
        Cheeze cheeze;
        public Burger()
        {
 
        }
        public void SetBurger(Patty patty, Lettuce lettuce, Cheeze cheeze)
        {
            this.patty = patty;
            this.lettuce = lettuce;
            this.cheeze = cheeze;
        }
        public string GetPatty()
        {
            return this.patty.GetPatty();
        }
        public string GetLettuce()
        {
            return this.lettuce.GetLettuce();
        }
        public string GetCheeze()
        {
            return this.cheeze.GetCheeze();
        }
        
    }
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
class Patty
    {
        string name;
        public Patty()
        {
 
        }
        public void SetPatty(string name)
        {
            this.name = name;
        }
        public string GetPatty()
        {
            return 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
15
16
class Lettuce
    {
        string name;
        public Lettuce()
        {
 
        }
        public void SetLettuce(string name)
        {
            this.name = name;
        }
        public string GetLettuce()
        {
            return 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
15
16
class Cheeze
    {
        string name;
        public Cheeze()
        {
 
        }
        public void SetCheeze(string name)
        {
            this.name = name;
        }
        public string GetCheeze()
        {
            return this.name;
        }
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
:

10.07 Class 활용해 BurgerSet 만들기

C#/실습 2019. 10. 7. 16:59

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class App
    {
        public App()
        {
            Burger burger = new Burger("슈슈버거");            
            Side side = new Side("감자칩");            
            Drink drink = new Drink();
            drink.SetDrinkName("콜라");
            Set set = new Set();
            set.SetSet(burger, side, drink);
            var GetSetBurger = set.GetBurger();
            var GetSetSide = set.GetSide();
            var GetSetDrink = set.GetDrink();
            Console.WriteLine($"세트메뉴의 구성품은 {GetSetBurger.GetName()},{GetSetSide.GetSideName()},{GetSetDrink.GetDrinkName()}입니다.");
 
        }
    }
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 Burger
    {
        string name;
        public Burger(string name)
        {
            this.name = name;
        }
        public string GetName()
        {            
            return this.name;
        }
    }
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Drink
    {
        string name;
        public Drink()
        {
 
        }
        public void SetDrinkName(string name)
        {
            this.name = name;
        }
        public string GetDrinkName()
        {
            return 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
class Side
    {
        string name;
        public Side(string name)
        {
            this.name = name;
        }
        public string GetSideName()
        {            
            return this.name;
        }
    }
 
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
class Set
    {        
        public Burger burger;
        public Side side;
        public Drink drink;
        public Set()
        {
            
        }
        public void SetSet(Burger burger, Side side, Drink drink)
        {
            this.burger = burger;
            this.side = side;
            this.drink = drink;
        }
        public Burger GetBurger()
        {
            return this.burger;
        }
        public Side GetSide()
        {
            return this.side;
        }
        public Drink GetDrink()
        {
            return this.drink;
        }
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

:

10.07 class 활용해 자동차만들기

C#/실습 2019. 10. 7. 16:56

코드:

 

1
2
3
4
5
6
7
8
9
10
11
12
public App()
        {
            Engine engine = new Engine("호준엔진");
            Wheel wheel = new Wheel("호준타이어");
            Car car = new Car("BMW");
            car.SetEngine(engine);
            car.SetWheel(wheel);
            var carEngine = car.GetEngine();
            var carWheel = car.GetWheel();
            Console.WriteLine($"{car.name}의 엔진은 {carEngine.name}이고, 타이어는 {carWheel.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
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Car
    {
        public string name;
        Engine engine;
        Wheel wheel;
        public Car(string name)
        {
            this.name = name;
        }
        public void SetEngine(Engine engine)
        {
            this.engine = engine;
            Console.WriteLine(engine.name + "을 설치했습니다.");
        }
        public void SetWheel(Wheel wheel)
        {
            this.wheel = wheel;
            Console.WriteLine(wheel.name + "을 설치했습니다.");
        }
        public Engine GetEngine()
        {
            return this.engine;
        }
        public Wheel GetWheel()
        {
            return this.wheel;
        }
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
1
2
3
4
5
6
7
8
class Engine
    {
        public string name;
        public Engine(string name)
        {
            this.name = name;
        }
    }
 
1
2
3
4
5
6
7
8
class Wheel
    {
        public string name;
        public Wheel(string name)
        {
            this.name = name;
        }
    }
 

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

10.07 class 활용해 1955버거 만들기  (0) 2019.10.07
10.07 Class 활용해 BurgerSet 만들기  (0) 2019.10.07
10.02 컴퓨터 조립  (0) 2019.10.02
10.02 자동차 부품설정  (0) 2019.10.02
10.02 버거세트  (0) 2019.10.02
:

10.02 컴퓨터 조립

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

에제:

코드:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
class App
    {
        public App()
        {
            GraphicCard graphicCard1 = new GraphicCard("GT730","GAINWARD");
            CPU cpu1 = new CPU("라이젠 3""AMD");
            PC pc1 = new PC("컴퓨터1", cpu1, graphicCard1);
            pc1.ReadCPU();
            pc1.ReadGraPhicCard();
            cpu1.ReadManu();
            graphicCard1.ReadManu();
        }
    }
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
 class PC
    {
        public string name;
        CPU cpu;
        GraphicCard graphicCard;
        public PC(string name, CPU cpu, GraphicCard graphicCard)
        {
            this.name = name;
            this.cpu = cpu;
            this.graphicCard = graphicCard;
            Console.WriteLine(this.name + "이(가) 생성되었습니다.");
            Console.WriteLine(this.name + "의 그래픽카드가 생성되었습니다.");
            Console.WriteLine(this.name + "의 CPU가 생성되었습니다.");
 
        }
        public void ReadCPU()
        {
            Console.WriteLine($"{this.name}의 CPU는 {this.cpu.name}입니다.");
        }
        public void ReadGraPhicCard()
        {
            Console.WriteLine($"{this.name}의 그래픽카드는 {this.graphicCard.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
15
class CPU
    {
        public string name;
        public string manufacturer;
        public CPU(string name, string manu)
        {
            this.name = name;
            this.manufacturer = manu;
 
        }
        public void ReadManu()
        {
            Console.WriteLine($"{this.name}의 제조사는 {this.manufacturer}입니다.");
        }
    }
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 GraphicCard
    {
        public string name;
        public string manufacturer;
        public GraphicCard(string name, string manuname)
        {
            this.name = name;
            this.manufacturer = manuname;            
        }
        public void ReadManu()
        {
            Console.WriteLine($"{this.name}의 제조사는 {this.manufacturer}입니다.");
        }
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

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

10.07 Class 활용해 BurgerSet 만들기  (0) 2019.10.07
10.07 class 활용해 자동차만들기  (0) 2019.10.07
10.02 자동차 부품설정  (0) 2019.10.02
10.02 버거세트  (0) 2019.10.02
10.02 커피상점  (0) 2019.10.02
:

10.02 자동차 부품설정

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

코드:

 

1
2
3
4
5
6
7
8
9
10
11
12
class App
    {
        public App()
        {
            Car car1 = new Car("KIA 모닝");
            Engine engine1 = new Engine("카파 1.0 ECO Prime");
            Tire tire1 = new Tire("Kumho 타이어");
            car1.GetEngine(engine1);
            car1.GetTire(tire1);
            Console.WriteLine(tire1.name + "의 규격은 " + tire1.standard + "입니다");
        }
    }
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
class Car
    {
        public string name;
        public Car(string name)
        {
            this.name = name;
            Console.WriteLine(this.name + "이(가) 생성되었습니다.");
        }
        public Engine GetEngine(Engine engine)
        {
            Console.WriteLine(this.name + "의 엔진은 " + engine.name + "입니다.");
            return engine;
        }
        public Tire GetTire(Tire tire)
        {
            Console.WriteLine(this.name + "의 타이어는 " + tire.name + "입니다.");
            return tire;
        }
    }
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
class Engine
    {
        public string name;
        public Engine(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 Tire
    {
        public string name;
        public string standard = "Solus TA31";
        public Tire(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
 

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

10.07 class 활용해 자동차만들기  (0) 2019.10.07
10.02 컴퓨터 조립  (0) 2019.10.02
10.02 버거세트  (0) 2019.10.02
10.02 커피상점  (0) 2019.10.02
10.01 커맨드센터에서 SCV1,2를 만들고 공격하기  (0) 2019.10.01
: