Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: yagom-academy/ios-number-baseball
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: dannykim1215/ios-number-baseball
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 13 commits
  • 10 files changed
  • 4 contributors

Commits on Jan 3, 2024

  1. Copy the full SHA
    a13ce26 View commit details
  2. Copy the full SHA
    96d90f3 View commit details

Commits on Jan 4, 2024

  1. Copy the full SHA
    9dc5970 View commit details
  2. Copy the full SHA
    f9f4d33 View commit details
  3. Copy the full SHA
    9b7c730 View commit details
  4. Copy the full SHA
    3749cf8 View commit details
  5. Copy the full SHA
    ae8b2c2 View commit details
  6. Copy the full SHA
    9efef7d View commit details
  7. Copy the full SHA
    2e8b49c View commit details

Commits on Jan 5, 2024

  1. Copy the full SHA
    8291401 View commit details
  2. Copy the full SHA
    aea0052 View commit details
  3. Copy the full SHA
    b085c2b View commit details

Commits on Jan 7, 2024

  1. Update README.md

    dannykim1215 authored Jan 7, 2024
    Copy the full SHA
    b7b358f View commit details
22 changes: 22 additions & 0 deletions NumberBaseball/NumberBaseball.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -7,6 +7,11 @@
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 */; };
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 */

@@ -23,6 +28,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>"; };
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; };
C7A29CFB2551372B00CAC77A /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -58,6 +69,12 @@
isa = PBXGroup;
children = (
C7A29CFB2551372B00CAC77A /* main.swift */,
2E6689722B464FC4009123FF /* ExcuteGame.swift */,
2E66896E2B464C1B009123FF /* GameStart.swift */,
2E6689682B464B00009123FF /* GenerateNumber.swift */,
2E66896A2B464B1A009123FF /* UserInputNumber.swift */,
2E66896C2B464B88009123FF /* CheckStrikeAndBall.swift */,
8BA1F3BF2B46562C00D80796 /* FlowChar_Baseball.png */,
);
path = NumberBaseball;
sourceTree = "<group>";
@@ -120,6 +137,11 @@
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 */,
);
runOnlyForDeploymentPostprocessing = 0;
};
57 changes: 57 additions & 0 deletions NumberBaseball/NumberBaseball/CheckStrikeAndBall.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// CheckWinOrLose.swift
// NumberBaseball
//
// Created by 김민제 on 1/4/24.
//

import Foundation

extension NumberBaseBall {
func compare(){
if repeatTime > 1 {
let strike = checkStrike()
let ball = checkIfBall()

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

if strike == 3 {
print("사용자 승리..!")
repeatTime = 9
} else {
repeatTime -= 1
print("남은 기회는 \(repeatTime)")
userInputNumber()
}
} else {
print("컴퓨터 승리...!")
repeatTime = 9
}
}

func checkStrike () -> Int {
var numberOfStrike: Int = 0

for i in 0...(userNumList.count - 1) {
if comNumList[i] == userNumList[i] {
numberOfStrike += 1
}
}
return numberOfStrike
}

func checkIfBall() -> Int {
var numberOfBall: Int = 0

for i in 0...(userNumList.count - 1) {
var changedComNumList: [String] = comNumList
changedComNumList[i] = "-1"

if changedComNumList.contains(userNumList[i]) {
numberOfBall += 1
}
}
return numberOfBall
}
}

41 changes: 41 additions & 0 deletions NumberBaseball/NumberBaseball/ExcuteGame.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// 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

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

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

guard let selected = GameFunc(rawValue: input) else {
continue
}

switch selected {
case .start:
gameStart()
case .end:
flag = false
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 {

}
16 changes: 16 additions & 0 deletions NumberBaseball/NumberBaseball/GameStart.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// GameStart.swift
// NumberBaseball
//
// Created by 김민제 on 1/4/24.
//

import Foundation

extension NumberBaseBall {
func gameStart(){
generateNumber()
userInputNumber()
}
}

27 changes: 27 additions & 0 deletions NumberBaseball/NumberBaseball/GenerateNumber.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// GenerateNumber.swift
// NumberBaseball
//
// Created by 김민제 on 1/4/24.
//

import Foundation

extension NumberBaseBall {
func generateNumber() {
comNumList = []

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

let randomNumStr = String(randomNum)

if !comNumList.contains(randomNumStr) {
comNumList.append(randomNumStr)
}
}

print(comNumList)
}
}

47 changes: 47 additions & 0 deletions NumberBaseball/NumberBaseball/UserInputNumber.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// UserInputNumber.swift
// NumberBaseball
//
// Created by 김민제 on 1/4/24.
//

import Foundation

extension NumberBaseBall {
func userInputNumber() {
userNumList = []

var flag: Bool = true

while flag {
print("입력해주세요 : ", terminator: "")

guard let randomNum = readLine() else {
return
}

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

if splitUserInput.count > 3 {
print("숫자 3개를 띄어쓰기로 구분하여 입력해주세요.")
continue
}

let deleteSameNumber: Array<String> = []

for i in 0...(splitUserInput.count - 1) {
let deleteSameNumber = splitUserInput.filter({$0 == splitUserInput[i]})
}

if deleteSameNumber.count == 3 {
flag = false
userNumList = splitUserInput
} else if deleteSameNumber.count > 3{
print("중복 숫자는 허용하지 않습니다.")
}
}
compare()
}
}


17 changes: 14 additions & 3 deletions NumberBaseball/NumberBaseball/main.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
//
// NumberBaseball - main.swift
// Created by yagom.
// Created by yagom.
// Copyright © yagom academy. All rights reserved.
//
//

import Foundation

print("Hello, World!")
class NumberBaseBall {
var comNumList: Array<String>
var userNumList: Array<String>
var repeatTime: Int = 9

init(comNumList: Array<String>, userNumList: Array<String>) {
self.comNumList = comNumList
self.userNumList = userNumList
}
}

let numberBaseball = NumberBaseBall(comNumList: [], userNumList: [])
numberBaseball.execute()
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
## iOS 커리어 스타터 캠프
# 숫자야구 프로젝트

### 숫자야구 프로젝트 저장소
#### 구성원: Diana, Danny

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

## 📝 요구사항
- 코드에 느낌표(!)를 작성하지 않습니다.
- 사용자 정의 타입을 구현하지 않고, 함수와 변수, 상수만으로 구현합니다.
- 코드 들여쓰기를 2번 초과하지 않습니다.
- Swift API Design Guidlines을 참고합니다.
- 코드에 주석을 남기지 않습니다.
- exit() 함수를 사용하지 않습니다.
- 해당 프로젝트는 짝프로그래밍을 통해 진행합니다.
</br>

## ✍️ FlowChart

![FlowChart_BaseballGame](https://github.com/Diana-yjh/ios-number-baseball/assets/57698939/e9a3bce5-c7ed-4a60-a34f-78742ba4d2c2)