Skip to content

๐Ÿ•น๏ธ ๋น™๊ณ ๋กœ ๋ณด๋Š” ์šฐ๋ฆฌ ๋™๋„ค ๋ง›์ง‘_ํฌํ•ญํŽธ ๐ŸŒŠ

Notifications You must be signed in to change notification settings

DeveloperAcademy-POSTECH/2024-NC2-M16-GameCenter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

51 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

2024-NC2-M16-Game-Center

แ„€แ…ฆแ„‹แ…ตแ†ทแ„‰แ…ฆแ†ซแ„แ…ฅ

๏ฃฟ Authors

๊ฐ•ํฌ์ฃผ(Rad) ๊น€์œ ๋นˆ(Nini)
๐ŸŽจ ๋””์ž์ธ ๐ŸŽจ ๐ŸŽ ํ…Œํฌ ๐ŸŽ
๋ž˜๋“œ ๋‹ˆ๋‹ˆ

๐ŸŽฅ Youtube Link


๐Ÿ’ก About Game Center

Game Center แ„‰แ…ฉแ„€แ…ข


๐ŸŽฏ What we focus on?

๋ฉ€ํ‹ฐ ํ”Œ๋ ˆ์ด์–ด(์นœ๊ตฌ), ์ˆœ์œ„ํ‘œ(๋ฆฌ๋”๋ณด๋“œ), ๋ชฉํ‘œ ๋‹ฌ์„ฑ(์—…์ )

Focus on


๐Ÿ’ผ Use Case

๋ง›์ง‘ ํƒ๋ฐฉ์ด๋ผ๋Š” ์ฃผ์ œ๋ฅผ ๊ฒŒ์ด๋ฏธํ”ผ์ผ€์ด์…˜์„ ์ ์šฉํ•œ ๋น™๊ณ ๋ฅผ ํ†ตํ•ด ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•˜๋ฉฐ, ๊ฒŒ์ž„์„ผํ„ฐ์˜ ๊ธฐ๋Šฅ์„ ํ†ตํ•ด ์„œ๋ฒ„๋ฅผ ๋Œ€์‹ ํ•˜์—ฌ ์‚ฌ์šฉ์ž๊ฐ„์˜ ๊ฒฝ์Ÿ๊ณผ ์žฌ์ฐธ์—ฌ๋ฅผ ์œ ๋„ํ•œ๋‹ค.

Use Case Use Case2


๐Ÿ–ผ๏ธ Prototype

ย ย ย 
แ„‘แ…ณแ„…แ…ฉแ„แ…ฉแ„แ…กแ„‹แ…ตแ†ธ_แ„†แ…ฆแ„‹แ…ตแ†ซ แ„‘แ…ณแ„…แ…ฉแ„แ…ฉแ„แ…กแ„‹แ…ตแ†ธ_แ„‡แ…ตแ†ผแ„€แ…ฉ แ„‘แ…ณแ„…แ…ฉแ„แ…ฉแ„แ…กแ„‹แ…ตแ†ธ_แ„€แ…ฆแ„‹แ…ตแ†ทแ„‰แ…ฆแ†ซแ„แ…ฅ

๐Ÿ•น๏ธ Demo Video

prototype.mp4

๐Ÿ› ๏ธ About Code

1๏ธโƒฃ GameKit์„ ์‚ฌ์šฉํ•˜์—ฌ ํ˜„์žฌ ๋””๋ฐ”์ด์Šค์˜ ๊ฒŒ์ž„ ์„ผํ„ฐ ํ”Œ๋ ˆ์ด์–ด ์ธ์ฆ

-> ์ธ์ฆ๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ, ๊ฒŒ์ž„ ์„ผํ„ฐ ๋กœ๊ทธ์ธ ํ™”๋ฉด์„ ํ‘œ์‹œํ•˜์—ฌ ํ”Œ๋ ˆ์ด์–ด๊ฐ€ ๋กœ๊ทธ์ธํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์คŒ

import GameKit
// ๋กœ์ปฌ ํ”Œ๋ ˆ์ด์–ด ์ธ์ฆ ๋ฉ”์„œ๋“œ
    func authenticateLocalPlayer() {
        // ์ด๋ฏธ ์ธ์ฆ ์ค‘์ด๋ฉด ์ค‘๋ณต ์‹คํ–‰ ๋ฐฉ์ง€
        guard !authenticating else { return }
        authenticating = true

        // ์ธ์ฆ ํ•ธ๋“ค๋Ÿฌ ์„ค์ •
        GKLocalPlayer.local.authenticateHandler = { [weak self] viewController, error in
            guard let self = self else { return }
            self.authenticating = false
            if let error = error {
                print("Authentication failed: \\(error.localizedDescription)")
                self.isAuthenticated = false
            } else if let viewController = viewController {
                // ๋กœ๊ทธ์ธ ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ ํ‘œ์‹œ
                print("Game Center login required")
                if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
                   let window = windowScene.windows.first {
                    window.rootViewController?.present(viewController, animated: true, completion: nil)
                }
            } else if GKLocalPlayer.local.isAuthenticated {
                // ์ธ์ฆ ์„ฑ๊ณต
                self.isAuthenticated = true
                print("Player authenticated")
            } else {
                // ์ธ์ฆ ์‹คํŒจ
                self.isAuthenticated = false
                print("Player not authenticated")
            }
        }
    }

2๏ธโƒฃ Game Center ์ˆœ์œ„ํ‘œ(๋ฆฌ๋”๋ณด๋“œ)์— ์‚ฌ์šฉ์ž์˜ ์ ์ˆ˜ ๋ณด๋‚ด๊ธฐ

// (์ˆœ์œ„ํ‘œ๋ฅผ ์œ„ํ•œ) ๊ฒŒ์ž„์„ผํ„ฐ ์ ์ˆ˜ ์ €์žฅ ๋ฉ”์„œ๋“œ
    func reportBingoCount(_ count: Int) {
        // ์ธ์ฆ ์—ฌ๋ถ€ ํ™•์ธ
        guard isAuthenticated else {
            print("Player is not authenticated")
            return
        }

        let score = GKLeaderboardScore()
        score.leaderboardID = "์ˆœ์œ„ํ‘œ ID"
        // ์ˆœ์œ„ํ‘œ์— ๋ถ€์—ฌํ•ด์•ผ ํ•˜๋Š” ์˜์ˆซ์ž ์‹๋ณ„์ž - ์ด ID๋Š” 100์ž๋กœ ์ œํ•œ, ์˜๊ตฌ์ ์œผ๋กœ ์„ค์ •๋˜๋ฉฐ ๋‚˜์ค‘์— ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†์Œ
        score.value = Int(count)

        // ์ ์ˆ˜ ์ €์žฅ
        GKLeaderboard.submitScore(score.value, context: 0, player: GKLocalPlayer.local, leaderboardIDs: [score.leaderboardID]) { error in
            if let error = error {
                print("Failed to report score: \\(error.localizedDescription)")
            } else {
                print("Score reported successfully")
            }
        }
    }

3๏ธโƒฃ ๋ชฉํ‘œ ๋‹ฌ์„ฑ์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•œ ๋ฐ์ดํ„ฐ ์ „๋‹ฌ

// ๋ชฉํ‘œ(์—…์ ) ๋‹ฌ์„ฑ ๋ฉ”์„œ๋“œ
    func reportAchievement(identifier: String, percentComplete: Double) {
        // ์ธ์ฆ ์—ฌ๋ถ€ ํ™•์ธ
        guard isAuthenticated else {
            print("Player is not authenticated")
            return
        }

        // ๋ชฉํ‘œ ๊ฐ์ฒด ์ƒ์„ฑ ๋ฐ ์„ค์ •
        let achievement = GKAchievement(identifier: identifier)
        achievement.percentComplete = percentComplete
        achievement.showsCompletionBanner = true

        // ๋ชฉํ‘œ ๋‹ฌ์„ฑ ๋ณด๊ณ 
        GKAchievement.report([achievement]) { error in
            if let error = error {
                print("Failed to report achievement: \\(error.localizedDescription)")
            } else {
                print("Achievement reported successfully")
            }
        }
    }

4๏ธโƒฃ Game Center ์ˆœ์œ„ํ‘œ ๋ณด๊ธฐ

// ์ˆœ์œ„ํ‘œ ๋ณด๊ธฐ ๋ฉ”์„œ๋“œ
    func showLeaderboard() {
        let leaderboardID = "์ˆœ์œ„ํ‘œ ID"
        let viewController = GKGameCenterViewController(leaderboardID: leaderboardID, playerScope: .friendsOnly, timeScope: .allTime)
        viewController.gameCenterDelegate = self

        if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
            if let window = windowScene.windows.first {
                window.rootViewController?.present(viewController, animated: true, completion: nil)
            }
        }
    }

About

๐Ÿ•น๏ธ ๋น™๊ณ ๋กœ ๋ณด๋Š” ์šฐ๋ฆฌ ๋™๋„ค ๋ง›์ง‘_ํฌํ•ญํŽธ ๐ŸŒŠ

Topics

Resources

Stars

Watchers

Forks