1.요구 사항
-배열 사용
-아이템 줍기
-아이템 버리기
-상태보기
-가방의 수량제한(다차면 더 못담는다.)
2.결과 화면 및 샘플
3.소스 코드
string[] backPack = new string[9]; string[] thingItem = new string[15]; thingItem[0] = "양날검"; thingItem[1] = "낡은검"; thingItem[2] = "녹슨검"; thingItem[3] = "도검"; thingItem[4] = "대검"; thingItem[5] = "단검"; thingItem[6] = "지팡이"; thingItem[7] = "방망이"; thingItem[8] = "몽둥이"; thingItem[9] = "사탕"; thingItem[10] = "막대"; thingItem[11] = "판자"; thingItem[12] = "못"; thingItem[13] = "망치"; thingItem[14] = "연필"; inpuutCommand: Console.WriteLine(); Console.WriteLine("원하는 명령어를 입력하세요."); Console.WriteLine("보기 \n?? 줍기 \n?? 버리기 \n소지품 \n끝"); Console.Write(">"); string check; check = Console.ReadLine(); Console.Clear(); if(check.Contains(" 줍기")) { check = check.Replace(" 줍기", ""); if (Array.IndexOf(thingItem, check) > -1 && Array.IndexOf(thingItem, check) < thingItem.Length) { for (int j = 0; j < backPack.Length; j++) { if(backPack[j] == ""|| backPack[j] == null) { backPack[j] = check; thingItem[Array.IndexOf(thingItem, check)] = ""; Console.WriteLine(check+"를 주었습니다."); goto inpuutCommand; } } Console.WriteLine("가방이 꽉차서 더이상 넣을수가 없네요."); } } if (check.Contains(" 버리기")) { check = check.Replace(" 버리기", ""); if (Array.IndexOf(backPack, check) > -1 && Array.IndexOf(backPack, check) < backPack.Length) { for (int j = 0; j < thingItem.Length; j++) { if (thingItem[j] == "") { thingItem[j] = check; backPack[Array.IndexOf(backPack, check)] = ""; Console.WriteLine(check + "를 버렸습니다."); goto inpuutCommand; } } } } if (check.Equals("소지품")) { for (int j = 0; j < backPack.Length; j++) { if (backPack[j] == "" || backPack[j] ==null) ; else Console.WriteLine(backPack[j]); } } if (check.Equals("보기")) { for (int j = 0; j < thingItem.Length; j++) { if (thingItem[j] == "") ; else Console.WriteLine(thingItem[j]); } } if (check == "끝") goto endBye; goto inpuutCommand; endBye: Console.Write("아무키나 입력하세요"); Console.ReadKey();
'정리 카테고리 > 실습_과제' 카테고리의 다른 글
실습_최종 포스기계(상품명,상품개수,금액 정리및 금액 자리수(,)표시 (0) | 2018.03.13 |
---|---|
실습_배열로 과목별 성적 받고 성적 및 합계,평균 출력 (0) | 2018.03.13 |
실습_성적 및 총합 평균 출력 (0) | 2018.03.12 |
실습_아이템 확인+집기+버리기+순서확인 (0) | 2018.03.12 |
실습_아이디 비밀번호 직업 선택 프로그램 (0) | 2018.03.08 |