From 41049345e519ab1ae11ee65cbc9ab952b4f54cae Mon Sep 17 00:00:00 2001 From: Jamong-mini Date: Mon, 4 Nov 2024 11:38:16 +0900 Subject: [PATCH 01/27] =?UTF-8?q?Update=20README:=20=ED=92=80=20=EB=A6=AC?= =?UTF-8?q?=ED=80=98=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1=20=EA=B7=9C?= =?UTF-8?q?=EC=B9=99=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 풀 리퀘스트 작성 규칙 추가 --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 3b24489..9e5db6e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ 각 레벨마다 기능이 확장되며, 팀원들이 협업하여 매주 주어진 과제를 해결해 나갑니다. # 📝 협업 규칙 + +### 풀 리퀘스트 작성 규칙 +**1** 형식: `[레벨] 작업 내용 - 팀원 이름` + - 예시: `[Lv_1] 야구 로직 구현 - 김상민` +**2** 작업 세부 사항: 해당 레벨에서 구현한 주요 기능을 요약하여 추가 설명으로 작성합니다. + ### 레포지토리 설정 및 브랜치 관리 **1** **Fork로 가져오기**: 각 팀원은 레포지토리를 Fork하여 자신의 개인 레포지토리로 가져옵니다.
**2** **브랜치 생성**: Fork한 개인 레포지토리에서 각자의 이름을 딴 브랜치를 생성합니다.
From ca65084a0b0ad73d6e81731086510b4afd8821af Mon Sep 17 00:00:00 2001 From: Jamong-mini Date: Mon, 4 Nov 2024 11:38:54 +0900 Subject: [PATCH 02/27] =?UTF-8?q?Update=20README=20:=20=EB=A7=88=ED=81=AC?= =?UTF-8?q?=EB=8B=A4=EC=9A=B4=20=EB=AC=B8=EB=B2=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 띄어쓰기 문제 수정 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e5db6e..025aece 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ### 풀 리퀘스트 작성 규칙 **1** 형식: `[레벨] 작업 내용 - 팀원 이름` - - 예시: `[Lv_1] 야구 로직 구현 - 김상민` + - 예시: `[Lv_1] 야구 로직 구현 - 김상민`
**2** 작업 세부 사항: 해당 레벨에서 구현한 주요 기능을 요약하여 추가 설명으로 작성합니다. ### 레포지토리 설정 및 브랜치 관리 From a1f36f5a308774bb33bb37c7b93304e7f9180d16 Mon Sep 17 00:00:00 2001 From: name-mun Date: Mon, 4 Nov 2024 20:30:07 +0900 Subject: [PATCH 03/27] =?UTF-8?q?=E2=9C=A8=20Lv1=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Week2-BaseballGame.xcodeproj/project.pbxproj | 2 ++ .../xcschemes/xcschememanagement.plist | 14 ++++++++++++++ ...204\354\210\230\352\265\254\355\230\204).swift" | 7 +++++++ Week2-BaseballGame/Week2-BaseballGame/main.swift | 3 ++- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 Week2-BaseballGame/Week2-BaseballGame.xcodeproj/xcuserdata/mun.xcuserdatad/xcschemes/xcschememanagement.plist diff --git a/Week2-BaseballGame/Week2-BaseballGame.xcodeproj/project.pbxproj b/Week2-BaseballGame/Week2-BaseballGame.xcodeproj/project.pbxproj index b5ea2cd..0695a57 100644 --- a/Week2-BaseballGame/Week2-BaseballGame.xcodeproj/project.pbxproj +++ b/Week2-BaseballGame/Week2-BaseballGame.xcodeproj/project.pbxproj @@ -249,6 +249,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; + MACOSX_DEPLOYMENT_TARGET = 15.0; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; }; @@ -258,6 +259,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; + MACOSX_DEPLOYMENT_TARGET = 15.0; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; }; diff --git a/Week2-BaseballGame/Week2-BaseballGame.xcodeproj/xcuserdata/mun.xcuserdatad/xcschemes/xcschememanagement.plist b/Week2-BaseballGame/Week2-BaseballGame.xcodeproj/xcuserdata/mun.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..dfbd5af --- /dev/null +++ b/Week2-BaseballGame/Week2-BaseballGame.xcodeproj/xcuserdata/mun.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Week2-BaseballGame.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" index afd8aba..4d727d0 100644 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" +++ "b/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" @@ -5,5 +5,12 @@ import Foundation func levelOne() { + // 정답을 저장한 set 생성 + var correctAnswer = Set() + // correctAnswer의 크기가 3보다 작을 때까지 실행 + while (correctAnswer.count < 3) { + // correctAnswer에 랜덤 숫자 추가 + correctAnswer.insert(Int.random(in: 1 ... 9)) + } } diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index 36bba57..73215ea 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -1,8 +1,9 @@ import Foundation + func startGame() { print("레벨을 선택하세요 (1, 2, 4, 5, 6):") - + if let input = readLine(), let level = Int(input) { switch level { case 1: From 71ebc28baea2e67a1e06302a81ee9b975b7ac58d Mon Sep 17 00:00:00 2001 From: name-mun Date: Tue, 5 Nov 2024 16:02:27 +0900 Subject: [PATCH 04/27] =?UTF-8?q?=E2=9C=A8=20=EC=9E=85=EB=A0=A5=EA=B0=92?= =?UTF-8?q?=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\210\230\352\265\254\355\230\204).swift" | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" index 6930839..c2cda9e 100644 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" +++ "b/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" @@ -16,6 +16,63 @@ import Foundation +func inputErrorCheck(_ input: String?) -> Bool { + var numberCount = [0, 0, 0, 0, 0, 0, 0, 0, 0] + + // 입력값이 3개가 아닌경우 예외처리 + if input!.count != 3 { + return false + } + + // 입력값이 숫자가 아니거나 0이 있는 경우 예외처리 + for i in input! { + if Int(String(i)) == nil || Int(String(i)) == 0 { + return false + } + numberCount[Int(String(i))!-1] += 1 + } + + // 입력값에 같은 수가 2번 있는 경우 예외처리 + for i in numberCount { + if i > 1 { + return false + } + } + + return true +} + func levelTwo() { + // 랜덤값을 저장할 set 생성 + var randomNumberSet = Set() + // 스트라이크와 볼을 저장할 변수 생성 + var strikeCount = 0 + var ballCount = 0 + + // randomNumberSet의 크기가 3이 될 때까지 실행 + while (randomNumberSet.count < 3) { + // randomNumberSet에 랜덤 숫자 추가 + randomNumberSet.insert(Int.random(in: 1 ... 9)) + } + // randomNumberSet을 배열로 저장 + let randomNumberArray = randomNumberSet.map { $0 } + + print("< 게임을 시작합니다 >") + + + // 정답을 맞출 때까지 실행 + while strikeCount != 3 { + print("숫자를 입력하세요") + + var input = readLine() + + if inputErrorCheck(input) == false { + print("올바르지 않은 입력값입니다\n") + continue + } + + + + } } From 4315d3fae635b4b65e0e472ae25384ca89b9a35e Mon Sep 17 00:00:00 2001 From: name-mun Date: Tue, 5 Nov 2024 16:16:02 +0900 Subject: [PATCH 05/27] =?UTF-8?q?=E2=9C=A8=20Lv2=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\210\230\352\265\254\355\230\204).swift" | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" index c2cda9e..790071c 100644 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" +++ "b/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" @@ -46,10 +46,6 @@ func levelTwo() { // 랜덤값을 저장할 set 생성 var randomNumberSet = Set() - // 스트라이크와 볼을 저장할 변수 생성 - var strikeCount = 0 - var ballCount = 0 - // randomNumberSet의 크기가 3이 될 때까지 실행 while (randomNumberSet.count < 3) { // randomNumberSet에 랜덤 숫자 추가 @@ -60,19 +56,49 @@ func levelTwo() { print("< 게임을 시작합니다 >") - // 정답을 맞출 때까지 실행 - while strikeCount != 3 { + while true { print("숫자를 입력하세요") - var input = readLine() + let input = readLine() + var inputArray = [Int]() + + // 스트라이크와 볼을 저장할 변수 생성 + var strikeCount = 0 + var ballCount = 0 if inputErrorCheck(input) == false { print("올바르지 않은 입력값입니다\n") continue } - + inputArray = Array(input!).map { Int(String($0))! } + // 스트라이크, 볼 계산 + for i in 0...2 { + for j in 0...2 { + // 같은 자리 같은 숫자이면 스트라이크 저장 + if i == j && inputArray[i] == randomNumberArray[j] { + strikeCount += 1 + // 다른 자리 같은 숫자이면 볼 저장 + } else if inputArray[i] == randomNumberArray[j] { + ballCount += 1 + } + } + } + + if strikeCount == 3 { + print("정답입니다!") + break + } else if strikeCount > 0 && ballCount > 0 { + print("\(strikeCount)스트라이크 \(ballCount)볼\n") + } else if strikeCount > 0 { + print("\(strikeCount)스트라이크\n") + } else if ballCount > 0 { + print("\(ballCount)볼\n") + } else { + print("Out\n") + } + } } From 3d1fbd265df54e1c62fbdd15191789fa5fccd9af Mon Sep 17 00:00:00 2001 From: name-mun Date: Tue, 5 Nov 2024 16:18:23 +0900 Subject: [PATCH 06/27] =?UTF-8?q?=F0=9F=8E=A8=20=E1=84=87=E1=85=AE?= =?UTF-8?q?=E1=86=AF=E1=84=91=E1=85=B5=E1=86=AF=E1=84=8B=E1=85=AD=E1=84=92?= =?UTF-8?q?=E1=85=A1=E1=86=AB=20=E1=84=8C=E1=85=AE=E1=84=89=E1=85=A5?= =?UTF-8?q?=E1=86=A8=20=E1=84=89=E1=85=A1=E1=86=A8=E1=84=8C=E1=85=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\210\230\352\265\254\355\230\204).swift" | 16 ---------------- 1 file changed, 16 deletions(-) diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" index 790071c..135966f 100644 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" +++ "b/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" @@ -1,19 +1,3 @@ -// Lv 2 (11/06 까지) - -/* -- 정답을 맞추기 위해 3자리수를 입력하고 힌트를 받습니다 - - 힌트는 야구용어인 **볼**과 **스트라이크**입니다. - - 같은 자리에 같은 숫자가 있는 경우 **스트라이크**, 다른 자리에 숫자가 있는 경우 **볼**입니다 - - ex) 정답 : 456 인 경우 - - 435를 입력한 경우 → 1스트라이크 1볼 - - 357를 입력한 경우 → 1스트라이크 - - 678를 입력한 경우 → 1볼 - - 123를 입력한 경우 → Nothing - - 만약 올바르지 않은 입력값에 대해서는 오류 문구를 보여주세요 -- 3자리 숫자가 정답과 같은 경우 게임이 종료됩니다 -- 실행 예시(정답 : 456)13123213 -*/ - import Foundation func inputErrorCheck(_ input: String?) -> Bool { From 9da9f0ab9626dc847e590991ef5b125a7814dfa2 Mon Sep 17 00:00:00 2001 From: name-mun Date: Tue, 5 Nov 2024 17:52:16 +0900 Subject: [PATCH 07/27] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EC=9D=84=20=ED=95=98=EB=82=98=EB=A1=9C=20=ED=95=A9=EC=B9=98?= =?UTF-8?q?=EA=B3=A0=20=EC=BD=94=EB=93=9C=20=EA=B5=AC=EC=A1=B0=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\210\230\352\265\254\355\230\204).swift" | 16 ---- ...54\210\230\352\265\254\355\230\204).swift" | 88 ------------------- ...54\240\204\352\265\254\355\230\204).swift" | 15 ---- ...54\240\204\352\265\254\355\230\204).swift" | 24 ----- ...54\240\204\352\265\254\355\230\204).swift" | 20 ----- ...54\240\204\352\265\254\355\230\204).swift" | 26 ------ 6 files changed, 189 deletions(-) delete mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" delete mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" delete mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_3(\353\217\204\354\240\204\352\265\254\355\230\204).swift" delete mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_4(\353\217\204\354\240\204\352\265\254\355\230\204).swift" delete mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_5(\353\217\204\354\240\204\352\265\254\355\230\204).swift" delete mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_6(\353\217\204\354\240\204\352\265\254\355\230\204).swift" diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" deleted file mode 100644 index 4d727d0..0000000 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" +++ /dev/null @@ -1,16 +0,0 @@ -// Lv 1 (11/04 까지) -// 1에서 9까지의 서로 다른 임의의 수 3개를 정하고 맞추는 게임입니다 -// 정답은 랜덤으로 만듭니다.(1에서 9까지의 서로 다른 임의의 수 3자리) - -import Foundation - -func levelOne() { - // 정답을 저장한 set 생성 - var correctAnswer = Set() - - // correctAnswer의 크기가 3보다 작을 때까지 실행 - while (correctAnswer.count < 3) { - // correctAnswer에 랜덤 숫자 추가 - correctAnswer.insert(Int.random(in: 1 ... 9)) - } -} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" deleted file mode 100644 index 135966f..0000000 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" +++ /dev/null @@ -1,88 +0,0 @@ -import Foundation - -func inputErrorCheck(_ input: String?) -> Bool { - var numberCount = [0, 0, 0, 0, 0, 0, 0, 0, 0] - - // 입력값이 3개가 아닌경우 예외처리 - if input!.count != 3 { - return false - } - - // 입력값이 숫자가 아니거나 0이 있는 경우 예외처리 - for i in input! { - if Int(String(i)) == nil || Int(String(i)) == 0 { - return false - } - numberCount[Int(String(i))!-1] += 1 - } - - // 입력값에 같은 수가 2번 있는 경우 예외처리 - for i in numberCount { - if i > 1 { - return false - } - } - - return true -} - -func levelTwo() { - // 랜덤값을 저장할 set 생성 - var randomNumberSet = Set() - - // randomNumberSet의 크기가 3이 될 때까지 실행 - while (randomNumberSet.count < 3) { - // randomNumberSet에 랜덤 숫자 추가 - randomNumberSet.insert(Int.random(in: 1 ... 9)) - } - // randomNumberSet을 배열로 저장 - let randomNumberArray = randomNumberSet.map { $0 } - - print("< 게임을 시작합니다 >") - - // 정답을 맞출 때까지 실행 - while true { - print("숫자를 입력하세요") - - let input = readLine() - var inputArray = [Int]() - - // 스트라이크와 볼을 저장할 변수 생성 - var strikeCount = 0 - var ballCount = 0 - - if inputErrorCheck(input) == false { - print("올바르지 않은 입력값입니다\n") - continue - } - - inputArray = Array(input!).map { Int(String($0))! } - - // 스트라이크, 볼 계산 - for i in 0...2 { - for j in 0...2 { - // 같은 자리 같은 숫자이면 스트라이크 저장 - if i == j && inputArray[i] == randomNumberArray[j] { - strikeCount += 1 - // 다른 자리 같은 숫자이면 볼 저장 - } else if inputArray[i] == randomNumberArray[j] { - ballCount += 1 - } - } - } - - if strikeCount == 3 { - print("정답입니다!") - break - } else if strikeCount > 0 && ballCount > 0 { - print("\(strikeCount)스트라이크 \(ballCount)볼\n") - } else if strikeCount > 0 { - print("\(strikeCount)스트라이크\n") - } else if ballCount > 0 { - print("\(ballCount)볼\n") - } else { - print("Out\n") - } - - } -} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_3(\353\217\204\354\240\204\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_3(\353\217\204\354\240\204\352\265\254\355\230\204).swift" deleted file mode 100644 index d5df17e..0000000 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_3(\353\217\204\354\240\204\352\265\254\355\230\204).swift" +++ /dev/null @@ -1,15 +0,0 @@ -// Lv 3 (11/06 까지) - -/* - - 정답이 되는 숫자를 0에서 9까지의 서로 다른 3자리의 숫자로 바꿔주세요 - - 맨 앞자리에 0이 오는 것은 불가능합니다 - - 092 → 불가능 - - 870 → 가능 - - 300 → 불가능 - */ - -import Foundation - -func levelThree() { - -} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_4(\353\217\204\354\240\204\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_4(\353\217\204\354\240\204\352\265\254\355\230\204).swift" deleted file mode 100644 index f529e37..0000000 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_4(\353\217\204\354\240\204\352\265\254\355\230\204).swift" +++ /dev/null @@ -1,24 +0,0 @@ -// Lv 4 (11/07 까지) - -/* - 프로그램을 시작할 때 안내문구를 보여주세요 - // 예시 - 환영합니다! 원하시는 번호를 입력해주세요 - 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 - ​ - 1번 게임 시작하기의 경우 “필수 구현 기능” 의 예시처럼 게임이 진행됩니다 - 정답을 맞혀 게임이 종료된 경우 위 안내문구를 다시 보여주세요 - // 예시 - 환영합니다! 원하시는 번호를 입력해주세요 - 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 - 1 // 1번 게임 시작하기 입력 - - < 게임을 시작합니다 > - 숫자를 입력하세요 - */ - -import Foundation - -func levelFour() { - -} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_5(\353\217\204\354\240\204\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_5(\353\217\204\354\240\204\352\265\254\355\230\204).swift" deleted file mode 100644 index f9e0d17..0000000 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_5(\353\217\204\354\240\204\352\265\254\355\230\204).swift" +++ /dev/null @@ -1,20 +0,0 @@ -// Lv 5 (11/07 까지) - -/* - 2번 게임 기록 보기의 경우 완료한 게임들에 대해 시도 횟수를 보여줍니다 - // 예시 - 환영합니다! 원하시는 번호를 입력해주세요 - 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 - 2 // 2번 게임 기록 보기 입력 - - < 게임 기록 보기 > - 1번째 게임 : 시도 횟수 - 14 - 2번째 게임 : 시도 횟수 - 9 - 3번째 게임 : 시도 횟수 - 12 -*/ - -import Foundation - -func levelFive() { - -} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_6(\353\217\204\354\240\204\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_6(\353\217\204\354\240\204\352\265\254\355\230\204).swift" deleted file mode 100644 index 848f2d1..0000000 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_6(\353\217\204\354\240\204\352\265\254\355\230\204).swift" +++ /dev/null @@ -1,26 +0,0 @@ -// Lv 6 (11/07 까지) - -/* - 3번 종료하기의 경우 프로그램이 종료됩니다 - 이전의 게임 기록들도 초기화됩니다 - // 예시 - 환영합니다! 원하시는 번호를 입력해주세요 - 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 - 3 // 3번 종료하기 입력 - - < 숫자 야구 게임을 종료합니다 > - ​ - 1, 2, 3 이외의 입력값에 대해서는 오류 메시지를 보여주세요 - // 예시 - 환영합니다! 원하시는 번호를 입력해주세요 - 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 - 4 - - 올바른 숫자를 입력해주세요! -*/ - -import Foundation - -func levelSix() { - -} From 0720a2612bd2edfe987b54e7939b721df9fc2853 Mon Sep 17 00:00:00 2001 From: name-mun Date: Tue, 5 Nov 2024 17:55:22 +0900 Subject: [PATCH 08/27] =?UTF-8?q?Revert=20"=E2=99=BB=EF=B8=8F=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=EC=9D=84=20=ED=95=98=EB=82=98=EB=A1=9C=20=ED=95=A9?= =?UTF-8?q?=EC=B9=98=EA=B3=A0=20=EC=BD=94=EB=93=9C=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 9da9f0ab9626dc847e590991ef5b125a7814dfa2. --- ...54\210\230\352\265\254\355\230\204).swift" | 16 ++++ ...54\210\230\352\265\254\355\230\204).swift" | 88 +++++++++++++++++++ ...54\240\204\352\265\254\355\230\204).swift" | 15 ++++ ...54\240\204\352\265\254\355\230\204).swift" | 24 +++++ ...54\240\204\352\265\254\355\230\204).swift" | 20 +++++ ...54\240\204\352\265\254\355\230\204).swift" | 26 ++++++ 6 files changed, 189 insertions(+) create mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" create mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" create mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_3(\353\217\204\354\240\204\352\265\254\355\230\204).swift" create mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_4(\353\217\204\354\240\204\352\265\254\355\230\204).swift" create mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_5(\353\217\204\354\240\204\352\265\254\355\230\204).swift" create mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_6(\353\217\204\354\240\204\352\265\254\355\230\204).swift" diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" new file mode 100644 index 0000000..4d727d0 --- /dev/null +++ "b/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" @@ -0,0 +1,16 @@ +// Lv 1 (11/04 까지) +// 1에서 9까지의 서로 다른 임의의 수 3개를 정하고 맞추는 게임입니다 +// 정답은 랜덤으로 만듭니다.(1에서 9까지의 서로 다른 임의의 수 3자리) + +import Foundation + +func levelOne() { + // 정답을 저장한 set 생성 + var correctAnswer = Set() + + // correctAnswer의 크기가 3보다 작을 때까지 실행 + while (correctAnswer.count < 3) { + // correctAnswer에 랜덤 숫자 추가 + correctAnswer.insert(Int.random(in: 1 ... 9)) + } +} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" new file mode 100644 index 0000000..135966f --- /dev/null +++ "b/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" @@ -0,0 +1,88 @@ +import Foundation + +func inputErrorCheck(_ input: String?) -> Bool { + var numberCount = [0, 0, 0, 0, 0, 0, 0, 0, 0] + + // 입력값이 3개가 아닌경우 예외처리 + if input!.count != 3 { + return false + } + + // 입력값이 숫자가 아니거나 0이 있는 경우 예외처리 + for i in input! { + if Int(String(i)) == nil || Int(String(i)) == 0 { + return false + } + numberCount[Int(String(i))!-1] += 1 + } + + // 입력값에 같은 수가 2번 있는 경우 예외처리 + for i in numberCount { + if i > 1 { + return false + } + } + + return true +} + +func levelTwo() { + // 랜덤값을 저장할 set 생성 + var randomNumberSet = Set() + + // randomNumberSet의 크기가 3이 될 때까지 실행 + while (randomNumberSet.count < 3) { + // randomNumberSet에 랜덤 숫자 추가 + randomNumberSet.insert(Int.random(in: 1 ... 9)) + } + // randomNumberSet을 배열로 저장 + let randomNumberArray = randomNumberSet.map { $0 } + + print("< 게임을 시작합니다 >") + + // 정답을 맞출 때까지 실행 + while true { + print("숫자를 입력하세요") + + let input = readLine() + var inputArray = [Int]() + + // 스트라이크와 볼을 저장할 변수 생성 + var strikeCount = 0 + var ballCount = 0 + + if inputErrorCheck(input) == false { + print("올바르지 않은 입력값입니다\n") + continue + } + + inputArray = Array(input!).map { Int(String($0))! } + + // 스트라이크, 볼 계산 + for i in 0...2 { + for j in 0...2 { + // 같은 자리 같은 숫자이면 스트라이크 저장 + if i == j && inputArray[i] == randomNumberArray[j] { + strikeCount += 1 + // 다른 자리 같은 숫자이면 볼 저장 + } else if inputArray[i] == randomNumberArray[j] { + ballCount += 1 + } + } + } + + if strikeCount == 3 { + print("정답입니다!") + break + } else if strikeCount > 0 && ballCount > 0 { + print("\(strikeCount)스트라이크 \(ballCount)볼\n") + } else if strikeCount > 0 { + print("\(strikeCount)스트라이크\n") + } else if ballCount > 0 { + print("\(ballCount)볼\n") + } else { + print("Out\n") + } + + } +} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_3(\353\217\204\354\240\204\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_3(\353\217\204\354\240\204\352\265\254\355\230\204).swift" new file mode 100644 index 0000000..d5df17e --- /dev/null +++ "b/Week2-BaseballGame/Week2-BaseballGame/Lv_3(\353\217\204\354\240\204\352\265\254\355\230\204).swift" @@ -0,0 +1,15 @@ +// Lv 3 (11/06 까지) + +/* + - 정답이 되는 숫자를 0에서 9까지의 서로 다른 3자리의 숫자로 바꿔주세요 + - 맨 앞자리에 0이 오는 것은 불가능합니다 + - 092 → 불가능 + - 870 → 가능 + - 300 → 불가능 + */ + +import Foundation + +func levelThree() { + +} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_4(\353\217\204\354\240\204\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_4(\353\217\204\354\240\204\352\265\254\355\230\204).swift" new file mode 100644 index 0000000..f529e37 --- /dev/null +++ "b/Week2-BaseballGame/Week2-BaseballGame/Lv_4(\353\217\204\354\240\204\352\265\254\355\230\204).swift" @@ -0,0 +1,24 @@ +// Lv 4 (11/07 까지) + +/* + 프로그램을 시작할 때 안내문구를 보여주세요 + // 예시 + 환영합니다! 원하시는 번호를 입력해주세요 + 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 + ​ + 1번 게임 시작하기의 경우 “필수 구현 기능” 의 예시처럼 게임이 진행됩니다 + 정답을 맞혀 게임이 종료된 경우 위 안내문구를 다시 보여주세요 + // 예시 + 환영합니다! 원하시는 번호를 입력해주세요 + 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 + 1 // 1번 게임 시작하기 입력 + + < 게임을 시작합니다 > + 숫자를 입력하세요 + */ + +import Foundation + +func levelFour() { + +} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_5(\353\217\204\354\240\204\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_5(\353\217\204\354\240\204\352\265\254\355\230\204).swift" new file mode 100644 index 0000000..f9e0d17 --- /dev/null +++ "b/Week2-BaseballGame/Week2-BaseballGame/Lv_5(\353\217\204\354\240\204\352\265\254\355\230\204).swift" @@ -0,0 +1,20 @@ +// Lv 5 (11/07 까지) + +/* + 2번 게임 기록 보기의 경우 완료한 게임들에 대해 시도 횟수를 보여줍니다 + // 예시 + 환영합니다! 원하시는 번호를 입력해주세요 + 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 + 2 // 2번 게임 기록 보기 입력 + + < 게임 기록 보기 > + 1번째 게임 : 시도 횟수 - 14 + 2번째 게임 : 시도 횟수 - 9 + 3번째 게임 : 시도 횟수 - 12 +*/ + +import Foundation + +func levelFive() { + +} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_6(\353\217\204\354\240\204\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_6(\353\217\204\354\240\204\352\265\254\355\230\204).swift" new file mode 100644 index 0000000..848f2d1 --- /dev/null +++ "b/Week2-BaseballGame/Week2-BaseballGame/Lv_6(\353\217\204\354\240\204\352\265\254\355\230\204).swift" @@ -0,0 +1,26 @@ +// Lv 6 (11/07 까지) + +/* + 3번 종료하기의 경우 프로그램이 종료됩니다 + 이전의 게임 기록들도 초기화됩니다 + // 예시 + 환영합니다! 원하시는 번호를 입력해주세요 + 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 + 3 // 3번 종료하기 입력 + + < 숫자 야구 게임을 종료합니다 > + ​ + 1, 2, 3 이외의 입력값에 대해서는 오류 메시지를 보여주세요 + // 예시 + 환영합니다! 원하시는 번호를 입력해주세요 + 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 + 4 + + 올바른 숫자를 입력해주세요! +*/ + +import Foundation + +func levelSix() { + +} From 08e21a91d4dfecf0840ab51300ef6a27c5a3572e Mon Sep 17 00:00:00 2001 From: name-mun Date: Tue, 5 Nov 2024 21:58:49 +0900 Subject: [PATCH 09/27] =?UTF-8?q?=F0=9F=94=A5=20=E1=84=8F=E1=85=A9?= =?UTF-8?q?=E1=84=83=E1=85=B3=20=E1=84=90=E1=85=A9=E1=86=BC=E1=84=92?= =?UTF-8?q?=E1=85=A1=E1=86=B8=E1=84=8B=E1=85=B3=E1=86=AF=20=E1=84=8B?= =?UTF-8?q?=E1=85=B1=E1=84=92=E1=85=A1=E1=86=AB=20=E1=84=91=E1=85=A1?= =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=AF=20=E1=84=86=E1=85=B5=E1=86=BE=20?= =?UTF-8?q?=E1=84=8F=E1=85=A9=E1=84=83=E1=85=B3=20=E1=84=8C=E1=85=A6?= =?UTF-8?q?=E1=84=80=E1=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 6 ++ ...54\210\230\352\265\254\355\230\204).swift" | 16 ---- ...54\210\230\352\265\254\355\230\204).swift" | 88 ------------------- ...54\240\204\352\265\254\355\230\204).swift" | 15 ---- ...54\240\204\352\265\254\355\230\204).swift" | 24 ----- ...54\240\204\352\265\254\355\230\204).swift" | 20 ----- ...54\240\204\352\265\254\355\230\204).swift" | 26 ------ .../Week2-BaseballGame/main.swift | 29 ------ 8 files changed, 6 insertions(+), 218 deletions(-) create mode 100644 Week2-BaseballGame/Week2-BaseballGame.xcodeproj/xcuserdata/mun.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist delete mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" delete mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" delete mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_3(\353\217\204\354\240\204\352\265\254\355\230\204).swift" delete mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_4(\353\217\204\354\240\204\352\265\254\355\230\204).swift" delete mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_5(\353\217\204\354\240\204\352\265\254\355\230\204).swift" delete mode 100644 "Week2-BaseballGame/Week2-BaseballGame/Lv_6(\353\217\204\354\240\204\352\265\254\355\230\204).swift" diff --git a/Week2-BaseballGame/Week2-BaseballGame.xcodeproj/xcuserdata/mun.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Week2-BaseballGame/Week2-BaseballGame.xcodeproj/xcuserdata/mun.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..9218389 --- /dev/null +++ b/Week2-BaseballGame/Week2-BaseballGame.xcodeproj/xcuserdata/mun.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,6 @@ + + + diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" deleted file mode 100644 index 4d727d0..0000000 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_1(\355\225\204\354\210\230\352\265\254\355\230\204).swift" +++ /dev/null @@ -1,16 +0,0 @@ -// Lv 1 (11/04 까지) -// 1에서 9까지의 서로 다른 임의의 수 3개를 정하고 맞추는 게임입니다 -// 정답은 랜덤으로 만듭니다.(1에서 9까지의 서로 다른 임의의 수 3자리) - -import Foundation - -func levelOne() { - // 정답을 저장한 set 생성 - var correctAnswer = Set() - - // correctAnswer의 크기가 3보다 작을 때까지 실행 - while (correctAnswer.count < 3) { - // correctAnswer에 랜덤 숫자 추가 - correctAnswer.insert(Int.random(in: 1 ... 9)) - } -} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" deleted file mode 100644 index 135966f..0000000 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_2(\355\225\204\354\210\230\352\265\254\355\230\204).swift" +++ /dev/null @@ -1,88 +0,0 @@ -import Foundation - -func inputErrorCheck(_ input: String?) -> Bool { - var numberCount = [0, 0, 0, 0, 0, 0, 0, 0, 0] - - // 입력값이 3개가 아닌경우 예외처리 - if input!.count != 3 { - return false - } - - // 입력값이 숫자가 아니거나 0이 있는 경우 예외처리 - for i in input! { - if Int(String(i)) == nil || Int(String(i)) == 0 { - return false - } - numberCount[Int(String(i))!-1] += 1 - } - - // 입력값에 같은 수가 2번 있는 경우 예외처리 - for i in numberCount { - if i > 1 { - return false - } - } - - return true -} - -func levelTwo() { - // 랜덤값을 저장할 set 생성 - var randomNumberSet = Set() - - // randomNumberSet의 크기가 3이 될 때까지 실행 - while (randomNumberSet.count < 3) { - // randomNumberSet에 랜덤 숫자 추가 - randomNumberSet.insert(Int.random(in: 1 ... 9)) - } - // randomNumberSet을 배열로 저장 - let randomNumberArray = randomNumberSet.map { $0 } - - print("< 게임을 시작합니다 >") - - // 정답을 맞출 때까지 실행 - while true { - print("숫자를 입력하세요") - - let input = readLine() - var inputArray = [Int]() - - // 스트라이크와 볼을 저장할 변수 생성 - var strikeCount = 0 - var ballCount = 0 - - if inputErrorCheck(input) == false { - print("올바르지 않은 입력값입니다\n") - continue - } - - inputArray = Array(input!).map { Int(String($0))! } - - // 스트라이크, 볼 계산 - for i in 0...2 { - for j in 0...2 { - // 같은 자리 같은 숫자이면 스트라이크 저장 - if i == j && inputArray[i] == randomNumberArray[j] { - strikeCount += 1 - // 다른 자리 같은 숫자이면 볼 저장 - } else if inputArray[i] == randomNumberArray[j] { - ballCount += 1 - } - } - } - - if strikeCount == 3 { - print("정답입니다!") - break - } else if strikeCount > 0 && ballCount > 0 { - print("\(strikeCount)스트라이크 \(ballCount)볼\n") - } else if strikeCount > 0 { - print("\(strikeCount)스트라이크\n") - } else if ballCount > 0 { - print("\(ballCount)볼\n") - } else { - print("Out\n") - } - - } -} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_3(\353\217\204\354\240\204\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_3(\353\217\204\354\240\204\352\265\254\355\230\204).swift" deleted file mode 100644 index d5df17e..0000000 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_3(\353\217\204\354\240\204\352\265\254\355\230\204).swift" +++ /dev/null @@ -1,15 +0,0 @@ -// Lv 3 (11/06 까지) - -/* - - 정답이 되는 숫자를 0에서 9까지의 서로 다른 3자리의 숫자로 바꿔주세요 - - 맨 앞자리에 0이 오는 것은 불가능합니다 - - 092 → 불가능 - - 870 → 가능 - - 300 → 불가능 - */ - -import Foundation - -func levelThree() { - -} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_4(\353\217\204\354\240\204\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_4(\353\217\204\354\240\204\352\265\254\355\230\204).swift" deleted file mode 100644 index f529e37..0000000 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_4(\353\217\204\354\240\204\352\265\254\355\230\204).swift" +++ /dev/null @@ -1,24 +0,0 @@ -// Lv 4 (11/07 까지) - -/* - 프로그램을 시작할 때 안내문구를 보여주세요 - // 예시 - 환영합니다! 원하시는 번호를 입력해주세요 - 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 - ​ - 1번 게임 시작하기의 경우 “필수 구현 기능” 의 예시처럼 게임이 진행됩니다 - 정답을 맞혀 게임이 종료된 경우 위 안내문구를 다시 보여주세요 - // 예시 - 환영합니다! 원하시는 번호를 입력해주세요 - 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 - 1 // 1번 게임 시작하기 입력 - - < 게임을 시작합니다 > - 숫자를 입력하세요 - */ - -import Foundation - -func levelFour() { - -} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_5(\353\217\204\354\240\204\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_5(\353\217\204\354\240\204\352\265\254\355\230\204).swift" deleted file mode 100644 index f9e0d17..0000000 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_5(\353\217\204\354\240\204\352\265\254\355\230\204).swift" +++ /dev/null @@ -1,20 +0,0 @@ -// Lv 5 (11/07 까지) - -/* - 2번 게임 기록 보기의 경우 완료한 게임들에 대해 시도 횟수를 보여줍니다 - // 예시 - 환영합니다! 원하시는 번호를 입력해주세요 - 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 - 2 // 2번 게임 기록 보기 입력 - - < 게임 기록 보기 > - 1번째 게임 : 시도 횟수 - 14 - 2번째 게임 : 시도 횟수 - 9 - 3번째 게임 : 시도 횟수 - 12 -*/ - -import Foundation - -func levelFive() { - -} diff --git "a/Week2-BaseballGame/Week2-BaseballGame/Lv_6(\353\217\204\354\240\204\352\265\254\355\230\204).swift" "b/Week2-BaseballGame/Week2-BaseballGame/Lv_6(\353\217\204\354\240\204\352\265\254\355\230\204).swift" deleted file mode 100644 index 848f2d1..0000000 --- "a/Week2-BaseballGame/Week2-BaseballGame/Lv_6(\353\217\204\354\240\204\352\265\254\355\230\204).swift" +++ /dev/null @@ -1,26 +0,0 @@ -// Lv 6 (11/07 까지) - -/* - 3번 종료하기의 경우 프로그램이 종료됩니다 - 이전의 게임 기록들도 초기화됩니다 - // 예시 - 환영합니다! 원하시는 번호를 입력해주세요 - 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 - 3 // 3번 종료하기 입력 - - < 숫자 야구 게임을 종료합니다 > - ​ - 1, 2, 3 이외의 입력값에 대해서는 오류 메시지를 보여주세요 - // 예시 - 환영합니다! 원하시는 번호를 입력해주세요 - 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기 - 4 - - 올바른 숫자를 입력해주세요! -*/ - -import Foundation - -func levelSix() { - -} diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index 73215ea..fecc4ab 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -1,30 +1 @@ import Foundation - - -func startGame() { - print("레벨을 선택하세요 (1, 2, 4, 5, 6):") - - if let input = readLine(), let level = Int(input) { - switch level { - case 1: - levelOne() - case 2: - levelTwo() - case 3: - levelThree() - case 4: - levelFour() - case 5: - levelFive() - case 6: - levelSix() - default: - print("유효하지 않은 레벨입니다. 1~6까지를 선택해주세요.") - } - } else { - print("잘못된 입력입니다.") - } -} - -// 게임 시작 -startGame() From c3abca45d477f88330a02d628e03e16d7ddc2191 Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 15:32:48 +0900 Subject: [PATCH 10/27] =?UTF-8?q?=E2=9C=A8=20LV1=20-=20=EB=9E=9C=EB=8D=A4?= =?UTF-8?q?=20=EC=88=AB=EC=9E=90=EB=A5=BC=20=EC=83=9D=EC=84=B1=ED=95=98?= =?UTF-8?q?=EB=8A=94=20class=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Week2-BaseballGame/main.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index fecc4ab..3640f6a 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -1 +1,18 @@ import Foundation + + +class RandomNumber { + // 서로 다른 임의수 3개를 만드는 함수 + func makeRandomNumber() -> [Int] { + // 랜덤 숫자를 저장할 Set 생성 + var randomNumber = Set() + + // 서로 다른 숫자가 3개를 생성할 때까지 반복 + while (randomNumber.count < 3) { + randomNumber.insert(Int.random(in: 1 ... 9)) + } + + // 베열로 변환 후 반환 + return Array(randomNumber) + } +} From d63454cca8b49b8c80ae1144956d03a789746671 Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 17:51:50 +0900 Subject: [PATCH 11/27] =?UTF-8?q?=E2=9C=A8=20LV2=20-=20=EA=B2=8C=EC=9E=84?= =?UTF-8?q?=EC=9D=84=20=EC=8B=A4=ED=96=89=ED=95=98=EB=8A=94=20BaseballGame?= =?UTF-8?q?=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Week2-BaseballGame/RandomNumber.swift | 21 +++++++++++++++ .../Week2-BaseballGame/main.swift | 26 ++++++++++--------- 2 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift diff --git a/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift b/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift new file mode 100644 index 0000000..3035fa0 --- /dev/null +++ b/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift @@ -0,0 +1,21 @@ +class RandomNumber { + var randomNumber = [Int]() + + init() { + randomNumber = makeRandomNumber() + } + + // 서로 다른 임의수 3개를 만드는 함수 + func makeRandomNumber() -> [Int] { + // 랜덤 숫자를 저장할 Set 생성 + var randomNumber = Set() + + // 서로 다른 숫자가 3개를 생성할 때까지 반복 + while (randomNumber.count < 3) { + randomNumber.insert(Int.random(in: 1 ... 9)) + } + + // 베열로 변환 후 반환 + return Array(randomNumber) + } +} diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index 3640f6a..570bc09 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -1,18 +1,20 @@ import Foundation +class BaseballGame { + // 랜덤 숫자 인스턴스 생성 + let randomNumber = RandomNumber() + + func gameStart() { + print("< 게임을 시작합니다 >") + // 입력값과 결과가 같을 때까지 반복 + while true { + // 입력값을 받고 변수에 저장 + print("숫자를 입력하세요") + let input = readLine() -class RandomNumber { - // 서로 다른 임의수 3개를 만드는 함수 - func makeRandomNumber() -> [Int] { - // 랜덤 숫자를 저장할 Set 생성 - var randomNumber = Set() - - // 서로 다른 숫자가 3개를 생성할 때까지 반복 - while (randomNumber.count < 3) { - randomNumber.insert(Int.random(in: 1 ... 9)) } - - // 베열로 변환 후 반환 - return Array(randomNumber) } } + +let baseballGame = BaseballGame() +baseballGame.gameStart() From 82286cd8df1dbe23f49c8b74acd1c3cac91fadc3 Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 17:55:02 +0900 Subject: [PATCH 12/27] =?UTF-8?q?=E2=9C=A8=20LV2=20-=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EA=B0=92=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=EB=A5=BC=20?= =?UTF-8?q?=ED=95=98=EB=8A=94=20InputError=20=ED=81=B4=EB=9E=98=EC=8A=A4?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Week2-BaseballGame/InputError.swift | 14 ++++++++++++++ Week2-BaseballGame/Week2-BaseballGame/main.swift | 8 ++++++++ 2 files changed, 22 insertions(+) create mode 100644 Week2-BaseballGame/Week2-BaseballGame/InputError.swift diff --git a/Week2-BaseballGame/Week2-BaseballGame/InputError.swift b/Week2-BaseballGame/Week2-BaseballGame/InputError.swift new file mode 100644 index 0000000..5d6e65d --- /dev/null +++ b/Week2-BaseballGame/Week2-BaseballGame/InputError.swift @@ -0,0 +1,14 @@ +class InputError { + // 입력값이 올바른지 확인하는 메서드 + func checkInputError(_ input: String?) -> Bool { + // 입력값의 길이가 3이 아니거나, 다른 타입이 있는 경우 + guard input!.count == 3, let inputInt = Int(input!), Set(input!).count == 3 else { + return true + } + // 0이 있는 경우 + if input!.contains("0") { + return true + } + return false + } +} diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index 570bc09..87715a3 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -3,6 +3,8 @@ import Foundation class BaseballGame { // 랜덤 숫자 인스턴스 생성 let randomNumber = RandomNumber() + // 에러 확인 인스턴스 생성 + let inputError = InputError() func gameStart() { print("< 게임을 시작합니다 >") @@ -11,6 +13,12 @@ class BaseballGame { // 입력값을 받고 변수에 저장 print("숫자를 입력하세요") let input = readLine() + + // 입력값이 올바른지 확인 + if inputError.checkInputError(input) == true { + print("올바르지 않은 입력값입니다\n") + continue + } } } From 3e62ae845a0592795c64360cfa89d702fd6ad479 Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 17:57:40 +0900 Subject: [PATCH 13/27] =?UTF-8?q?=E2=9C=A8=20LV2=20-=20=EA=B2=B0=EA=B3=BC?= =?UTF-8?q?=EA=B0=92=EC=9D=84=20=EC=A0=80=EC=9E=A5=ED=95=98=EB=8A=94=20Res?= =?UTF-8?q?ult=20enum=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Week2-BaseballGame/Result.swift | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Week2-BaseballGame/Week2-BaseballGame/Result.swift diff --git a/Week2-BaseballGame/Week2-BaseballGame/Result.swift b/Week2-BaseballGame/Week2-BaseballGame/Result.swift new file mode 100644 index 0000000..d31ceda --- /dev/null +++ b/Week2-BaseballGame/Week2-BaseballGame/Result.swift @@ -0,0 +1,23 @@ +// 결과값의 열겨형 +enum Result { + case success + case strikeBall + case strike + case ball + case out + + func printResult(strike: Int, ball: Int) { + switch self { + case .success : + print("정답입니다!") + case .strikeBall: + print("\(strike)스트라이크 \(ball)볼\n") + case .strike: + print("\(strike)스트라이크\n") + case .ball: + print("\(ball)볼\n") + case .out: + print("Out\n") + } + } +} From ab0e5caa11be0910295680751953956e19162211 Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 17:59:56 +0900 Subject: [PATCH 14/27] =?UTF-8?q?=E2=9C=A8=20LV2=20-=20=EC=A0=95=EB=8B=B5?= =?UTF-8?q?=EC=9D=84=20=EC=95=8C=EB=A0=A4=EC=A3=BC=EB=8A=94=20compareInput?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Week2-BaseballGame/RandomNumber.swift | 34 +++++++++++++++++++ .../Week2-BaseballGame/main.swift | 9 ++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift b/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift index 3035fa0..a869205 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift @@ -18,4 +18,38 @@ class RandomNumber { // 베열로 변환 후 반환 return Array(randomNumber) } + + // 랜덤 숫자와 입력값을 비교하는 함수 + func compareInput(_ input: [Int]) -> Result { + // 결과를 저장한 변수 생성 + var strike = 0 + var ball = 0 + + for i in randomNumber.indices { + for j in input.indices { + // 자리&숫자 같으면 스트라이크 + if i == j && randomNumber[i] == input[j] { strike += 1 } + // 숫자만 같으면 볼 + else if randomNumber[i] == input[j] { ball += 1 } + } + } + + let result: Result + + if strike > 0 && ball > 0 { + result = .strikeBall + } else if strike == 3 { + result = .success + } else if strike > 0 { + result = .strike + } else if ball > 0 { + result = .ball + } else { + result = .out + } + + result.printResult(strike: strike, ball: ball) + + return result + } } diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index 87715a3..8ad97b9 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -19,7 +19,14 @@ class BaseballGame { print("올바르지 않은 입력값입니다\n") continue } - + + // 입력값을 배열로 저장 + let inputArray = input!.map { Int(String($0))! } + + // 정답과 입력값을 비교하고, 성공하면 함수 종료 + if randomNumber.compareInput(inputArray) == .success { + break + } } } } From 3cb8337bab6e31ef754b31dc36e81b12ca4379a4 Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 20:09:29 +0900 Subject: [PATCH 15/27] =?UTF-8?q?=E2=9C=A8=20LV3=20-=20=EC=A0=95=EB=8B=B5?= =?UTF-8?q?=EC=9D=B4=20=EB=90=98=EB=8A=94=20=EC=88=AB=EC=9E=90=EC=9D=98=20?= =?UTF-8?q?=EB=B2=94=EC=9C=84=EB=A5=BC=20=EB=B3=80=EA=B2=BD=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Week2-BaseballGame/RandomNumber.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift b/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift index a869205..f5bc8ee 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift @@ -8,15 +8,26 @@ class RandomNumber { // 서로 다른 임의수 3개를 만드는 함수 func makeRandomNumber() -> [Int] { // 랜덤 숫자를 저장할 Set 생성 - var randomNumber = Set() - + var randomNumber = [Int]() + // 서로 다른 숫자가 3개를 생성할 때까지 반복 while (randomNumber.count < 3) { - randomNumber.insert(Int.random(in: 1 ... 9)) + let thisRandomNumber = Int.random(in: 0...9) + print(thisRandomNumber) + + // 배열의 첫 요소이고 랜덤 숫자가 0인지 확인 + if thisRandomNumber == 0 && randomNumber.count == 0 { + continue + } + + // 중복값이 없으면 배열에 랜덤 숫자 추가 + if !randomNumber.contains(thisRandomNumber) { + randomNumber.append(thisRandomNumber) + } } // 베열로 변환 후 반환 - return Array(randomNumber) + return randomNumber } // 랜덤 숫자와 입력값을 비교하는 함수 From 61d91873b40d54b530cb63e0f26909a1cdd84ffc Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 20:15:25 +0900 Subject: [PATCH 16/27] =?UTF-8?q?=F0=9F=94=A5=20=E1=84=87=E1=85=AE?= =?UTF-8?q?=E1=86=AF=E1=84=91=E1=85=B5=E1=86=AF=E1=84=8B=E1=85=AD=E1=84=92?= =?UTF-8?q?=E1=85=A1=E1=86=AB=20=E1=84=8F=E1=85=A9=E1=84=83=E1=85=B3=20?= =?UTF-8?q?=E1=84=89=E1=85=A1=E1=86=A8=E1=84=8C=E1=85=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift b/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift index f5bc8ee..e3827b5 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/RandomNumber.swift @@ -13,7 +13,6 @@ class RandomNumber { // 서로 다른 숫자가 3개를 생성할 때까지 반복 while (randomNumber.count < 3) { let thisRandomNumber = Int.random(in: 0...9) - print(thisRandomNumber) // 배열의 첫 요소이고 랜덤 숫자가 0인지 확인 if thisRandomNumber == 0 && randomNumber.count == 0 { From 89d76a53366ea174fa688abebef8e0288d94afb9 Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 20:23:10 +0900 Subject: [PATCH 17/27] =?UTF-8?q?=E2=9C=A8=20LV4=20-=20=EC=95=88=EB=82=B4?= =?UTF-8?q?=20=EB=AC=B8=EA=B5=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Week2-BaseballGame/Week2-BaseballGame/main.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index 8ad97b9..7be401f 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -6,6 +6,10 @@ class BaseballGame { // 에러 확인 인스턴스 생성 let inputError = InputError() + func selectCategory() { + print("환영합니다! 원하시는 번호를 입력해주세요\n 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기") + } + func gameStart() { print("< 게임을 시작합니다 >") // 입력값과 결과가 같을 때까지 반복 @@ -29,7 +33,7 @@ class BaseballGame { } } } -} + } let baseballGame = BaseballGame() -baseballGame.gameStart() +baseballGame.selectCategory() From b7d758c751b4c01120e12706934e1e3db6e587e3 Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 20:24:36 +0900 Subject: [PATCH 18/27] =?UTF-8?q?=E2=9C=A8=20LV4=20-=20=EC=95=88=EB=82=B4?= =?UTF-8?q?=20=EB=AC=B8=EA=B5=AC=EC=99=80=20gameStart=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Week2-BaseballGame/Week2-BaseballGame/main.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index 7be401f..00bcfdd 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -8,6 +8,13 @@ class BaseballGame { func selectCategory() { print("환영합니다! 원하시는 번호를 입력해주세요\n 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기") + + let input = Int(readLine()!) + + switch input { + case 1: gameStart() + default: selectCategory() + } } func gameStart() { From bd5fea5b3147c2162fea961a2b3cc1af86fbaa7e Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 20:29:18 +0900 Subject: [PATCH 19/27] =?UTF-8?q?=E2=9C=A8=20LV4=20-=20=EC=A0=95=EB=8B=B5?= =?UTF-8?q?=20=EB=A7=9E=ED=9E=8C=20=EA=B2=BD=EC=9A=B0=20selectCategory=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Week2-BaseballGame/Week2-BaseballGame/Result.swift | 2 +- Week2-BaseballGame/Week2-BaseballGame/main.swift | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Week2-BaseballGame/Week2-BaseballGame/Result.swift b/Week2-BaseballGame/Week2-BaseballGame/Result.swift index d31ceda..b82ce96 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/Result.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/Result.swift @@ -9,7 +9,7 @@ enum Result { func printResult(strike: Int, ball: Int) { switch self { case .success : - print("정답입니다!") + print("정답입니다!\n") case .strikeBall: print("\(strike)스트라이크 \(ball)볼\n") case .strike: diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index 00bcfdd..a698594 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -39,6 +39,7 @@ class BaseballGame { break } } + selectCategory() } } From d5069da973fe863ced551d4d617ae373e0da2da6 Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 20:38:31 +0900 Subject: [PATCH 20/27] =?UTF-8?q?=F0=9F=94=A7=20input=E1=84=8B=E1=85=B4=20?= =?UTF-8?q?=E1=84=8B=E1=85=A8=E1=84=8B=E1=85=AC=20=E1=84=8E=E1=85=A5?= =?UTF-8?q?=E1=84=85=E1=85=B5=20=E1=84=87=E1=85=A7=E1=86=AB=E1=84=80?= =?UTF-8?q?=E1=85=A7=E1=86=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Week2-BaseballGame/Week2-BaseballGame/InputError.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Week2-BaseballGame/Week2-BaseballGame/InputError.swift b/Week2-BaseballGame/Week2-BaseballGame/InputError.swift index 5d6e65d..bec190e 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/InputError.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/InputError.swift @@ -5,10 +5,11 @@ class InputError { guard input!.count == 3, let inputInt = Int(input!), Set(input!).count == 3 else { return true } - // 0이 있는 경우 - if input!.contains("0") { + // 첫 번째 자리에 0이 있는 경우 + if Array(input!)[0] == "0" { return true } + return false } } From 33a3bc09eebf71b20175643a3ba525ac69ed9dd6 Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 22:03:57 +0900 Subject: [PATCH 21/27] =?UTF-8?q?=E2=9C=A8=20LV5=20-=20=EA=B2=8C=EC=9E=84?= =?UTF-8?q?=20=EA=B8=B0=EB=A1=9D=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Week2-BaseballGame/main.swift | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index a698594..a1b8668 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -1,6 +1,8 @@ import Foundation class BaseballGame { + // 게임 기록을 저장할 2차원 배열 생성 + var gameHistory = [[0],[0]] // 랜덤 숫자 인스턴스 생성 let randomNumber = RandomNumber() // 에러 확인 인스턴스 생성 @@ -13,12 +15,17 @@ class BaseballGame { switch input { case 1: gameStart() + case 2: printGameHistory() default: selectCategory() } } func gameStart() { - print("< 게임을 시작합니다 >") + print("\n< 게임을 시작합니다 >") + // 몇 번째 게임인지 저장 + gameHistory[0].append(gameHistory[0].count) + gameHistory[1].append(0) + // 입력값과 결과가 같을 때까지 반복 while true { // 입력값을 받고 변수에 저장 @@ -30,6 +37,8 @@ class BaseballGame { print("올바르지 않은 입력값입니다\n") continue } + // 시도 횟수 추가 + gameHistory[1][gameHistory[1].count - 1] += 1 // 입력값을 배열로 저장 let inputArray = input!.map { Int(String($0))! } @@ -39,6 +48,17 @@ class BaseballGame { break } } + + selectCategory() + } + + func printGameHistory() { + print("\n< 게임 기록 보기 >") + + for i in 1...gameHistory[0].count - 1 { + print("\(gameHistory[0][i])번째 게임 : 시도 횟수 - \(gameHistory[1][i])\n") + } + selectCategory() } } From 13b3ebe57a8be87812fc27af3bb695ce64aa3f5b Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 22:07:57 +0900 Subject: [PATCH 22/27] =?UTF-8?q?=F0=9F=90=9B=20=E1=84=85=E1=85=A2?= =?UTF-8?q?=E1=86=AB=E1=84=83=E1=85=A5=E1=86=B7=20=E1=84=89=E1=85=AE?= =?UTF-8?q?=E1=86=BA=E1=84=8C=E1=85=A1=E1=84=80=E1=85=A1=20=E1=84=92?= =?UTF-8?q?=E1=85=A1=E1=86=AB=20=E1=84=87=E1=85=A5=E1=86=AB=E1=84=86?= =?UTF-8?q?=E1=85=A1=E1=86=AB=20=E1=84=89=E1=85=A2=E1=86=BC=E1=84=89?= =?UTF-8?q?=E1=85=A5=E1=86=BC=E1=84=83=E1=85=AC=E1=84=82=E1=85=B3=E1=86=AB?= =?UTF-8?q?=20=E1=84=86=E1=85=AE=E1=86=AB=E1=84=8C=E1=85=A6=20=E1=84=92?= =?UTF-8?q?=E1=85=A2=E1=84=80=E1=85=A7=E1=86=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Week2-BaseballGame/Week2-BaseballGame/main.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index a1b8668..7e5889d 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -3,8 +3,6 @@ import Foundation class BaseballGame { // 게임 기록을 저장할 2차원 배열 생성 var gameHistory = [[0],[0]] - // 랜덤 숫자 인스턴스 생성 - let randomNumber = RandomNumber() // 에러 확인 인스턴스 생성 let inputError = InputError() @@ -26,6 +24,9 @@ class BaseballGame { gameHistory[0].append(gameHistory[0].count) gameHistory[1].append(0) + // 랜덤 숫자 인스턴스 생성 + let randomNumber = RandomNumber() + // 입력값과 결과가 같을 때까지 반복 while true { // 입력값을 받고 변수에 저장 From 02c4fc421a2ef9a9417de266be27ccb2f871713c Mon Sep 17 00:00:00 2001 From: name-mun Date: Wed, 6 Nov 2024 22:13:13 +0900 Subject: [PATCH 23/27] =?UTF-8?q?=E2=9C=A8=20LV6=20-=20=EA=B2=8C=EC=9E=84?= =?UTF-8?q?=20=EC=A2=85=EB=A3=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Week2-BaseballGame/Week2-BaseballGame/main.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index 7e5889d..f89c59e 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -14,6 +14,7 @@ class BaseballGame { switch input { case 1: gameStart() case 2: printGameHistory() + case 3: gameOver() default: selectCategory() } } @@ -62,6 +63,11 @@ class BaseballGame { selectCategory() } + + func gameOver() { + print("\n< 숫자 야구 게임을 종료합니다 >") + return + } } let baseballGame = BaseballGame() From 6fb1f6021d6cab2389cc8b39b93708cfd8411825 Mon Sep 17 00:00:00 2001 From: name-mun Date: Thu, 7 Nov 2024 10:08:33 +0900 Subject: [PATCH 24/27] =?UTF-8?q?=E2=9C=A8=20LV6=20-=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=EA=B0=92=20=EC=98=A4=EB=A5=98=20=EB=A9=94=EC=8B=9C=EC=A7=80=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Week2-BaseballGame/InputError.swift | 11 ++++++++++- Week2-BaseballGame/Week2-BaseballGame/main.swift | 6 ++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Week2-BaseballGame/Week2-BaseballGame/InputError.swift b/Week2-BaseballGame/Week2-BaseballGame/InputError.swift index bec190e..0f91230 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/InputError.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/InputError.swift @@ -1,6 +1,15 @@ class InputError { + + func checkInputErrorMain(_ input: String?) -> Bool { + guard input!.count == 1, let inputInt = Int(input!) else { + return true + } + + return false + } + // 입력값이 올바른지 확인하는 메서드 - func checkInputError(_ input: String?) -> Bool { + func checkInputErrorGame(_ input: String?) -> Bool { // 입력값의 길이가 3이 아니거나, 다른 타입이 있는 경우 guard input!.count == 3, let inputInt = Int(input!), Set(input!).count == 3 else { return true diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index f89c59e..b387772 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -15,7 +15,9 @@ class BaseballGame { case 1: gameStart() case 2: printGameHistory() case 3: gameOver() - default: selectCategory() + default: + print("\n올바른 숫자를 입력해주세요!\n") + selectCategory() } } @@ -35,7 +37,7 @@ class BaseballGame { let input = readLine() // 입력값이 올바른지 확인 - if inputError.checkInputError(input) == true { + if inputError.checkInputErrorGame(input) == true { print("올바르지 않은 입력값입니다\n") continue } From e544ac207bbdc8fc9cf4a1a83f63e5c0c351483d Mon Sep 17 00:00:00 2001 From: name-mun Date: Thu, 7 Nov 2024 10:19:20 +0900 Subject: [PATCH 25/27] =?UTF-8?q?=F0=9F=90=9B=20=E1=84=80=E1=85=A6?= =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=20=E1=84=80=E1=85=B5=E1=84=85?= =?UTF-8?q?=E1=85=A9=E1=86=A8=E1=84=8B=E1=85=B5=20=E1=84=8B=E1=85=A5?= =?UTF-8?q?=E1=86=B9=E1=84=8B=E1=85=B3=E1=86=AF=20=E1=84=89=E1=85=B5=20?= =?UTF-8?q?=E1=84=8F=E1=85=B3=E1=84=85=E1=85=A2=E1=84=89=E1=85=B5=E1=84=80?= =?UTF-8?q?=E1=85=A1=20=E1=84=82=E1=85=A1=E1=84=82=E1=85=B3=E1=86=AB=20?= =?UTF-8?q?=E1=84=8B=E1=85=A9=E1=84=85=E1=85=B2=20=E1=84=92=E1=85=A2?= =?UTF-8?q?=E1=84=80=E1=85=A7=E1=86=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Week2-BaseballGame/Week2-BaseballGame/main.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Week2-BaseballGame/Week2-BaseballGame/main.swift b/Week2-BaseballGame/Week2-BaseballGame/main.swift index b387772..1cb0a31 100644 --- a/Week2-BaseballGame/Week2-BaseballGame/main.swift +++ b/Week2-BaseballGame/Week2-BaseballGame/main.swift @@ -7,7 +7,7 @@ class BaseballGame { let inputError = InputError() func selectCategory() { - print("환영합니다! 원하시는 번호를 입력해주세요\n 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기") + print("\n환영합니다! 원하시는 번호를 입력해주세요\n 1. 게임 시작하기 2. 게임 기록 보기 3. 종료하기") let input = Int(readLine()!) @@ -16,7 +16,7 @@ class BaseballGame { case 2: printGameHistory() case 3: gameOver() default: - print("\n올바른 숫자를 입력해주세요!\n") + print("\n올바른 숫자를 입력해주세요!") selectCategory() } } @@ -59,8 +59,12 @@ class BaseballGame { func printGameHistory() { print("\n< 게임 기록 보기 >") - for i in 1...gameHistory[0].count - 1 { - print("\(gameHistory[0][i])번째 게임 : 시도 횟수 - \(gameHistory[1][i])\n") + if gameHistory[0].count > 1 { + for i in 1...gameHistory[0].count - 1 { + print("\(gameHistory[0][i])번째 게임 : 시도 횟수 - \(gameHistory[1][i])") + } + } else { + print("저장된 기록이 없습니다\n2") } selectCategory() From fd2f7a6f2406c483ecc935be054bb1001be10b2d Mon Sep 17 00:00:00 2001 From: mun <77603287+name-mun@users.noreply.github.com> Date: Thu, 7 Nov 2024 10:48:48 +0900 Subject: [PATCH 26/27] =?UTF-8?q?=F0=9F=93=9D=20README=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 77 ++++++++----------------------------------------------- 1 file changed, 11 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 025aece..f2abc65 100644 --- a/README.md +++ b/README.md @@ -1,77 +1,22 @@ -# 숫자 야구 게임 과제 (Week 2) -숫자 야구 게임은 1에서 9까지의 서로 다른 3개의 숫자를 맞추는 게임입니다.
-각 레벨마다 기능이 확장되며, 팀원들이 협업하여 매주 주어진 과제를 해결해 나갑니다. +# Swift로 야구게임 만들기 -# 📝 협업 규칙 +## 📄 개요 +랜덤으로 생성된 3자리 숫자를 맞추는 게임으로, 사용자가 입력한 숫자와 정답을 비교해 결과를 알려주고 기록을 저장합니다. -### 풀 리퀘스트 작성 규칙 -**1** 형식: `[레벨] 작업 내용 - 팀원 이름` - - 예시: `[Lv_1] 야구 로직 구현 - 김상민`
-**2** 작업 세부 사항: 해당 레벨에서 구현한 주요 기능을 요약하여 추가 설명으로 작성합니다. +## 🛠️ 기능 +- **랜덤 숫자 생성**: 게임 시작 시 서로 다른 3자리 숫자를 생성합니다. +- **입력값 비교**: 사용자가 입력한 숫자와 정답을 비교하여 결과를 반환합니다. +- **게임 기록 저장**: 사용자의 게임 기록을 저장하고 확인할 수 있는 기능입니다. +- **게임 종료**: 사용자가 종료를 원하면 게임이 종료됩니다. -### 레포지토리 설정 및 브랜치 관리 -**1** **Fork로 가져오기**: 각 팀원은 레포지토리를 Fork하여 자신의 개인 레포지토리로 가져옵니다.
-**2** **브랜치 생성**: Fork한 개인 레포지토리에서 각자의 이름을 딴 브랜치를 생성합니다.
-**3** **Pull Request**: 과제를 마친 후, 각자의 브랜치로 Pull Request를 생성하여 코드 리뷰를 요청합니다. 모든 팀원이 Pull Request에 코멘트를 달고 피드백을 제공합니다.
-**4** **수정 및 Merge**: 피드백을 반영하여 수정하고, 팀원들의 동의를 얻은 후 merge를 진행합니다.
+## ⚠️ 참고사항 +- **랜덤 숫자 생성 제약**: 서로 다른 임의의 숫자 3자리를 생성하며, 첫 자리는 0이 될 수 없습니다. +- **사용자 입력값 예외 처리**: 3자리의 숫자가 아닌 경우 예외 처리가 이루어집니다. -이 과정을 통해 서로의 코드에 대해 이해를 높이고, “왜 이렇게 작성했는지”에 대한 질문과 답변을 주고받으며 과제를 진행합니다. -# 📂 코드 파일 구조 -* main.swift: 게임의 메인 진입점으로, 레벨을 선택하고 시작할 수 있도록 구성되어 있습니다. startGame() 함수가 게임의 시작을 담당합니다. -* Lv_1.swift ~ Lv_6.swift: 각 레벨별 요구사항에 맞게 구현된 파일입니다. 각 파일에는 해당 레벨의 기능을 구현하는 함수가 포함되어 있습니다. -⠀📜 구현 가이드 -### main.swift -Command Line Tool 프로젝트에서는 하나의 `main.swift` 파일에서만 프로그램을 시작할 수 있습니다. 따라서 각 레벨별 기능을 별도의 파일로 구현한 후, `main.swift` 파일에서 해당 레벨의 함수를 호출하여 실행하도록 구성합니다. -```swift -import Foundation -func startGame() { - print("레벨을 선택하세요 (1, 2, 3, 4, 5, 6):") - - if let input = readLine(), let level = Int(input) { - switch level { - case 1: - levelOne() - case 2: - levelTwo() - case 3: - levelThree() - case 4: - levelFour() - case 5: - levelFive() - case 6: - levelSix() - default: - print("유효하지 않은 레벨입니다. 1~6까지를 선택해주세요.") - } - } else { - print("잘못된 입력입니다.") - } -} -// 게임 시작 -startGame() -``` -* startGame() 함수에서 게임의 레벨을 선택하여 시작할 수 있도록 구성합니다. -* 사용자가 입력한 레벨 번호에 따라 해당 레벨의 함수를 호출하여 게임을 진행합니다. -### 각 레벨 파일 (Lv_1.swift ~ Lv_6.swift) - 구현 파일 - -**Lv_1.swift** - -```swift -import Foundation - -func levelOne() { - // 1. 정답을 생성하는 로직을 추가합니다. - // 2. 유저가 정답을 맞출 때까지 반복해서 입력을 받습니다. - // 3. 입력값이 유효한지 검사하고 힌트를 제공하는 기능을 구현합니다. -} -``` - -각 레벨별로 구현하시면 됩니다. From 65c1ee3304200364083d37e108bd899abcd2b485 Mon Sep 17 00:00:00 2001 From: mun <77603287+name-mun@users.noreply.github.com> Date: Thu, 7 Nov 2024 21:02:32 +0900 Subject: [PATCH 27/27] =?UTF-8?q?=F0=9F=93=9D=20README=20=EC=9E=90?= =?UTF-8?q?=EC=84=B8=ED=95=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f2abc65..e4ef774 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## 📄 개요 랜덤으로 생성된 3자리 숫자를 맞추는 게임으로, 사용자가 입력한 숫자와 정답을 비교해 결과를 알려주고 기록을 저장합니다. -## 🛠️ 기능 +## 🛠️ 주요 기능 - **랜덤 숫자 생성**: 게임 시작 시 서로 다른 3자리 숫자를 생성합니다. - **입력값 비교**: 사용자가 입력한 숫자와 정답을 비교하여 결과를 반환합니다. - **게임 기록 저장**: 사용자의 게임 기록을 저장하고 확인할 수 있는 기능입니다. @@ -13,6 +13,56 @@ - **랜덤 숫자 생성 제약**: 서로 다른 임의의 숫자 3자리를 생성하며, 첫 자리는 0이 될 수 없습니다. - **사용자 입력값 예외 처리**: 3자리의 숫자가 아닌 경우 예외 처리가 이루어집니다. +## ✏️ 상세 설명 +### `BaseballGame` +게임을 시작하고, 기록을 보고 종료하는 기능이 있는 클래스입니다. +
+**selectCategory()** +
+사용자는 게임을 시작하고, 기록을 보고 게임을 종료할 수 있습니다. 올바르지 않은 값을 입력했을 경우 예외 처리했습니다. +
+**gameStart()** +
+랜덤 숫자를 생성하여 사용자의 값과 비교한 뒤 결과를 출력합니다. +
+**printGameHistory()** +
+게임 순서와 게임 시도 횟수를 확인합니다. +
+**gameOver()** +
+게임을 종료합니다. + +### `RandomNumber` +랜덤 숫자를 생성하고 랜덤 숫자와 사용자의 입력값을 비교하는 클래스입니다. +
+**makeRandomNumber** +
+서로 다른 3개의 수를 생성합니다. +
+**compareInput()** +
+랜덤 숫자와 입력값을 비교하여 스트라이크, 볼을 사용하여 결과를 반환합니다. + +### `Result` +게임 결과를 저장하는 열거형으로, `success`, `strikeBall`, `strike`, `ball`, `out`이 있습니다. +
+**printResult()** +
+게임 결과를 출력하는 메서드입니다. + +### `InputError` +사용자의 입력값에 오류가 있는지 확인하는 클래스입니다. +
+**checkInputErrorMain()** +
+메인 화면에서 입력값 오류가 있는지 확인합니다. +
+**checkInputErrorGame()** +
+게임 화면에서 입력값 오류가 있는지 확인합니다. + +