Skip to content

Commit

Permalink
feat: compare 함수 내 excute 함수 제거, gameEnd 파일 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
Diana-yjh committed Jan 4, 2024
1 parent 9efef7d commit 2e8b49c
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 35 deletions.
4 changes: 0 additions & 4 deletions NumberBaseball/NumberBaseball.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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 @@ -33,7 +32,6 @@
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>"; };
8BA1F3BF2B46562C00D80796 /* FlowChar_Baseball.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = FlowChar_Baseball.png; sourceTree = "<group>"; };
C7A29CF82551372B00CAC77A /* NumberBaseball */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = NumberBaseball; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -73,7 +71,6 @@
C7A29CFB2551372B00CAC77A /* main.swift */,
2E6689722B464FC4009123FF /* ExcuteGame.swift */,
2E66896E2B464C1B009123FF /* GameStart.swift */,
2E6689702B464C25009123FF /* GameEnd.swift */,
2E6689682B464B00009123FF /* GenerateNumber.swift */,
2E66896A2B464B1A009123FF /* UserInputNumber.swift */,
2E66896C2B464B88009123FF /* CheckStrikeAndBall.swift */,
Expand Down Expand Up @@ -145,7 +142,6 @@
2E66896D2B464B88009123FF /* CheckStrikeAndBall.swift in Sources */,
2E6689732B464FC4009123FF /* ExcuteGame.swift in Sources */,
2E66896F2B464C1B009123FF /* GameStart.swift in Sources */,
2E6689712B464C25009123FF /* GameEnd.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
15 changes: 3 additions & 12 deletions NumberBaseball/NumberBaseball/CheckStrikeAndBall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ import Foundation

extension NumberBaseBall {
func compare(){

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

while repeatTime > 0 {

strike = checkStrike()
ball = checkIfBall()
let strike = checkStrike()
let ball = checkIfBall()

print("\(strike) 스트라이크, \(ball)")

Expand All @@ -25,6 +20,7 @@ extension NumberBaseBall {
repeatTime = 9
break
}

repeatTime -= 1
print("남은 기회는 \(repeatTime)")

Expand All @@ -35,11 +31,7 @@ extension NumberBaseBall {
}

userInputNumber()

}

execute()

}

func checkStrike () -> Int {
Expand All @@ -66,6 +58,5 @@ extension NumberBaseBall {
}
return numberOfBall
}

}

10 changes: 3 additions & 7 deletions NumberBaseball/NumberBaseball/ExcuteGame.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ extension NumberBaseBall {
}

func execute() {

var flag: Bool = true

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

guard let input = readLine(), !input.isEmpty else {
//execute()
print("입력이 잘못 되었습니다.")
continue
}

Expand All @@ -35,11 +34,8 @@ extension NumberBaseBall {
case .start:
gameStart()
case .end:
//gameEnd()
flag = false
print("")
}
} while (flag)

}
}
}
3 changes: 0 additions & 3 deletions NumberBaseball/NumberBaseball/GameStart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import Foundation

extension NumberBaseBall {
func gameStart(){

generateNumber()
userInputNumber()


}
}

6 changes: 2 additions & 4 deletions NumberBaseball/NumberBaseball/GenerateNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ extension NumberBaseBall {
comNumList = []

while comNumList.count < 3 {
var randomNum = Int.random(in: 1...9)
let randomNum = Int.random(in: 1...9)

var randomNumStr = String(randomNum)
let randomNumStr = String(randomNum)

if !comNumList.contains(randomNumStr) {
comNumList.append(randomNumStr)
Expand All @@ -23,8 +23,6 @@ extension NumberBaseBall {
}

print(comNumList)

}

}

5 changes: 1 addition & 4 deletions NumberBaseball/NumberBaseball/UserInputNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ extension NumberBaseBall {
var flag: Bool = true

while flag {

guard let randomNum = readLine() else {
return
}

var splitUserInput = randomNum.components(separatedBy: " ")
let splitUserInput = randomNum.components(separatedBy: " ")

if splitUserInput[0] != splitUserInput[1] && splitUserInput[0] != splitUserInput[2] && splitUserInput[1] != splitUserInput[2] {
flag = false
userNumList = splitUserInput
}
}

compare()

}
}

Expand Down
1 change: 0 additions & 1 deletion NumberBaseball/NumberBaseball/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class NumberBaseBall {
self.comNumList = comNumList
self.userNumList = userNumList
}

}

let numberBaseball = NumberBaseBall(comNumList: [], userNumList: [])
Expand Down

0 comments on commit 2e8b49c

Please sign in to comment.