#57 桌遊棋類 App,比方蛇梯棋 (Snakes & Ladders)

目的: 練習製作桌遊棋類 App。

以 Apple The Swift Programming Language 介紹 while 迴圈的例子蛇梯棋為例

蛇梯棋遊戲說明

遊戲模式

1 全人工
跟朋友 PK,點選骰子移動角色。

2 全自動觀戰
角色自己移動,躺著也可以贏。

3 自己跟電腦 PK
輸到自己時,要點選骰子移動

基本版

  1. 玩家人數固定 2 人。
  2. 格子數 ( 25 或 100)
  3. 地圖採用現成的圖片,比方以下的圖片。

進階版

  1. 從程式繪製地圖。
  2. 可設定玩家人數 2 人,3 人或 4 人。

其它桌遊棋類例子:

象棋,西洋棋,跳棋,大富翁。

Apple 官方範例參考

let finalSquare = 25
var board = [Int](repeating: 0, count: finalSquare + 1)
board[03] = +08; board[06] = +11; board[09] = +09; board[10] = +02
board[14] = -10; board[19] = -11; board[22] = -02; board[24] = -08
var square = 0
var diceRoll = 0
repeat {
// move up or down for a snake or ladder
square += board[square]
// roll the dice
diceRoll += 1
if diceRoll == 7 { diceRoll = 1 }
// move by the rolled amount
square += diceRoll
} while square < finalSquare
print("Game over!")

App Store 範例

彼得潘的 100 道 Swift iOS App 謎題

適合新手練功的 100 道 Swift iOS App 謎題

彼得潘的 iOS App Neverland

Written by

彼得潘的 Swift 程式設計入門,App程式設計入門作者,彼得潘的iOS App程式設計入門,文組生的iOS App程式設計入門講師,http://apppeterpan.strikingly.com

彼得潘的 100 道 Swift iOS App 謎題

適合新手練功的 100 道 Swift iOS App 謎題

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade