Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
對戰三平棋
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
MarkFly
March 20, 2018
Programming
210
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
對戰三平棋
SIMPEI小遊戲實作分享 @ iOS Taipei
MarkFly
March 20, 2018
Transcript
23 slides
對戰三平棋 ⼩遊戲實作分享 iOS@Taipei 2018/3/20
謝騰⾶ 前接案公司iOS⼯程師 前鼎新電腦ERP顧問 Line: ledway917 歡迎各種合作
https://www.youtube.com/watch?v=iGzv1t9rV0c
None
遊戲規則 • ⼈數: 2⼈ • 率先連成三⼦者獲勝 • 每⼈各4顆棋⼦ • 棋盤分成上下兩個世界
遊戲流程 1. 第⼀顆棋只能放在上界中間四個位置 2. 雙⽅輪流放⼦ 3. 雙⽅輪流走⼦(只能走到異界的相臨位置) 4. 若過程中我⽅在同⼀世界夾住對⽅棋⼦ 則我⽅可將該棋⼦移⾄任何位置
BUT • 連成四⼦不算 • 四⼦移走⼀顆也不算 • 吹走對⼿棋⼦連三還是不算 • ⾃⼰走到⼈家中間去被夾住................................不算
None
在圖片上疊⼀個透明的view view上⾯拉格⼦的imageView imageView⽤autoresize去配合圖片 棋盤是⼀張圖 如何在適應各種螢幕尺⼨的前提下 讓棋⼦可以對準裡⾯的格⼦
對棋⼦imageView加入⼿勢UIPanGestureRecognizer 拿到座標就去修改棋⼦imageView的center 如何讓棋⼦移動
遍歷所有的位置 去算該位置是否夠靠近(這邊要做誤差修正) 太遠則清空提⽰ 如何讓移動時格⼦出現提⽰
• 第⼀回合 • 寫死5,6,9,10 • 放⼦、吹⼦ • All You Can
Place 各階段如何判斷可不可下 showMoveHint
1. 先判斷天堂或地獄 2. 地獄:有公式 3. 天堂:四個⾓跟中間也有公式 4. 邊棋只好HardCode 5. PS.右圖x跟y顛倒了.......(懶得改圖了Orz)
比較難搞的是走⼦階段
1. 同⾊同界的棋⼦數⼤於3 1. 同界周圍(x或y相減絕對值為1)是否有同⾊棋(第⼆顆棋) 1. 有第三顆棋(註1) 1. 地獄 1. 贏了
2. 天堂 1. 沒有第四顆棋(註2) 1. 贏了 如何判斷是否連線 checkLink(currentChess:Chess)
思路:根據1號棋跟2號棋的相對位置推算3號棋的位置 1. 可能在中間、可能在旁邊 2. 從八個⽅向去發散 如何判斷有無第三顆棋 assign3rdChessXandY
思路:窮舉10條可能的路線, 是否都有同⾊的棋⼦ 1. 由現有棋盤上的棋⼦坐標算出序號(by公式) 2. [(0,1),(4,1),(8,1),(12,1),(0,4),(1,4),(2,4),(3,4),(0,5),(3,3)] //(從哪個開頭,遞增多少) 3. 展出每條路線的序號跟第⼀點比對 如何判斷有無第四顆棋
isLineFourChess
思路:跟找連線判斷類似 如何判斷是否夾⼦ checkBetween(currentChess:Chess) -> Chess?
對戰流程 1. 設定:開房間的⼈為主場, 主場⼀律紅棋 2. 若WaitingRoom裡無房就開房,反之加入 3. 有⼈加入有把房間移到MappedRoom(先刪後加) 4. 等⼈加入時,
取消或斷線要把WaitingRoom的資料刪除 5. 隨機決定誰先 6. 主場建立新比賽
Firebase function 1. Database.database().reference(withPath: ".info/connected") 2. onDisconnectRemoveValue 3. onDisconnectSetValue 4.
observeSingleEvent 1. childAdded 2. childRemoved 3. childChanged 4. childMoved 5. value 5. observe 6. removeAllObservers 7. childByAutoId 8. child 9. setValue 10. removeValue
監聽對象 1. 換⼿ 2. 對⼿走⼦ 3. 對⼿夾⼦ 4. 對⼿贏了 5.
對⼿投降 6. 續戰邀約 7. 建立新比賽
再來⼀碗
https://www.asovision.com/simpei/ 了解更多…
感謝聆聽 圖片來源http://en.aobo-shop.com/114-simpei-japanese.html
More Decks by MarkFly
See All by MarkFly
關於 Mobile Developer 用 Flutter 去寫 Web 這檔事
mark33699
0
55
關於我在 visionOS 上 寫影片貼圖 app 這檔事
mark33699
0
320
iOS、Android、Flutter超級比一比
mark33699
1
1k
如何使用Swift遙控你的樂高
mark33699
0
76
直播簡單講
mark33699
1
130
多執行緒編程
mark33699
0
90
演算法到底是在演哪一齣
mark33699
0
100
Other Decks in Programming
See All in Programming
[Kotlin Fest 2026] eBPF Tracing for Kotlin
takehaya
1
410
眠らない開発チームの作り方
biwakonbu
0
180
Going Full Circle with Virtual Graphs and Relational Databases
michaelsimons
1
120
例外からRich Errorsまで Kotlinエラーハンドリングの進化を読み解く
shiita0903
0
260
初学者向け 分散トレーシングとDatadog
mtaka1222
0
120
Jujutsu で毎日のバージョン管理に「安心」と「直感性」を
oukayuka
0
130
R言語プログラミング
profjoesuzuki
0
150
DroidKnights 2026 Android A2UI Jetpack Compose 기반의 안전한 AI UI 렌더링 - 박제창
itsmedreamwalker
1
270
疎結合とは何か?ソフトウェア設計における結合バランスについて考える #phpcon_niigata
kajitack
2
450
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
290
テストだけで見つかる? Rubyでつくるメソッド発掘器
izawa
0
180
Spec-driven Development with AI
simas
PRO
0
2.3k
Featured
See All Featured
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.5k
How to build a perfect <img>
jonoalderson
1
6.3k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
4
1.3k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
330
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Raft: Consensus for Rubyists
vanstee
143
7.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.7k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
970
How to Think Like a Performance Engineer
csswizardry
28
3k
Faster Mobile Websites
deanohume
310
32k