diff --git a/iOS/baseball-game/baseball-game/GamePlay/GroundGraphics/BallCountView.swift b/iOS/baseball-game/baseball-game/GamePlay/GroundGraphics/BallCountView.swift index 5d6f6eca0..6892c50c4 100644 --- a/iOS/baseball-game/baseball-game/GamePlay/GroundGraphics/BallCountView.swift +++ b/iOS/baseball-game/baseball-game/GamePlay/GroundGraphics/BallCountView.swift @@ -142,7 +142,7 @@ class BallCountView: UIView { private func fill(with property: DrawingProperty, upto count: Int) { guard let targetLayers = countCircleLayers[property.row] else { return } - if count > property.maxColumn { + if count > property.maxColumn || count == 0 { targetLayers.forEach { layer in layer.backgroundColor = Color.clear } diff --git a/iOS/baseball-game/baseball-game/GamePlay/Model/BallCounter.swift b/iOS/baseball-game/baseball-game/GamePlay/Model/BallCounter.swift index 6619bceaf..c6cac37e9 100644 --- a/iOS/baseball-game/baseball-game/GamePlay/Model/BallCounter.swift +++ b/iOS/baseball-game/baseball-game/GamePlay/Model/BallCounter.swift @@ -36,23 +36,13 @@ class BallCounter { self.ball = 0 self.out = 0 - notiStrikeChange() - notiBallChange() - notiOutChange() + notiBallChange(ballType: BallCount.strike, count: self.strike) + notiBallChange(ballType: BallCount.ball, count: self.ball) + notiBallChange(ballType: BallCount.out, count: self.out) } - private func notiStrikeChange() { - let updateInfo: [String: Any] = ["ballType": BallCount.strike, "count": self.strike] - NotificationCenter.default.post(name: BallCounter.notiName, object: nil, userInfo: updateInfo) - } - - private func notiBallChange() { - let updateInfo: [String: Any] = ["ballType": BallCount.ball, "count": self.ball] - NotificationCenter.default.post(name: BallCounter.notiName, object: nil, userInfo: updateInfo) - } - - private func notiOutChange() { - let updateInfo: [String: Any] = ["ballType": BallCount.out, "count": self.out] + private func notiBallChange(ballType: BallCount, count: Int) { + let updateInfo: [String: Any] = ["ballType": ballType, "count": count] NotificationCenter.default.post(name: BallCounter.notiName, object: nil, userInfo: updateInfo) } @@ -65,31 +55,22 @@ class BallCounter { private func updateStrike(_ count: Int) { self.strike += count - notiStrikeChange() - - if self.strike == 3 { - self.strike = 0 - } + notiBallChange(ballType: BallCount.strike, count: self.strike) + if self.strike == 3 { self.strike = 0 } } private func updateBall(_ count: Int) { self.ball += count - - notiBallChange() - - if self.ball == 4 { - self.ball = 0 - } + + notiBallChange(ballType: BallCount.ball, count: self.ball) + if self.ball == 4 { self.ball = 0 } } private func updateOut(_ count: Int) { self.out += count - notiOutChange() - - if self.out == 3 { - self.out = 0 - } + notiBallChange(ballType: BallCount.out, count: self.out) + if self.out == 3 { self.out = 0 } } } diff --git a/iOS/baseball-game/baseball-game/GamePlay/Model/BaseManager.swift b/iOS/baseball-game/baseball-game/GamePlay/Model/BaseManager.swift index e5da74534..14d5268b9 100644 --- a/iOS/baseball-game/baseball-game/GamePlay/Model/BaseManager.swift +++ b/iOS/baseball-game/baseball-game/GamePlay/Model/BaseManager.swift @@ -43,6 +43,15 @@ class BaseManager { self.first = false self.second = false self.third = false + + notiBaseChanged(movement: BaseMovement.reset) + } + + static let notiName = Notification.Name.init("baseChanged") + + private func notiBaseChanged(movement: BaseMovement) { + let updateInfo: [String: Any] = ["movement": movement] + NotificationCenter.default.post(name: BaseManager.notiName, object: nil, userInfo: updateInfo) } func update(with baseInfo: BaseChanged) { @@ -62,36 +71,30 @@ class BaseManager { } - static let notiName = Notification.Name.init("baseChanged") - private func thirdToHome() { self.third = false - let updateInfo: [String: Any] = ["movement": BaseMovement.thirdToHome] - NotificationCenter.default.post(name: BaseManager.notiName, object: nil, userInfo: updateInfo) + notiBaseChanged(movement: BaseMovement.thirdToHome) } private func secondToThird() { self.second = false self.third = true - let updateInfo: [String: Any] = ["movement": BaseMovement.secondToThird] - NotificationCenter.default.post(name: BaseManager.notiName, object: nil, userInfo: updateInfo) + notiBaseChanged(movement: BaseMovement.secondToThird) } private func firstToSecond() { self.first = false self.second = true - let updateInfo: [String: Any] = ["movement": BaseMovement.firstToSecond] - NotificationCenter.default.post(name: BaseManager.notiName, object: nil, userInfo: updateInfo) + notiBaseChanged(movement: BaseMovement.firstToSecond) } private func homeToFirst() { self.first = true - let updateInfo: [String: Any] = ["movement": BaseMovement.homeToFirst] - NotificationCenter.default.post(name: BaseManager.notiName, object: nil, userInfo: updateInfo) + notiBaseChanged(movement: BaseMovement.homeToFirst) } } @@ -101,4 +104,5 @@ enum BaseMovement { case firstToSecond case secondToThird case thirdToHome + case reset } diff --git a/iOS/baseball-game/baseball-game/GamePlay/Model/GameManager.swift b/iOS/baseball-game/baseball-game/GamePlay/Model/GameManager.swift index 1e19f0fa7..d4aa42887 100644 --- a/iOS/baseball-game/baseball-game/GamePlay/Model/GameManager.swift +++ b/iOS/baseball-game/baseball-game/GamePlay/Model/GameManager.swift @@ -122,8 +122,8 @@ extension GameManager: GameUpdatable { } func changeBatter(to newBatter: Player) { + if self.batter.name != newBatter.name { self.ballCounter.reset() } self.batter = newBatter - self.ballCounter.reset() } func updateBallCount(with ballChanged: BallChanged) { diff --git a/iOS/baseball-game/baseball-game/GamePlay/ViewModel/GamePlayViewModel.swift b/iOS/baseball-game/baseball-game/GamePlay/ViewModel/GamePlayViewModel.swift index 8ba26bde9..a8d1d8b1d 100644 --- a/iOS/baseball-game/baseball-game/GamePlay/ViewModel/GamePlayViewModel.swift +++ b/iOS/baseball-game/baseball-game/GamePlay/ViewModel/GamePlayViewModel.swift @@ -38,11 +38,8 @@ class GamePlayViewModel { self.gameUpdator = self.gameManager self.pitchList = self.gameUpdator.pitchInfo() } - + }.store(in: &cancelBag) - self.gameManager = GameManager(userTeamSide: self.userTeamSide, teams: Teams(home: "하하하", away: "귀찮다"), batter: Player(name: "롤로", info: "귀찮음"), pitcher: Player(name: "리아", info: "화이팅!")) - self.gameUpdator = self.gameManager - self.pitchList = self.gameUpdator.pitchInfo() } func requestPitch() { @@ -53,42 +50,37 @@ class GamePlayViewModel { if let data = value.data { if let newInning = data.inning { self.gameManager.resetForNewInning(with: newInning) + } else { + if let newScore = data.score { + self.gameManager.updateScore(with: newScore) + } + + if let newPitch = data.newPitch { + self.gameManager.updatePitchList(with: newPitch) + self.pitchList = self.gameManager.pitchInfo() + } + + if let newBallInfo = data.ballChanged { + self.gameManager.updateBallCount(with: newBallInfo) + } + + if let newBaseInfo = data.baseChanged { + self.gameManager.updateBase(with: newBaseInfo) + } } - - if let newScore = data.score { - self.gameManager.updateScore(with: newScore) - } - + if let newBatter = data.batter { self.gameManager.changeBatter(to: newBatter) } - + if let newPitcher = data.pitcher { self.gameManager.changePitcher(to: newPitcher) } - if let newPitch = data.newPitch { - self.gameManager.updatePitchList(with: newPitch) - self.pitchList = self.gameManager.pitchInfo() - } - - if let newBallInfo = data.ballChanged { - self.gameManager.updateBallCount(with: newBallInfo) - } - - if let newBaseInfo = data.baseChanged { - self.gameManager.updateBase(with: newBaseInfo) - } self.gameUpdator = self.gameManager } - + }.store(in: &cancelBag) - self.gameManager.updatePitchList(with: Pitch(count: 1, result: "테스트", log: "1-1")) - self.gameManager.changeBatter(to: Player(name: "깔깔", info: "랄랄")) - self.gameManager.updateBallCount(with: BallChanged(strike: 1, ball: 0, out: 0)) - self.gameManager.updateBase(with: BaseChanged(first: BaseChanged.BaseStatus(baseIn: true, baseOut: false), second: nil, third: nil)) - self.gameUpdator = self.gameManager - self.pitchList = self.gameManager.pitchInfo() } }