1.요구 조건
//"본다", "소지품", "집는다", "버린다", "모두 집는다", "모두 버린다", "끝"
/* 본다
헝겊으로 된 지우개가 떨어져 있다.
꽤 길어 보이는 막대기가 떨어져 있다.
*/
//"000 집는다"
// 당신이 000를 집었습니다.
//"000 버린다"
// 당신이 000을 버렸습니다.
//"모두 집는다."
// 당신이 000를 집었습니다.
// 당신이 000를 집었습니다.
//"모두 버린다"
// 당신이 000을 버렸습니다.
// 당신이 000을 버렸습니다.
// "소지품"
/*
─────── 당신이 가지고 있는 물건들 ────────
아무것도 가진것이 없네요 ~
─────────────────────────────
*/
/*
─────── 당신이 가지고 있는 물건들 ────────
2개::대걸레
1개::칠판지우개
─────────────────────────────
*/
2.결과 화면 및 샘플
3.소스 코드
static void Main(string[] args) { //소지품 집는다 버린다 끝 string thing1Name = "대걸레";//물건 이름 int thing1Throw = 1;//떨어진 물건 정보 int thing1Save = 0 ;//소지한 물건 정보 string thing2Name = "칠판"; int thing2Throw = 1; int thing2Save = 0; string thing3Name = "분필"; int thing3Throw = 1; int thing3Save = 0; string thing4Name = "칠판지우개"; int thing4Throw = 1; int thing4Save = 0; string thing5Name = "양동이"; int thing5Throw = 1; int thing5Save = 0; string thing6Name = "죽도"; int thing6Throw = 1; int thing6Save = 0; string command = "";//명령어를 받아 쓰는 변수 bool check = true;//반복문의 반복여부 bool checkSecond = true;//내부 반복문의 반복여부 while (check) { Console.WriteLine(""); Console.WriteLine("원하시는 명령어를 입력하여 주세요."); Console.WriteLine("본다 - 현재 집을수 있는 물품을 보여줍니다."); Console.WriteLine("소지품 - 현재 가지고 있는 물품을 보여줍니다."); Console.WriteLine("집는다 - 물품을 소지품에 넣습니다."); Console.WriteLine("버린다 - 물품을 소지품에서 뺍니다."); Console.WriteLine("끝 - 프로그램을 종료합니다."); Console.Write("명령어::"); command = Console.ReadLine(); switch (command) { case "본다": { //떨어져 있는 물건 확인후 화면 출력 if ((thing1Throw + thing2Throw + thing3Throw + thing4Throw + thing5Throw + thing6Throw) > 0) { Console.Clear(); Console.WriteLine("현재 집을수 있는 물건들 입니다."); if (thing1Throw > 0) Console.WriteLine(thing1Name + "(이)가 " + thing1Throw + "개 있습니다."); if (thing2Throw > 0) Console.WriteLine(thing2Name + "(이)가 " + thing2Throw + "개 있습니다."); if (thing3Throw > 0) Console.WriteLine(thing3Name + "(이)가 " + thing3Throw + "개 있습니다."); if (thing4Throw > 0) Console.WriteLine(thing4Name + "(이)가 " + thing4Throw + "개 있습니다."); if (thing5Throw > 0) Console.WriteLine(thing5Name + "(이)가 " + thing5Throw + "개 있습니다."); if (thing6Throw > 0) Console.WriteLine(thing6Name + "(이)가 " + thing6Throw + "개 있습니다."); Console.WriteLine(""); } else {//떨어진게 아무것도 없는경우 Console.Clear(); Console.WriteLine("바닥은 깨끗합니다."); } break; } case"소지품": {//소지 물품 확인후 화면 출력 Console.Clear(); if((thing1Save+thing2Save +thing3Save +thing4Save + thing5Save + thing6Save) == 0) { Console.WriteLine("-----------------------소지품---------------------------"); Console.WriteLine("텅텅 비어있습니다."); Console.WriteLine("--------------------------------------------------------"); } else { Console.Clear(); Console.WriteLine("-----------------------소지품---------------------------"); if (thing1Save > 0) Console.WriteLine(" "+thing1Name + " :: " + thing1Save + " 개"); if (thing2Save > 0) Console.WriteLine(" " + thing2Name + " :: " + thing2Save + " 개"); if (thing3Save > 0) Console.WriteLine(" " + thing3Name + " :: " + thing3Save + " 개"); if (thing4Save > 0) Console.WriteLine(" " + thing4Name + " :: " + thing4Save + " 개"); if (thing5Save > 0) Console.WriteLine(" " + thing5Name + " :: " + thing5Save + " 개"); if (thing6Save > 0) Console.WriteLine(" " + thing6Name + " :: " + thing6Save + " 개"); Console.WriteLine("--------------------------------------------------------"); } break; } case "집는다": {//떨어진것 여부 확인 후 화면출력 Console.Clear(); checkSecond = true; if ((thing1Throw + thing2Throw + thing3Throw + thing4Throw + thing5Throw + thing6Throw) > 0) { while (checkSecond) { Console.WriteLine(); Console.WriteLine("현재 집을수 있는 물건들 입니다."); if (thing1Throw > 0) Console.WriteLine(thing1Name + "(이)가 " + thing1Throw + "개 있습니다."); if (thing2Throw > 0) Console.WriteLine(thing2Name + "(이)가 " + thing2Throw + "개 있습니다."); if (thing3Throw > 0) Console.WriteLine(thing3Name + "(이)가 " + thing3Throw + "개 있습니다."); if (thing4Throw > 0) Console.WriteLine(thing4Name + "(이)가 " + thing4Throw + "개 있습니다."); if (thing5Throw > 0) Console.WriteLine(thing5Name + "(이)가 " + thing5Throw + "개 있습니다."); if (thing6Throw > 0) Console.WriteLine(thing6Name + "(이)가 " + thing6Throw + "개 있습니다."); Console.WriteLine(""); Console.WriteLine("집고싶은 물건 '이름'을 입력해 주세요."); Console.WriteLine("한개씩 모두집으려면 '전부'를 입력하세요."); Console.WriteLine("이전화면으로 돌아가려면 '뒤로'를 입력하세요."); Console.Write("명령어::"); command = Console.ReadLine(); if (command == thing1Name) { if (thing1Throw > 0) { Console.Clear(); Console.WriteLine(thing1Name + "(을)를 한개 집어넣습니다."); thing1Save++; thing1Throw--; } else { Console.Clear(); Console.WriteLine("집을것이 없습니다."); } } else if (command == thing2Name) { if (thing2Throw > 0) { Console.Clear(); Console.WriteLine(thing2Name + "(을)를 한개 집어넣습니다."); thing2Save++; thing2Throw--; } else { Console.Clear(); Console.WriteLine("집을것이 없습니다."); } } else if (command == thing3Name) { if (thing3Throw > 0) { Console.Clear(); Console.WriteLine(thing3Name + "(을)를 한개 집어넣습니다."); thing3Save++; thing3Throw--; } else { Console.Clear(); Console.WriteLine("집을것이 없습니다."); } } else if (command == thing4Name) { if (thing4Throw > 0) { Console.Clear(); Console.WriteLine(thing4Name + "(을)를 한개 집어넣습니다."); thing4Save++; thing4Throw--; } else { Console.Clear(); Console.WriteLine("집을것이 없습니다."); } } else if (command == thing5Name) { if (thing5Throw > 0) { Console.Clear(); Console.WriteLine(thing5Name + "(을)를 한개 집어넣습니다."); thing5Save++; thing5Throw--; } else { Console.Clear(); Console.WriteLine("집을것이 없습니다."); } } else if (command == thing6Name) { if (thing6Throw > 0) { Console.Clear(); Console.WriteLine(thing6Name + "(을)를 한개 집어넣습니다."); thing6Save++; thing6Throw--; } else { Console.Clear(); Console.WriteLine("집을것이 없습니다."); } } else if (command == "전부") {//전부 집기전 집을것 있는지 여부 확인 if ((thing1Throw + thing2Throw + thing3Throw + thing4Throw + thing5Throw + thing6Throw) > 0) { Console.Clear(); if (thing1Throw > 0) { Console.WriteLine(thing1Name + "(을)를 한개 집어넣습니다."); thing1Save++; thing1Throw--; } if (thing2Throw > 0) { Console.WriteLine(thing2Name + "(을)를 한개 집어넣습니다."); thing2Save++; thing2Throw--; } if (thing3Throw > 0) { Console.WriteLine(thing3Name + "(을)를 한개 집어넣습니다."); thing3Save++; thing3Throw--; } if (thing4Throw > 0) { Console.WriteLine(thing4Name + "(을)를 한개 집어넣습니다."); thing4Save++; thing4Throw--; } if (thing5Throw > 0) { Console.WriteLine(thing5Name + "(을)를 한개 집어넣습니다."); thing5Save++; thing5Throw--; } if (thing6Throw > 0) { Console.WriteLine(thing6Name + "(을)를 한개 집어넣습니다."); thing6Save++; thing6Throw--; } } //반복적으로 집는중 집을게 없어진경우 else { Console.Clear(); Console.WriteLine("집을것이 없습니다."); } } else if (command == "뒤로")//집는 메뉴에서 나가는 명령어 { Console.Clear(); checkSecond = false; Console.WriteLine("뒤로 이동합니다."); } else Console.WriteLine("모르는 명령어 입니다."); } } else {//집을것이 처음부터 없는경우 Console.Clear(); Console.WriteLine("집을 물건이 없습니다."); } break; } case "버린다": {//버리기전 가지고 있는것 여부 확인 후 출력 Console.Clear(); checkSecond = true; if ((thing1Save + thing2Save + thing3Save + thing4Save + thing5Save + thing6Save) > 0) { while (checkSecond) { Console.WriteLine("현재 버릴수 있는 물건들 입니다."); if (thing1Save > 0) Console.WriteLine(thing1Name + "(이)가 " + thing1Save + "개 있습니다."); if (thing2Save > 0) Console.WriteLine(thing2Name + "(이)가 " + thing2Save + "개 있습니다."); if (thing3Save > 0) Console.WriteLine(thing3Name + "(이)가 " + thing3Save + "개 있습니다."); if (thing4Save > 0) Console.WriteLine(thing4Name + "(이)가 " + thing4Save + "개 있습니다."); if (thing5Save > 0) Console.WriteLine(thing5Name + "(이)가 " + thing5Save + "개 있습니다."); if (thing6Save > 0) Console.WriteLine(thing6Name + "(이)가 " + thing6Save + "개 있습니다."); Console.WriteLine(""); Console.WriteLine("버리고 싶은 물건 '이름'을 입력해 주세요."); Console.WriteLine("모두집으려면 '전부'를 입력하세요."); Console.WriteLine("이전화면으로 돌아가려면 '뒤로'를 입력하세요."); Console.Write("명령어::"); command = Console.ReadLine(); //한가지씩 버리는것 if (command == thing1Name) { if (thing1Save > 0) { Console.Clear(); Console.WriteLine(thing1Name + "(을)를 한개 버립니다."); thing1Save--; thing1Throw++; } else { Console.Clear(); Console.WriteLine("버릴것이 없습니다."); } } else if (command == thing2Name) { if (thing2Save > 0) { Console.Clear(); Console.WriteLine(thing2Name + "(을)를 한개 버립니다."); thing2Save--; thing2Throw++; } else { Console.Clear(); Console.WriteLine("버릴것이 없습니다."); } } else if (command == thing3Name) { if (thing3Save > 0) { Console.Clear(); Console.WriteLine(thing3Name + "(을)를 한개 버립니다."); thing3Save--; thing3Throw++; } else { Console.Clear(); Console.WriteLine("버릴것이 없습니다."); } } else if (command == thing4Name) { if (thing4Save > 0) { Console.Clear(); Console.WriteLine(thing4Name + "(을)를 한개 버립니다."); thing4Save--; thing4Throw++; } else { Console.Clear(); Console.WriteLine("버릴것이 없습니다."); } } else if (command == thing5Name) { if (thing5Save > 0) { Console.Clear(); Console.WriteLine(thing5Name + "(을)를 한개 버립니다."); thing5Save--; thing5Throw++; } else { Console.Clear(); Console.WriteLine("버릴것이 없습니다."); } } else if (command == thing6Name) { if (thing6Save > 0) { Console.Clear(); Console.WriteLine(thing6Name + "(을)를 한개 버립니다."); thing6Save--; thing6Throw++; } else { Console.Clear(); Console.WriteLine("버릴것이 없습니다."); } } else if (command == "전부")//한번에 모두 버리는 경우 { //전부 버릴것이 있는지 확인 if ((thing1Save + thing2Save + thing3Save + thing4Save + thing5Save + thing6Save) > 0) { Console.Clear(); if (thing1Save > 0) { Console.WriteLine(thing1Name + "(을)를 모두 버립니다."); thing1Save = 0; thing1Throw++; } if (thing2Save > 0) { Console.WriteLine(thing2Name + "(을)를 모두 버립니다."); thing2Save = 0; thing2Throw++; } if (thing3Save > 0) { Console.WriteLine(thing3Name + "(을)를 모두 버립니다."); thing3Save = 0; thing3Throw++; } if (thing4Save > 0) { Console.WriteLine(thing4Name + "(을)를 모두 버립니다."); thing4Save = 0; thing4Throw++; } if (thing5Save > 0) { Console.WriteLine(thing5Name + "(을)를 모두 버립니다."); thing5Save = 0; thing5Throw++; } if (thing6Save > 0) { Console.WriteLine(thing6Name + "(을)를 모두 버립니다."); thing6Save = 0; thing6Throw++; } } else//반복정으로 버리다가 버릴것이 없는경우 출력 { Console.Clear(); Console.WriteLine("버릴것이 없습니다."); } } else if (command == "뒤로")//버리는 메뉴에서 나가는 기능 { Console.Clear(); checkSecond = false; Console.WriteLine("뒤로 이동합니다."); } else Console.WriteLine("모르는 명령어 입니다."); } } else {//버리기 전부터 버릴것이 없는경우 Console.Clear(); Console.WriteLine("버릴수 있는 물품이 없습니다."); } break; } case "끝": { Console.Clear(); Console.WriteLine("프로그램을 종료합니다."); check = false; break; } default: { Console.Clear(); Console.WriteLine("알 수 없는 명령어 입니다."); break; } } } Console.ReadKey(); }
PS. : 같은물건을 여러개 집을수 있게 해보려고 하다보니 코드가 길어진 상태다.
가장 맨위 Throw 로 끝나는 변수값을 바꾸면 떨어진것이 복수개가 되는데.
그 변수를 바꾸게 되면 바꾸어야 되는 부분이 있다.
'정리 카테고리 > 실습_과제' 카테고리의 다른 글
실습_아이디 비밀번호 직업 선택 프로그램 (0) | 2018.03.08 |
---|---|
실습_로또 생성기 (2) | 2018.03.07 |
Unity-9일차 실습-과제(03-06) (2) | 2018.03.07 |
실습_직업을 골라 늑대사냥 및 강화 (0) | 2018.03.06 |
실습_비밀번호 설정 및 확인 프로그램 (0) | 2018.03.06 |