-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[STEP 1] Gray, Hamzzi #203
base: ic_11_hamzzi
Are you sure you want to change the base?
Changes from 10 commits
17ab751
7cc9054
ceb3d88
6b7c674
1db5ee3
fcd6adb
97eb3fa
fbee330
c9dc1ac
50f0c1a
8076185
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,59 @@ | |
|
||
import Foundation | ||
|
||
print("Hello, World!") | ||
var comNumbers = [Int]() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 변수의 네이밍은 줄임말보다는 명확한게 더 좋을거같습니다! |
||
var userNumbers = [Int]() | ||
var attemp = 9 | ||
|
||
func generateRandomNumbers() -> [Int] { | ||
var setNumber = Set<Int>() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. swift 에 이미 정의 되어있는 키워드는 변수명에 사용하지 않는 것이 좋을것같습니다! |
||
|
||
while setNumber.count < 3{ | ||
let randomNumber = Int.random(in: 1...9) | ||
setNumber.insert(randomNumber) | ||
} | ||
|
||
return [Int](setNumber) | ||
} | ||
|
||
func judgeResult(val: [Int]) -> (countStrike: Int, countBall: Int) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
파라미터의 네이밍또한 적절하지 않은것 같습니다! |
||
var countStrike = 0 | ||
var countBall = 0 | ||
|
||
for i in 0...2 { | ||
if (comNumbers.contains(userNumbers[i]) && comNumbers[i] == userNumbers[i]) { | ||
countStrike += 1 | ||
} else if (comNumbers.contains(userNumbers[i])) { | ||
countBall += 1 | ||
} | ||
} | ||
Comment on lines
+28
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if 문에서 소괄호는 생략가능한데 생략하지 않은 이유가 궁금합니다! |
||
print("\(countStrike) 스트라이크, \(countBall) 볼") | ||
|
||
return (countStrike, countBall) | ||
} | ||
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 튜플을 적절하게 잘 사용해주신것같습니다👍👍 |
||
|
||
func startGame() { | ||
comNumbers = [Int]() | ||
userNumbers = [Int]() | ||
attemp = 9 | ||
comNumbers = generateRandomNumbers() | ||
Comment on lines
+40
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
print("Computer: \(comNumbers)") | ||
while attemp > 0 { | ||
userNumbers = generateRandomNumbers() | ||
print("임의의 수 : \(userNumbers)") | ||
|
||
let result = judgeResult(val: userNumbers) | ||
|
||
if result.countStrike == 3 { | ||
print("WIN!") | ||
|
||
return | ||
} | ||
attemp -= 1 | ||
print("남은 기회 : \(attemp)") | ||
} | ||
Comment on lines
+47
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while 문을 적절히 잘 사용하신것같습니다!😀 |
||
print("컴퓨터 승리!") | ||
} | ||
|
||
startGame() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ | |
|
||
- 이 저장소를 자신의 저장소로 fork하여 프로젝트를 진행합니다 | ||
|
||
### 플로우 차트 | ||
<img src="./flow-chart-ios-number-baseball.png"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import Foundation
을 사용하신 이유가 궁금합니다!!Foundation
이 어떤 역할을 하는지 설명해주세요!