Skip to content
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

Open
wants to merge 11 commits into
base: ic_11_hamzzi
Choose a base branch
from
56 changes: 55 additions & 1 deletion NumberBaseball/NumberBaseball/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,59 @@

import Foundation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import Foundation 을 사용하신 이유가 궁금합니다!!

Foundation 이 어떤 역할을 하는지 설명해주세요!


print("Hello, World!")
var comNumbers = [Int]()

Choose a reason for hiding this comment

The 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>()

Choose a reason for hiding this comment

The 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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

judge 라는 동사보다는 judgment 라는 명사를 사용하는것이 좋을것 같습니다!

파라미터의 네이밍또한 적절하지 않은것 같습니다!

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

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comNumbers 를 빈배열로 초기화하고 랜덤 숫자를 다시 할당하신 이유가 있을까요??
빈배열로 초기화 하는 코드는 불필요하다고 생각됩니다!!
userNumbers 또한 while 문에서 랜덤 숫자를 할당하고 있기 때문에 불필요하다고 생각됩니다!


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while 문을 적절히 잘 사용하신것같습니다!😀

print("컴퓨터 승리!")
}

startGame()
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

- 이 저장소를 자신의 저장소로 fork하여 프로젝트를 진행합니다

### 플로우 차트
<img src="./flow-chart-ios-number-baseball.png">
Binary file added flow-chart-ios-number-baseball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.