ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 연습 [2020-04-12]
    C#/과제 2020. 4. 12. 15:09
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace practice008
    {
        class Character
        {
            //이름 멤버변수 / 필드
            public string name;
            public int damage;
            public int hp;
            public int maxhp;
     
     
            //1. 생성자
            public Character(string name, int damage, int hp, int maxhp)
            {
                this.name = name;
                this.damage = damage;
                this.hp = hp;
                this.maxhp = maxhp;
            }
     
            //메소드 , 기능 
     
            public void PrintStatus()
            {
                Console.WriteLine("이름 : {0}"this.name);
                Console.WriteLine("공격력 : {0}"this.damage);
                Console.WriteLine("체력 : {0} / {1}"this.hp, this.maxhp);
                Console.WriteLine("------------------------------------");
            }
     
            public void Hit(int hitdamage)
            {
                this.hp = hp - hitdamage;
                Console.WriteLine("{0}은 {1} 데미지를 받았다."this.name, hitdamage);
                PrintStatus();
            }
     
            public void UsePotion()
            {
                this.hp = hp + 1;
                 if (this.hp > this.maxhp)
                 {
                    this.hp = this.maxhp;
                    PrintStatus();
                   Console.WriteLine(" 더 이상 체력을 회복 할 수 없습니다.");
                 }
                 else
                 {
                    PrintStatus();
                    Console.WriteLine("체력이 1회복되었습니다.");
                 }
     
            }
        }
    }
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace practice008
    {
        class APP
        {
            public APP()
            {
                //케릭터 클래스 정의
                // 데이터 : 이름, 공격력, 체력, 최대 체력
                // name, damage, hp, maxHp
                //기능 : 
                //1.내 정보를 출력 한다.PrintMyInfo
                //2.전달받은 피해량 만큼 피해를 받다. (체력감소)Hit
                //3 - 1.체력물약을 먹는 기능(체력이 1증가)  UsePotion
                //3 - 2.체력물약을 먹으면 현재 체력을 반환
     
                Character gran = new Character("그랑"5810);
     
                gran.PrintStatus();
     
                gran.Hit(2);
     
                gran.UsePotion();
                gran.UsePotion();
                gran.UsePotion();
     
                gran.UsePotion();
                gran.UsePotion();
                gran.UsePotion();
                gran.UsePotion();
                gran.UsePotion();
            }
        }
    }
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-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
    using System;
    using System.Collections.Generic;
     
    namespace practice008
    {
        class PizzaShop
        {
            //이름,    
            public string name;
     
            //생성자 
            public PizzaShop(string pizzashopname)
            {
                this.name = pizzashopname;
     
            }
     
            //메서드 , 기능 , 필드 
     
            public void MakePizza(string inputpizza)
            {
                Console.WriteLine("{0}을 만들었습니다.", inputpizza);
            }
     
            public void ImpossiblePizza(string imossiblepizza)
            {
                Console.WriteLine("{0}에서 {1}은 만들 수 없습니다." , this.name , imossiblepizza);
            }
        }
    }
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-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
    namespace practice008
    {
        class APP
        {
            public APP()
            {
     
                //피자가게 2개를 생성하세요
                //도미노피자, 피자헛
                //전달받은 피자이름을 만드는 기능
                //도미노피자에서는 불고기 피자는 만들수 없습니다.
     
                PizzaShop domino = new PizzaShop("도미노피자");
                PizzaShop pizzahut = new PizzaShop("피자헛");
     
                //domino.name = "도미노피자";
                //pizzahut.name = "피자헛";
     
                domino.MakePizza("불고기 피자");
                pizzahut.ImpossiblePizza("불고기 피자");
     
     
            }
        }
    }
     
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace practice008
    {
        class Character
        {
            // 멤버변수 / 필드 
     
            public string name;
            public string itemname;
              
            //생성자
            public Character(string name)
            {
                this.name = name; 
     
            }
     
            //기능 . 메소드 
            public  void Equipitem(string itemname)
            {
                Console.WriteLine("{0}이 {1}를 장비했습니다."this.name, itemname);
                this.itemname = itemname;
            }
     
            public void Disarmitem(string itemname)
            {
                Console.WriteLine("{0}이 {1}를 해제했습니다."this.name, itemname);
                this.itemname = null;
            }
     
            public void Attacktaget(string tagetattack)
            {
                if (this.itemname == null)
                {
                    Console.WriteLine("{0}이 {1}을 맨손으로 공격했습니다."this.name, tagetattack);
                }
                else
                {
                    Console.WriteLine("{0}이 {1}을 {2}로 공격했습니다."this.name, tagetattack, this.itemname);
                }
            }
     
        }
    }
     
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace practice008
    {
        class APP
        {
            public APP()
            {
     
                // 맴버 변수 : 이름, 아이템명
     
                //메서드 : 
                //아이템 착용(매개변수: 아이템명)
                //아이템 해제(매개변수: 아이템명)
                //공격(대상의 이름)
     
                //ex) 
                //홍길동님이 "장검"을 착용 했습니다.
                //홍길동님이 "장검"을 해제 했습니다.
                //홍길동님이 "대상"을(를) "장검"으로 공격 했습니다.
                //홍길동님이 "대상"을(를) "맨손"으로 공격 했습니다.
     
                Character gran = new Character("그랑");
     
                gran.Equipitem("롱소드");
     
                gran.Disarmitem("롱소드");
     
                gran.Attacktaget("아카샤");
     
                gran.Equipitem("활");
                gran.Attacktaget("타켓2");
            }
        }
    }
     
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
     

     

     

    'C# > 과제' 카테고리의 다른 글

    2020-04-15 [인벤토리 구축]  (0) 2020.04.15
    2020-04-14  (1) 2020.04.14
    2020-04-10 [할것] _ 기본 폼 완성  (1) 2020.04.10
    2020-04-07 while 활용  (0) 2020.04.08
    003  (1) 2020.04.07
Designed by Tistory.