반응형
1. 매개변수, 반환타입이 없는 메서드 정의 및 호출
//걷다.
private void Walk()
{
}
//부순다.
private void Break()
{
}
//데미지를 입다.
private void Attacked()
{
}
//끄다.
private void TurnOff()
{
}
//들다.
private void Hold()
{
}
//내리다.
private void TakeOff()
{
}
//던지다.
private void Throw()
{
}
//치다.
private void Beat()
{
}
//부딪치다.
private void Bump()
{
}
//깨지다.
private void Crash()
{
}
2. 매개변수가 있는 메서드 정의 및 호출
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace study02
{
class Program
{
static void Main(string[] args)
{
EnterPlace("집");
Stingmonster("고블린");
UseItem("동동주");
WearArmor("철 값옷");
UpHp(70);
BuyItem("검", 700);
ReinForce("천하제일검");
ChargeCash(8000);
Synthesize("빛나는 주문서", "천하제일검");
CookFood("소금", "돼지고기", "마늘");
}
//들어간다 (장소)
static private void EnterPlace(string place)
{
Console.WriteLine("{0}로 들어갑니다.", place);
}
//찌르다 (몬스터)
static private void Stingmonster(string monsterName)
{
Console.WriteLine("{0}을(를) 찔렀습니다.", monsterName);
}
//아이템을 사용한다 (물건)
static private void UseItem(string itemName)
{
Console.WriteLine("{0}을(를) 사용했습니다.", itemName);
}
//착용한다 (방어구)
static private void WearArmor(string armorName)
{
Console.WriteLine("{0}을(를) 착용했습니다.", armorName);
}
//체력증가시키다. (체력)
static private void UpHp(float userHp)
{
Console.WriteLine("현재 체력을 {0}만큼 증가되었습니다.", userHp);
}
//구매하다 (물건, 금액)
static private void BuyItem(string itemName, int money)
{
Console.WriteLine("{0}을(를) {1}원에 구매하였습니다.", itemName, money);
}
//무기를 강화하다.
static private void ReinForce(string itmeName)
{
Console.WriteLine("{0}을(를) 강화합니다.", itmeName);
}
//캐쉬를 충전하다.
static private void ChargeCash(int cash)
{
Console.WriteLine("캐쉬 {0}원을 충전합니다.", cash);
}
//두 아이템을 합성한다.
static private void Synthesize(string itemA, string itemB)
{
Console.WriteLine("{0}와(과){1}를(을) 합성합니다.",itemA,itemB);
}
//재료를 넣습니다.
static private void CookFood(string ingredientA, string ingredientB, string ingredientC)
{
Console.WriteLine("요리 재료 {0}, {1}, {2}을(를) 넣습니다.", ingredientA, ingredientB, ingredientC);
}
}
}
3. 매개변수가 없고 반환값이 있는 메서드 정의 및 호출
//닉네임을 생성하다. (string)
private string CreateNickName()
{
return "민규";
}
//미네랄 8를 생성하다. (int)
private int GetMineralAmount()
{
int mineralAmount = 8;
return mineralAmount;
}
//스킬을 사용했나?(bool 연습)
private bool IsUseSkill()
{
return true;
}
//종족종류 (enum 활용)
private eRace GetRace()
{
eRace race = eRace.Ogre;
return race;
}
//현재 마나양 확인하기 (float 연습)
private float CheckMp()
{
return 150;
}
//카페라떼 만들기 (string)
private string MakeLatte()
{
string coffee = "카페라떼";
return coffee;
}
//줍기 키 확인하기 (G)
private char CheckGetKey()
{
char getKey = 'G';
return getKey;
}
//오렌지 껍질까면 6조각 (int)
private int TakeOutOrange()
{
return 6;
}
//현재 공간에 유닛이 있나? (bool)
private bool IsExistUnit()
{
return false;
}
//과일종류 (enum 활용)
private eFruits GetFruits()
{
eFruits fruits = eFruits.Orange;
return fruits;
}
4. 매개변수가 있고 반환 값이 있는 메서드 정의 및 호출
- 로그인 하기
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace study02
{
class Program
{
static void Main(string[] args)
{
string eMail = Console.ReadLine();
string pW = Console.ReadLine();
bool infoResult = SignUp(eMail, pW);
Console.WriteLine(infoResult);
}
//아이디와 비밀번호를 입력한다.
//아이디와 비밀번호가 맞으면 로그인 성공
//틀리면 로그인 불가능!
static private bool SignUp(string eMail, string pW)
{
if ((eMail == "minquu") && (pW == "1234"))
{
Console.WriteLine("회원님의 정보가 맞습니다.");
Console.WriteLine("어서오세요!");
return true;
}
else
{
Console.WriteLine("회원님의 정보가 맞지 않습니다.");
return false;
}
}
}
}
로그인 성공시
로그인 실패시
-계산기
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace study02
{
class Program
{
static void Main(string[] args)
{
float result = Calculate(15, 6, "*");
Console.WriteLine(result);
}
static private float Calculate(float a, float b, string strOperator)
{
float result = 0;
if (strOperator == "*")
{
result = a + b;
}
return result;
}
}
}
결과
-아이템 판매하기
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace study02
{
class Program
{
static void Main(string[] args)
{
while (true)
{
string itemName = Console.ReadLine();
string sellstrValue = Console.ReadLine();
int sellIntValue = Convert.ToInt32(sellstrValue);
string itemselling = ItemSell(itemName, sellIntValue);
Console.WriteLine(itemselling);
}
}
//아이템 판매하기
//판매하고싶은 아이템 (string) 과 판매가격 (int)
//만약 아이템이 얼음칼이고 가격이 450 이하면 판매완료
//얼음칼이 아니거나 450 초과면 판매불가
static private string ItemSell(string itemName, int sellValue)
{
if (itemName == "얼음칼")
{
Console.WriteLine("구매자 : 오! 제가 찾던 {0}이네요!", itemName);
if (sellValue <= 450)
{
Console.WriteLine("구매자 : 가격도 제가 원하던 가격이네요! 구매하죠!");
Console.WriteLine("system : {0}가 팔렸습니다. +{1}원 획득!", itemName, sellValue);
}
else
{
Console.WriteLine("구매자 : 가격이 너무 비쌉니다. 다음에 사죠...");
}
}
else
{
Console.WriteLine("구매자 : 이건 얼음칼이 아니네요! 구매하기 싫습니다.");
}
return "";
}
}
}
판매성공(물건ok가격ok)
판매실패(물건X)
판매실패(물건ok,가격X)
-요리하기
ing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace study02
{
class Program
{
static void Main(string[] args)
{
string curryPouder = Console.ReadLine();
string potato = Console.ReadLine();
CookCurry(curryPouder, potato);
}
//요리하기
//재료 두 가지를 섞으면 새로운 요리가 나온다.
//카레가루 + 감자 조합하여 카레를 만들어보자
static private string CookCurry(string curryPouder, string potato)
{
if ((curryPouder == "카레가루") && (potato == "감자"))
{
Console.WriteLine("자~ 맛있는 카레를 만들어보자!");
for (int i = 0; i < 101; i += 25)
{
Console.WriteLine("맛있는 카레가 만들어지고 있습니다. {0}%", i);
}
}
else
{
Console.WriteLine("이런~ 재료가 맞지 않네.");
Console.WriteLine("만들수가 없겠다.");
}
return "";
}
}
}
조리성공
조리실패
반응형
'C# > 수업과제' 카테고리의 다른 글
scv _ 미네랄 캐기 (0) | 2021.03.15 |
---|---|
클래스 생성 및 맴버 호출 (0) | 2021.03.12 |
연산자 연습 (0) | 2021.03.09 |
변수정의 및 할당 출력 연습3 (기타 게임들 _ 8~10개) (0) | 2021.03.09 |
변수정의 및 할당 출력 연습2 (마비노기영웅전_4~7개) (0) | 2021.03.09 |