Skip to content

Commit

Permalink
add: 함수별 파일 분리, 구조변경
Browse files Browse the repository at this point in the history
  • Loading branch information
dannykim1215 committed Jan 4, 2024
1 parent 9dc5970 commit f9f4d33
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 80 deletions.
24 changes: 24 additions & 0 deletions NumberBaseball/NumberBaseball.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
objects = {

/* Begin PBXBuildFile section */
2E6689692B464B00009123FF /* GenerateNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E6689682B464B00009123FF /* GenerateNumber.swift */; };
2E66896B2B464B1A009123FF /* UserInputNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E66896A2B464B1A009123FF /* UserInputNumber.swift */; };
2E66896D2B464B88009123FF /* CheckStrikeAndBall.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E66896C2B464B88009123FF /* CheckStrikeAndBall.swift */; };
2E66896F2B464C1B009123FF /* GameStart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E66896E2B464C1B009123FF /* GameStart.swift */; };
2E6689712B464C25009123FF /* GameEnd.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E6689702B464C25009123FF /* GameEnd.swift */; };
2E6689732B464FC4009123FF /* ExcuteGame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2E6689722B464FC4009123FF /* ExcuteGame.swift */; };
C7A29CFC2551372B00CAC77A /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7A29CFB2551372B00CAC77A /* main.swift */; };
/* End PBXBuildFile section */

Expand All @@ -23,6 +29,12 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
2E6689682B464B00009123FF /* GenerateNumber.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GenerateNumber.swift; sourceTree = "<group>"; };
2E66896A2B464B1A009123FF /* UserInputNumber.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserInputNumber.swift; sourceTree = "<group>"; };
2E66896C2B464B88009123FF /* CheckStrikeAndBall.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckStrikeAndBall.swift; sourceTree = "<group>"; };
2E66896E2B464C1B009123FF /* GameStart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameStart.swift; sourceTree = "<group>"; };
2E6689702B464C25009123FF /* GameEnd.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameEnd.swift; sourceTree = "<group>"; };
2E6689722B464FC4009123FF /* ExcuteGame.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExcuteGame.swift; sourceTree = "<group>"; };
C7A29CF82551372B00CAC77A /* NumberBaseball */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = NumberBaseball; sourceTree = BUILT_PRODUCTS_DIR; };
C7A29CFB2551372B00CAC77A /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -58,6 +70,12 @@
isa = PBXGroup;
children = (
C7A29CFB2551372B00CAC77A /* main.swift */,
2E6689722B464FC4009123FF /* ExcuteGame.swift */,
2E66896E2B464C1B009123FF /* GameStart.swift */,
2E6689702B464C25009123FF /* GameEnd.swift */,
2E6689682B464B00009123FF /* GenerateNumber.swift */,
2E66896A2B464B1A009123FF /* UserInputNumber.swift */,
2E66896C2B464B88009123FF /* CheckStrikeAndBall.swift */,
);
path = NumberBaseball;
sourceTree = "<group>";
Expand Down Expand Up @@ -120,6 +138,12 @@
buildActionMask = 2147483647;
files = (
C7A29CFC2551372B00CAC77A /* main.swift in Sources */,
2E6689692B464B00009123FF /* GenerateNumber.swift in Sources */,
2E66896B2B464B1A009123FF /* UserInputNumber.swift in Sources */,
2E66896D2B464B88009123FF /* CheckStrikeAndBall.swift in Sources */,
2E6689732B464FC4009123FF /* ExcuteGame.swift in Sources */,
2E66896F2B464C1B009123FF /* GameStart.swift in Sources */,
2E6689712B464C25009123FF /* GameEnd.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
25 changes: 25 additions & 0 deletions NumberBaseball/NumberBaseball/CheckStrikeAndBall.swift
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


}

}

45 changes: 45 additions & 0 deletions NumberBaseball/NumberBaseball/ExcuteGame.swift
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)

}
}
12 changes: 12 additions & 0 deletions NumberBaseball/NumberBaseball/GameEnd.swift
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 {

}
26 changes: 26 additions & 0 deletions NumberBaseball/NumberBaseball/GameStart.swift
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("중복된 숫자는 허용되지 않습니다!")
}
}
}

36 changes: 36 additions & 0 deletions NumberBaseball/NumberBaseball/GenerateNumber.swift
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
}

}

12 changes: 12 additions & 0 deletions NumberBaseball/NumberBaseball/UserInputNumber.swift
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 {

}
90 changes: 10 additions & 80 deletions NumberBaseball/NumberBaseball/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,89 +6,19 @@

import Foundation

enum GameFunc: String {
case start = "1"
case end = "2"
case other = "x" // 변경예정
}

func execute() {
print("1. 게임시작")
print("2. 게임종료")
print("원하는 기능을 선택해주세요: ", terminator: "")

guard let input = readLine(), !input.isEmpty else {
//execute()
return
class NumberBaseBall {
var comNumList: Array<String>
var userNumList: Array<String>
init(comNumList: Array<String>, userNumList: Array<String>) {
self.comNumList = comNumList
self.userNumList = userNumList
}

verify(menu: input)
}

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
}
let numberBaseball = NumberBaseBall(comNumList: [], userNumList: [])
numberBaseball.execute()



func compare(comNum: [String], userNum: [String]){
var userNumList: Array<String> = []

guard let inputUser = readLine() else {
return
}

var strike: Int = 0
var ball: Int = 0


}

func verify(menu: String) {
let selected = GameFunc(rawValue: menu)
switch selected {
case .start:
gameStart()
case .end:
//gameEnd()
print("")
case .other:
//execute()
print("")
}
}

func gameStart(){
var comNum: Array<String> = []
comNum = randomNumber()

guard var userInput = readLine() else {
return
}

let splitUserInput = userInput.components(separatedBy: " ")

if userInput.count < 3 {
print("입력이 잘못 되었습니다.")
print("숫자 3개를 띄어쓰기로 구분하여 입력해주세요.")
print("중복된 숫자는 허용되지 않습니다!")
}
}

0 comments on commit f9f4d33

Please sign in to comment.