#195 Choose Your Own Adventure — 開發一個互動式多重結局 App

最近研究 Apple 的 Swift 範例程式,發現 Choose Your Own Adventure 滿有趣的,我們可以運用它創作互動式多重結局 App。

人生其實是一連串的選擇造就現在的我們。要是當初彼得潘選擇讀中文系,不是資工系,也許現在可以當躺著寫小說的作家。

Choose Your Own Adventure 把做選擇的概念用在虛擬世界,它讓我們化身上帝,做出一連串的選擇,改變小說、遊戲、影集和電影的結局。

知名的 Choose Your Own Adventure 小說

以小說為例,小說的某些地方會要讀者做選擇。下圖是恐怖小說 Return To Haunted House,第 6 頁介紹了兩個鬼屋,Montagoo Hall 和 Thailand,讀者可決定要前往的鬼屋,選擇 Montagoo Hall 請翻到下一頁,選擇 Thailand 請翻到第 14 頁。

了解 Choose Your Own Adventure 後,有興趣的朋友可以發揮創意編個故事,運用它開發有趣的互動式多重結局 App。

功能說明

  • 玩家做一連串的選擇,改變故事的結局。
  • 畫面上顯示故事的描述,問題和選項,玩家選擇不同的選項會跳到不同的頁面。
  • 使用以下其中一種方法開發。

方法 1: 無程式的做法。

用 storyboard & segue 開發。

方法 2: 程式的做法。

分成以下兩種。

  1. 使用 SwiftUI,以 NavigationLink 切換畫面。

2. 使用 UIKit,以 UINavigationController 的 pushViewController(_:animated:) 切換畫面。

採用程式做法時,每一頁的內容和選項可參考以下 Apple 範例的寫法,以 Choice 的 destination 控制跳到第幾頁,比方選擇 Back of the room 會跳到 index 2 的頁面(第三頁)。

[    
StoryPage( // 0 """
Welcome to Choose Your Own Story
🥖🍪Bake Off!🥐🍰

You enter a local baking competition at the county fair 🎪. It’s a beautiful summer day and you are excited! When you enter the room, you look around to see ten identical stations.

Each station is stocked with bowls of different sizes, spatulas, spoons, and a standing mixer. You are the third to arrive, so there are many stations still available. Where do you sit?
""",
choices: [
Choice(text: "Front row!", destination: 1),
Choice(text: "Find somewhere in the middle", destination: 1),
Choice(text: "Back of the room", destination: 2),
]
),
StoryPage( // 1
"""
Luckily, some nice people fill in around you and wave politely. The directions sounds fun! Make a sponge cake you would have wanted as a child for your birthday, focusing on the decorations and theme. The top three bakers will win a cash prize. You start with a theme.
""",
choices: [
Choice(text: "Trains", destination: 3),
Choice(text: "Castles", destination: 5),
Choice(text: "Rainbows", destination: 6),
Choice(text: "Woodland creatures", destination: 5),
Choice(text: "Outer space", destination: 3),
]
),
StoryPage( // 2
"""
Oh no. There is a very loud person next to you. You can barely hear the directions in the back of the room. You think they said something about a birthday cake. Luckily, the person in front of you whispers a brief review of what they said...glazing over a few things. “A birthday cake I would have wanted as a kid.” Hmm? You think back to your favorite cake.
""",
choices: [
Choice(text: "Chocolate", destination: 4),
Choice(text: "Red velvet", destination: 4),
Choice(text: "Vanilla confetti", destination: 5),
Choice(text: "Strawberry shortcake", destination: 3),
]
),

範例

  • Apple SwiftUI Sample Apps 的 Choose Your Own Story。
  • PBS 的 story book builder。

請 AI 編故事

請 AI 繪圖

作品集

  • SwiftUI
  • UIKit

--

--

彼得潘的 iOS App Neverland
彼得潘的 100 道 Swift iOS App 謎題

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