-
연습 [2020-04-12]C#/과제 2020. 4. 12. 15:0912345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061using System;using System.Collections.Generic;using System.Linq;using System.Text;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 Scripter123456789101112131415161718192021222324252627282930313233343536373839using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace practice008{class APP{public APP(){//케릭터 클래스 정의// 데이터 : 이름, 공격력, 체력, 최대 체력// name, damage, hp, maxHp//기능 ://1.내 정보를 출력 한다.PrintMyInfo//2.전달받은 피해량 만큼 피해를 받다. (체력감소)Hit//3 - 1.체력물약을 먹는 기능(체력이 1증가) UsePotion//3 - 2.체력물약을 먹으면 현재 체력을 반환Character gran = new Character("그랑", 5, 8, 10);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
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
123456789101112131415161718192021222324252627282930313233using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace practice008{class PizzaShop{//이름,public string name;//생성자public PizzaShop(string 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 Scripter1234567891011121314151617181920212223242526namespace 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========================================================================================================================================================
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950using System;using System.Collections.Generic;using System.Linq;using System.Text;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 Scripter12345678910111213141516171819202122232425262728293031323334353637383940using System;using System.Collections.Generic;using System.Linq;using System.Text;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