#15 Choose Your Own Adventure — 開發一個互動式多重結局 App (swiftUI)

Yahan
彼得潘的 Swift iOS / Flutter App 開發教室
1 min readMay 29, 2024

成品:


import SwiftUI

struct ContentView: View {
var body: some View {
NavigationStack{
ZStack{
Color(red: 32/255, green: 53/255, blue: 70/255)
.ignoresSafeArea()
VStack {
Image("1")
.resizable()
.frame(width: 393,height: 391)
Spacer()
.frame(height: 50.0)

Text("在這一個奇幻的世界裡,龍族曾經是統治世界的霸主。然而,在一次人類和龍族的戰爭之後,龍族被擊敗,被迫隱居在深山之中。 而你是居住在一個偏僻的小村莊的少年,接下來你將會如何度過一生呢...")
.foregroundStyle(.white)
.font(.title3)

NavigationLink {
Page1_1()
} label: {
Text("故事開始")
.padding(10)
.bold()
.font(.title)
.background(Color(red: 246/255, green: 241/255, blue: 196/255))
.foregroundStyle(.black)
.cornerRadius(5)



}
.padding()

}
.padding()
}

}
}
}

#Preview {
ContentView()
}
//
// Page1_1.swift
// swiftUI Story
//
// Created by YaHan on 2024/5/29.
//

import SwiftUI

struct Page1_1: View {
var body: some View {
ZStack{
Color(red: 149/255, green: 142/255, blue: 85/255)
.ignoresSafeArea()
VStack {
Image("1-1")
.resizable()
.frame(width: 393,height: 391)
Spacer()
.frame(height: 50.0)

Text("有一天,你在村莊附近的森林裡探險時,意外地發現了一個龍蛋。你會:")
.foregroundStyle(.white)
.font(.title3)
.padding(.horizontal,10)

NavigationLink {
Page2_1()
} label: {
Text("將龍蛋帶回家,悉心照料它")
.padding(.horizontal,20)
.padding(.vertical,10)
.bold()
.font(.title3)
.background(Color(red: 192/255, green: 188/255, blue: 76/255))
.foregroundStyle(.black)

}
.padding()
NavigationLink {
Page1_2()
} label: {
Text("將龍蛋扔掉,不讓它孵化")
.padding(.horizontal,20)
.padding(.vertical,10)
.bold()
.font(.title3)
.background(Color(red: 192/255, green: 188/255, blue: 76/255))
.foregroundStyle(.black)

}
.padding(5)
}
}
}
}
#Preview {
Page1_1()
}

GiHub:

--

--