-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9dc5970
commit f9f4d33
Showing
8 changed files
with
190 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// CheckWinOrLose.swift | ||
// NumberBaseball | ||
// | ||
// Created by 김민제 on 1/4/24. | ||
// | ||
|
||
import Foundation | ||
|
||
extension NumberBaseBall { | ||
func compare(comNum: [String], userNum: [String]){ | ||
var userNumList: Array<String> = [] | ||
|
||
guard let inputUser = readLine() else { | ||
return | ||
} | ||
|
||
var strike: Int = 0 | ||
var ball: Int = 0 | ||
|
||
|
||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// ExcuteGame.swift | ||
// NumberBaseball | ||
// | ||
// Created by 김민제 on 1/4/24. | ||
// | ||
|
||
import Foundation | ||
|
||
extension NumberBaseBall { | ||
enum GameFunc: String { | ||
case start = "1" | ||
case end = "2" | ||
} | ||
|
||
func execute() { | ||
|
||
var flag: Bool = true | ||
|
||
repeat { | ||
print("1. 게임시작") | ||
print("2. 게임종료") | ||
print("원하는 기능을 선택해주세요: ", terminator: "") | ||
|
||
guard let input = readLine(), !input.isEmpty else { | ||
//execute() | ||
continue | ||
} | ||
|
||
guard let selected = GameFunc(rawValue: input) else { | ||
continue | ||
} | ||
|
||
switch selected { | ||
case .start: | ||
gameStart() | ||
case .end: | ||
//gameEnd() | ||
flag = false | ||
print("") | ||
} | ||
} while (flag) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// GameEnd.swift | ||
// NumberBaseball | ||
// | ||
// Created by 김민제 on 1/4/24. | ||
// | ||
|
||
import Foundation | ||
|
||
extension NumberBaseBall { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// GameStart.swift | ||
// NumberBaseball | ||
// | ||
// Created by 김민제 on 1/4/24. | ||
// | ||
|
||
import Foundation | ||
|
||
extension NumberBaseBall { | ||
func gameStart(){ | ||
|
||
guard var userInput = readLine() else { | ||
return | ||
} | ||
|
||
let splitUserInput = userInput.components(separatedBy: " ") | ||
|
||
if userInput.count < 3 { | ||
print("입력이 잘못 되었습니다.") | ||
print("숫자 3개를 띄어쓰기로 구분하여 입력해주세요.") | ||
print("중복된 숫자는 허용되지 않습니다!") | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// GenerateNumber.swift | ||
// NumberBaseball | ||
// | ||
// Created by 김민제 on 1/4/24. | ||
// | ||
|
||
import Foundation | ||
|
||
extension NumberBaseBall { | ||
func randomNumber() -> [String] { | ||
var randomList: Array<String> = [] | ||
var randomNum1 = Int.random(in: 1...9) | ||
var randomNum2 = Int.random(in: 1...9) | ||
var randomNum3 = Int.random(in: 1...9) | ||
|
||
var flag: Bool = true | ||
|
||
while flag { | ||
if randomNum1 != randomNum2 && randomNum1 != randomNum3 && randomNum2 != randomNum3 { | ||
flag = false | ||
} else if randomNum1 == randomNum2 || randomNum2 == randomNum3 { | ||
randomNum2 = Int.random(in: 1...9) | ||
} else if randomNum1 == randomNum3 || randomNum2 == randomNum3 { | ||
randomNum3 = Int.random(in: 1...9) | ||
} | ||
} | ||
randomList.append(String(randomNum1)) | ||
randomList.append(String(randomNum2)) | ||
randomList.append(String(randomNum3)) | ||
|
||
return randomList | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// UserInputNumber.swift | ||
// NumberBaseball | ||
// | ||
// Created by 김민제 on 1/4/24. | ||
// | ||
|
||
import Foundation | ||
|
||
extension NumberBaseBall { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters