-
2020-04-10 [할것] _ 기본 폼 완성C#/과제 2020. 4. 10. 18:59123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596using System;using System.Collections.Generic;using System.Linq;using System.Text;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}\"에게 {2} 데미지! ", this.name, targetcharacter.name, this.basicAttack);targetcharacter.Hit(this);Printstatus();targetcharacter.Printstatus();return targetcharacter;}//타켓에게 피해를 받을 수 있다.// 피해를 받는다면 타켓의 공격력만큼 체력 감소// 만약에 체력이 0보다 같거나 작다면 죽어야한다.public Character Hit(Character hitcharacter){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 Scripter1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace practice008{class APP{public APP(){//캐릭터//이름 . 체력, 최대체력, 기본공격력, 아이템//기능 >>> 메서드로 정의 되어야한다.//타켓을 공격 할 수 있다//타켓에게 피해를 받을 수 있다.// 피해를 받는다면 타켓의 공격력만큼 체력 감소// 만약에 체력이 0보다 같거나 작다면 죽어야한다.//아이템을 획득 할 수 있다.//아이템을 제작 할 수 있따.//아이템을 착용 할 수 있다.//아이템을 해제 할 수 있다.//죽을수 있다.//------------------------------------------------//아이템//이름//공격력//// 명시되어야 하는 변수 하나하나 천천히//// 캐릭터 이름 / 체력 / 최대체력 / 기본공격력 / 아이템Character gran = new Character("그랑", 10, 10, 2);Character Djeeta = new Character("지타", 12, 12, 3);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