ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 2020-04-10 [할것] _ 기본 폼 완성
    C#/과제 2020. 4. 10. 18:59
    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
    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 currentHp;
            public int maxHp;
            public int basicAttack;
     
            public string itemname;
     
            //생성자
            public Character(string name, int hp, int maxhp, int basicattack)
            {
                this.name = name;
                this.currentHp = hp;
                this.maxHp = maxhp;
                this.basicAttack = basicattack;
            }
            //메서드
            public void Printstatus()
            {
                Console.WriteLine("이름 : {0}"this.name);
                Console.WriteLine("체력 : {0} / {1}"this.currentHp, this.maxHp);
                Console.WriteLine("기본 공격력 : {0}"this.basicAttack);
                Console.WriteLine("-----------------------------");
            }
     
            // 공격하려한다. () 매개변수값이 들어와서 실행되어야하는데 
            // 그럼 우선 해당 개체가 와야하는데. 
            public Character Attack(Character targetcharacter)
            {
                targetcharacter.currentHp = targetcharacter.currentHp - this.basicAttack;
                Console.WriteLine("\"{0}\"은(는) \"{1}\"을 공격했습니다."this.name, targetcharacter.name);
                Console.WriteLine("\"{0}\"은(는) \"{1}\"에게 {2} 데미지! "this.name, targetcharacter.name, this.basicAttack);
                targetcharacter.Hit(this);
                Printstatus();
                targetcharacter.Printstatus();
                return targetcharacter;
            }
            //타켓에게 피해를 받을 수 있다.
            // 피해를 받는다면 타켓의 공격력만큼 체력 감소 
            // 만약에 체력이 0보다 같거나 작다면 죽어야한다.
            public Character Hit(Character hitcharacter)
            {
                Console.WriteLine("\"{0}\"은(는) \"{1}\"에게 피해를 입었습니다."this.name, hitcharacter.name);
                CheckCharacter();
                return hitcharacter;
            }
            //죽을 수 있다. >> 캐릭터 체력이 0이 되면 쓰러진다. 
           public void CheckCharacter()
           {
                if (this.currentHp <= 0)
                {
                    this.currentHp = 0;
                }
                if (this.currentHp <= 0)
                {
                    Console.WriteLine("{0}의 체력이 {1}이 되었습니다. 캐릭터가 쓰러졌습니다"this.name , this.currentHp);
                }
           }
     
     
            public void CreateItem(string itemname)
            {
                this.itemname = itemname; 
                Console.WriteLine("\"{0}\"이 \"{1}\"을 제작했습니다." , this.name , itemname);
            }
     
            public void GetItem(string takingitem)
            {
                this.itemname = takingitem;
                Console.WriteLine("\"{0}\"이 \"{1}\"을 획득했습니다."this.name, takingitem);
            }
     
            public void EquipItem(string equipitem)
            {
                this.itemname = equipitem;
                Console.WriteLine("\"{0}\"이 \"{1}\"을 착용했습니다."this.name, equipitem);
            }
     
            public void DisarmItem(string disarmitem)
            {
                this.itemname = disarmitem;
                Console.WriteLine("\"{0}\"이 \"{1}\"을 착용했습니다."this.name, disarmitem);
            }
     
     
        }
    }
    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
     
    namespace practice008
    {
        class APP
        {
            public APP()
            {
     
                //캐릭터
                //이름 . 체력, 최대체력, 기본공격력, 아이템
     
     
                //기능 >>> 메서드로 정의 되어야한다. 
     
                //타켓을 공격 할 수 있다 
     
                //타켓에게 피해를 받을 수 있다.
                // 피해를 받는다면 타켓의 공격력만큼 체력 감소 
                // 만약에 체력이 0보다 같거나 작다면 죽어야한다. 
     
                //아이템을 획득 할 수 있다. 
     
                //아이템을 제작 할 수 있따.
     
                //아이템을 착용 할 수 있다.
     
                //아이템을 해제 할 수 있다.
     
                //죽을수 있다. 
                //------------------------------------------------
     
                //아이템
                //이름
                //공격력 
     
                //// 명시되어야 하는 변수 하나하나 천천히
                //// 캐릭터 이름 / 체력 / 최대체력 / 기본공격력 / 아이템 
     
     
                Character gran = new Character("그랑"10102);
                Character Djeeta = new Character("지타"12123);
     
     
     
                gran.Printstatus();
                Djeeta.Printstatus();
     
                Djeeta.Attack(gran); //이게 된다면 ()의 값 안에 들어와 앞에있는 클래스의 인스턴스가 실행 
     
                gran.CreateItem("장검");
                gran.GetItem("장검");
     
     
            }
        }
    }
     
    http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
    http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

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

    2020-04-14  (1) 2020.04.14
    연습 [2020-04-12]  (2) 2020.04.12
    2020-04-07 while 활용  (0) 2020.04.08
    003  (1) 2020.04.07
    과제 002 [2020-04-03]  (0) 2020.04.03
Designed by Tistory.