骰子轉轉轉 APP

同時隨機執行三骰子,並可計數
(Random功能)

製作步驟

Step1: 從Google下載六個面的骰子圖

圖片轉自

Step2: 複製到Assets.xcassets資料夾

Step3: 設定畫面如下:
-> 6張 骰子圖
-> 2個 Button
-> 3個 Label

Step4: 宣告images陣列 (引號字串為Assets.xcassets中圖片名稱)

Step5: 按cmd鍵,將左邊三個骰子與右邊三個骰子的設定 Outlet Collection
leftDices, rightDices

Step6: 按cmd鍵,新增3個Label的Outlet設定
leftDicesLabel, rightDicesLabel, sumDicesLabel

Step7: 按cmd鍵,新增兩個 Button 的Outlet設定
leftButton, rightButton

Step8: 按cmd鍵,新增 Button 的Action設定
dicesButtonPress

Step9: 按 Button隨機出現骰子數字功能&顯示總和
透過randomDistribution產生隨機亂數,並顯示骰子圖案
(viewDidLoad中定義random最大值為骰子數量)
(需 import GameplayKit)

完成 骰子轉轉轉APP

GitHub網址:

--

--