ソースコード source code

下記アプリの主要なソースコードを公開しています。アプリ開発の参考になれば幸いです。

画像等が別途必要ですので下記情報のみでアプリが完成するものではありません。 アプリは少しずつ機能拡張していますのでストア公開されているアプリと内容が異なる場合があります。 コードはコピーして自由にお使いいただけます。ただし著作権は放棄しておりませんので全部の再掲載はご遠慮ください。部分的に再掲載したり、改変して再掲載するのは構いません。 自身のアプリ作成の参考として個人使用・商用問わず自由にお使いいただけます。 コード記述のお手本を示すものではありません。ミニアプリですので変数名などさほど気遣いしていない部分も有りますし間違いも有るかと思いますので参考程度にお考え下さい。 他の賢者の皆様が公開されているコードを参考にした箇所も含まれます。iOSアプリ開発の熟練者が書いたコードではありません。 エンジニア向け技術情報共有サービスではありませんので説明は省いています。ご了承ください。 GitHubなどへの公開は予定しておりません。

下記コードの最終ビルド日: 2021-04-08

ConstValue.swift

//
//  ConstValue.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI

class ConstValue: ObservableObject {

    //background
    static let colorBg: Color = Color.init(red: 0, green: 124 / 255, blue: 64 / 256)
    
    //button color
    static let colorStart: Color = Color.init(red:0.238, green:0.77, blue:0.387)
    static let colorSetting: Color = Color.init(red:0.543, green:0.77, blue:0.289)
}

ContentView.swift

//
//  ContentView.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI
import GoogleMobileAds

struct ContentView: View {
    @EnvironmentObject var pub: PublicManager
    @State var buttonHeightRatio: CGFloat = 0.07
    //
    var body: some View {
        NavigationView {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    HStack(spacing: 0) {
                        NavigationLink(destination: Dice1View(),isActive: self.$pub.isDice1) {
                            Button(action:{
                                self.pub.isDice1 = true
                                self.pub.diceCount = 1
                            }){
                                Text("1")
                                    .frame(width: bodyView.size.width * 0.333, height: bodyView.size.height * self.buttonHeightRatio, alignment: .center)
                                    .foregroundColor(Color.white)
                            }
                        }
                        .background(ConstValue.colorSetting)
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height * self.buttonHeightRatio)
                        NavigationLink(destination: Dice2View(),isActive: self.$pub.isDice2) {
                            Button(action:{
                                self.pub.isDice2 = true
                                self.pub.diceCount = 2
                            }){
                                Text("2")
                                    .frame(width: bodyView.size.width * 0.333, height: bodyView.size.height * self.buttonHeightRatio, alignment: .center)
                                    .foregroundColor(Color.white)
                            }
                        }
                        .background(ConstValue.colorSetting)
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height * self.buttonHeightRatio)
                        NavigationLink(destination: Dice3View(),isActive: self.$pub.isDice3) {
                            Button(action:{
                                self.pub.isDice3 = true
                                self.pub.diceCount = 3
                            }){
                                Text("3")
                                    .frame(width: bodyView.size.width * 0.333, height: bodyView.size.height * self.buttonHeightRatio, alignment: .center)
                                    .foregroundColor(Color.white)
                            }
                        }
                        .background(ConstValue.colorSetting)
                    }
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    HStack(spacing: 0) {
                        NavigationLink(destination: Dice4View(),isActive: self.$pub.isDice4) {
                            Button(action:{
                                self.pub.isDice4 = true
                                self.pub.diceCount = 4
                            }){
                                Text("4")
                                    .frame(width: bodyView.size.width * 0.333, height: bodyView.size.height * self.buttonHeightRatio, alignment: .center)
                                    .foregroundColor(Color.white)
                            }
                        }
                        .background(ConstValue.colorSetting)
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height * self.buttonHeightRatio)
                        NavigationLink(destination: Dice5View(),isActive: self.$pub.isDice5) {
                            Button(action:{
                                self.pub.isDice5 = true
                                self.pub.diceCount = 5
                            }){
                                Text("5")
                                    .frame(width: bodyView.size.width * 0.333, height: bodyView.size.height * self.buttonHeightRatio, alignment: .center)
                                    .foregroundColor(Color.white)
                            }
                        }
                        .background(ConstValue.colorSetting)
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height * self.buttonHeightRatio)
                        NavigationLink(destination: Dice6View(),isActive: self.$pub.isDice6) {
                            Button(action:{
                                self.pub.isDice6 = true
                                self.pub.diceCount = 6
                            }){
                                Text("6")
                                    .frame(width: bodyView.size.width * 0.333, height: bodyView.size.height * self.buttonHeightRatio, alignment: .center)
                                    .foregroundColor(Color.white)
                            }
                        }
                        .background(ConstValue.colorSetting)
                    }
                    .frame(width:bodyView.size.width, height:bodyView.size.height * self.buttonHeightRatio)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    HStack(spacing: 0) {
                        NavigationLink(destination: Dice7View(),isActive: self.$pub.isDice7) {
                            Button(action:{
                                self.pub.isDice7 = true
                                self.pub.diceCount = 7
                            }){
                                Text("7")
                                    .frame(width: bodyView.size.width * 0.333, height: bodyView.size.height * self.buttonHeightRatio, alignment: .center)
                                    .foregroundColor(Color.white)
                            }
                        }
                        .background(ConstValue.colorSetting)
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height * self.buttonHeightRatio)
                        NavigationLink(destination: Dice8View(),isActive: self.$pub.isDice8) {
                            Button(action:{
                                self.pub.isDice8 = true
                                self.pub.diceCount = 8
                            }){
                                Text("8")
                                    .frame(width: bodyView.size.width * 0.333, height: bodyView.size.height * self.buttonHeightRatio, alignment: .center)
                                    .foregroundColor(Color.white)
                            }
                        }
                        .background(ConstValue.colorSetting)
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height * self.buttonHeightRatio)
                        NavigationLink(destination: Dice9View(),isActive: self.$pub.isDice9) {
                            Button(action:{
                                self.pub.isDice9 = true
                                self.pub.diceCount = 9
                            }){
                                Text("9")
                                    .frame(width: bodyView.size.width * 0.333, height: bodyView.size.height * self.buttonHeightRatio, alignment: .center)
                                    .foregroundColor(Color.white)
                            }
                        }
                        .background(ConstValue.colorSetting)
                    }
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    ScrollView {
                        HStack(spacing: 0) {
                            Image("dicetext").resizable()
                                .frame(width: bodyView.size.width, height: bodyView.size.width)
                        }
                    }
                    Spacer()
                    ZStack(alignment: .bottom) {
                        HStack(spacing: 0) {
                            Spacer(minLength: 0)
                            PublicManager.AdView().frame(maxWidth: bodyView.size.width, maxHeight: 50)
                            Spacer(minLength: 0)
                        }.background(Color(red:0.2,green:0.2,blue:0.2))
                    }
                }
                .background(ConstValue.colorBg)
                //.navigationBarTitle("")
                .navigationBarHidden(true)
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .onAppear {     //アプリ起動時に実行
            if self.pub.diceCount == 1 {
                self.pub.isDice1 = true
            } else if self.pub.diceCount == 2 {
                self.pub.isDice2 = true
            } else if self.pub.diceCount == 3 {
                self.pub.isDice3 = true
            } else if self.pub.diceCount == 4 {
                self.pub.isDice4 = true
            } else if self.pub.diceCount == 5 {
                self.pub.isDice5 = true
            } else if self.pub.diceCount == 6 {
                self.pub.isDice6 = true
            } else if self.pub.diceCount == 7 {
                self.pub.isDice7 = true
            } else if self.pub.diceCount == 8 {
                self.pub.isDice8 = true
            } else if self.pub.diceCount == 9 {
                self.pub.isDice9 = true
            }
        }
    }
    
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            ContentView().environmentObject(PublicManager())
        }
    }
}

Dice1View.swift

//
//  Dice9View.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI
import GoogleMobileAds

struct Dice1View: View {
    @EnvironmentObject var pub: PublicManager
    @State private var diceImage1: String = "dice7"
    private var diceImagePrefix: String = "dice"
    @State private var timeLine: Int = 0
    @State private var busyFlag: Bool = false   //実行中
    @State private var destroyFlag: Bool = false
    //
    var body: some View {
        NavigationView {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    HStack(spacing: 0) {
                        Button(action:{
                            self.startAction()
                        }){
                            Text("start")
                                .frame(width:bodyView.size.width / 4 * 3, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorStart)
                                .foregroundColor(Color.white)
                        }
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height / 6)
                        Button(action:{
                            if self.busyFlag {
                                return
                            }
                            self.pub.isDice1 = false
                        }){
                            Text("back")
                                .frame(width: bodyView.size.width / 4, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorSetting)
                                .foregroundColor(Color.white)
                        }
                        .background(ConstValue.colorSetting)
                    }
                    .frame(width:bodyView.size.width, height:bodyView.size.height / 6)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    ZStack(alignment: .bottom) {
                        ScrollView {
                            VStack {
                                Spacer(minLength: bodyView.size.height * 0.05)
                                HStack {
                                    Image(self.diceImage1).resizable()
                                        .frame(width: bodyView.size.width * 0.9, height: bodyView.size.width * 0.9)
                                }
                            }
                            Spacer(minLength: 150)
                        }
                        HStack(spacing: 0) {
                            Spacer(minLength: 0)
                            PublicManager.AdView().frame(maxWidth: bodyView.size.width, maxHeight: 50)
                            Spacer(minLength: 0)
                        }.background(Color(red:0.2,green:0.2,blue:0.2))
                    }
                }
                .background(ConstValue.colorBg)
                //.navigationBarTitle("")
                .navigationBarHidden(true)
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .navigationBarHidden(true)
        .onDisappear {     //アプリ終了時
            self.destroyFlag = true
        }
    }
    
    //start button on click
    private func startAction() {
        if self.busyFlag {
            return
        }
        self.busyFlag = true
        //
        self.timeLine = 0
        self.timeLineAnimation()
    }

    //animation
    private func timeLineAnimation() {
        withAnimation {
            if self.destroyFlag {
                return
            }
            self.timeLine += 1
            if self.timeLine > 30 {
                self.setImageResult()
                self.busyFlag = false
                return
            }
            self.setImage()
            DispatchQueue.global().async {
                Thread.sleep(forTimeInterval: 0.02)
                DispatchQueue.main.sync {
                    if self.destroyFlag == false {
                        self.timeLineAnimation()
                    }
                }
            }
        }
    }

    private func setImage() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 7...12))
    }

    private func setImageResult() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 1...6))
    }

}

struct Dice1View_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            Dice1View().environmentObject(PublicManager())
        }
    }
}

Dice2View.swift

//
//  Dice9View.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI
import GoogleMobileAds

struct Dice2View: View {
    @EnvironmentObject var pub: PublicManager
    @State private var diceImage1: String = "dice7"
    @State private var diceImage2: String = "dice8"
    private var diceImagePrefix: String = "dice"
    @State private var timeLine: Int = 0
    @State private var busyFlag: Bool = false   //実行中
    @State private var destroyFlag: Bool = false
    //
    var body: some View {
        NavigationView {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    HStack(spacing: 0) {
                        Button(action:{
                            self.startAction()
                        }){
                            Text("start")
                                .frame(width:bodyView.size.width / 4 * 3, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorStart)
                                .foregroundColor(Color.white)
                        }
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height / 6)
                        Button(action:{
                            if self.busyFlag {
                                return
                            }
                            self.pub.isDice2 = false
                        }){
                            Text("back")
                                .frame(width: bodyView.size.width / 4, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorSetting)
                                .foregroundColor(Color.white)
                        }
                        .background(ConstValue.colorSetting)
                    }
                    .frame(width:bodyView.size.width, height:bodyView.size.height / 6)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    ZStack(alignment: .bottom) {
                        ScrollView {
                            VStack {
                                Spacer(minLength: bodyView.size.height * 0.1)
                                HStack {
                                    Image(self.diceImage1).resizable()
                                        .frame(width: bodyView.size.width * 0.45, height: bodyView.size.width * 0.45)
                                    Image(self.diceImage2).resizable()
                                        .frame(width: bodyView.size.width * 0.45, height: bodyView.size.width * 0.45)
                                }
                            }
                            Spacer(minLength: 150)
                        }
                        HStack(spacing: 0) {
                            Spacer(minLength: 0)
                            PublicManager.AdView().frame(maxWidth: bodyView.size.width, maxHeight: 50)
                            Spacer(minLength: 0)
                        }.background(Color(red:0.2,green:0.2,blue:0.2))
                    }
                }
                .background(ConstValue.colorBg)
                //.navigationBarTitle("")
                .navigationBarHidden(true)
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .navigationBarHidden(true)
        .onDisappear {     //アプリ終了時
            self.destroyFlag = true
        }
    }
    
    //start button on click
    private func startAction() {
        if self.busyFlag {
            return
        }
        self.busyFlag = true
        //
        self.timeLine = 0
        self.timeLineAnimation()
    }

    //animation
    private func timeLineAnimation() {
        withAnimation {
            if self.destroyFlag {
                return
            }
            self.timeLine += 1
            if self.timeLine > 30 {
                self.setImageResult()
                self.busyFlag = false
                return
            }
            self.setImage()
            DispatchQueue.global().async {
                Thread.sleep(forTimeInterval: 0.02)
                DispatchQueue.main.sync {
                    if self.destroyFlag == false {
                        self.timeLineAnimation()
                    }
                }
            }
        }
    }

    private func setImage() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 7...12))
    }

    private func setImageResult() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 1...6))
    }

}

struct Dice2View_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            Dice2View().environmentObject(PublicManager())
        }
    }
}

Dice3View.swift

//
//  Dice9View.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI
import GoogleMobileAds

struct Dice3View: View {
    @EnvironmentObject var pub: PublicManager
    @State private var diceImage1: String = "dice7"
    @State private var diceImage2: String = "dice8"
    @State private var diceImage3: String = "dice9"
    private var diceImagePrefix: String = "dice"
    @State private var timeLine: Int = 0
    @State private var busyFlag: Bool = false   //実行中
    @State private var destroyFlag: Bool = false
    //
    var body: some View {
        NavigationView {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    HStack(spacing: 0) {
                        Button(action:{
                            self.startAction()
                        }){
                            Text("start")
                                .frame(width:bodyView.size.width / 4 * 3, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorStart)
                                .foregroundColor(Color.white)
                        }
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height / 6)
                        Button(action:{
                            if self.busyFlag {
                                return
                            }
                            self.pub.isDice3 = false
                        }){
                            Text("back")
                                .frame(width: bodyView.size.width / 4, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorSetting)
                                .foregroundColor(Color.white)
                        }
                        .background(ConstValue.colorSetting)
                    }
                    .frame(width:bodyView.size.width, height:bodyView.size.height / 6)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    ZStack(alignment: .bottom) {
                        ScrollView {
                            VStack {
                                Spacer(minLength: bodyView.size.height * 0.05)
                                HStack {
                                    Image(self.diceImage1).resizable()
                                        .frame(width: bodyView.size.width * 0.45, height: bodyView.size.width * 0.45)
                                    Image(self.diceImage2).resizable()
                                        .frame(width: bodyView.size.width * 0.45, height: bodyView.size.width * 0.45)
                                }
                                HStack {
                                    Image(self.diceImage3).resizable()
                                        .frame(width: bodyView.size.width * 0.45, height: bodyView.size.width * 0.45)
                                }
                            }
                            Spacer(minLength: 150)
                        }
                        HStack(spacing: 0) {
                            Spacer(minLength: 0)
                            PublicManager.AdView().frame(maxWidth: bodyView.size.width, maxHeight: 50)
                            Spacer(minLength: 0)
                        }.background(Color(red:0.2,green:0.2,blue:0.2))
                    }
                }
                .background(ConstValue.colorBg)
                //.navigationBarTitle("")
                .navigationBarHidden(true)
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .navigationBarHidden(true)
        .onDisappear {     //アプリ終了時
            self.destroyFlag = true
        }
    }
    
    //start button on click
    private func startAction() {
        if self.busyFlag {
            return
        }
        self.busyFlag = true
        //
        self.timeLine = 0
        self.timeLineAnimation()
    }

    //animation
    private func timeLineAnimation() {
        withAnimation {
            if self.destroyFlag {
                return
            }
            self.timeLine += 1
            if self.timeLine > 30 {
                self.setImageResult()
                self.busyFlag = false
                return
            }
            self.setImage()
            DispatchQueue.global().async {
                Thread.sleep(forTimeInterval: 0.02)
                DispatchQueue.main.sync {
                    if self.destroyFlag == false {
                        self.timeLineAnimation()
                    }
                }
            }
        }
    }

    private func setImage() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 7...12))
    }

    private func setImageResult() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 1...6))
    }

}

struct Dice3View_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            Dice3View().environmentObject(PublicManager())
        }
    }
}

Dice4View.swift

//
//  Dice9View.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI
import GoogleMobileAds

struct Dice4View: View {
    @EnvironmentObject var pub: PublicManager
    @State private var diceImage1: String = "dice7"
    @State private var diceImage2: String = "dice8"
    @State private var diceImage3: String = "dice9"
    @State private var diceImage4: String = "dice10"
    private var diceImagePrefix: String = "dice"
    @State private var timeLine: Int = 0
    @State private var busyFlag: Bool = false   //実行中
    @State private var destroyFlag: Bool = false
    //
    var body: some View {
        NavigationView {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    HStack(spacing: 0) {
                        Button(action:{
                            self.startAction()
                        }){
                            Text("start")
                                .frame(width:bodyView.size.width / 4 * 3, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorStart)
                                .foregroundColor(Color.white)
                        }
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height / 6)
                        Button(action:{
                            if self.busyFlag {
                                return
                            }
                            self.pub.isDice4 = false
                        }){
                            Text("back")
                                .frame(width: bodyView.size.width / 4, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorSetting)
                                .foregroundColor(Color.white)
                        }
                        .background(ConstValue.colorSetting)
                    }
                    .frame(width:bodyView.size.width, height:bodyView.size.height / 6)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    ZStack(alignment: .bottom) {
                        ScrollView {
                            VStack {
                                Spacer(minLength: bodyView.size.height * 0.05)
                                HStack {
                                    Image(self.diceImage1).resizable()
                                        .frame(width: bodyView.size.width * 0.45, height: bodyView.size.width * 0.45)
                                    Image(self.diceImage2).resizable()
                                        .frame(width: bodyView.size.width * 0.45, height: bodyView.size.width * 0.45)
                                }
                                HStack {
                                    Image(self.diceImage3).resizable()
                                        .frame(width: bodyView.size.width * 0.45, height: bodyView.size.width * 0.45)
                                    Image(self.diceImage4).resizable()
                                        .frame(width: bodyView.size.width * 0.45, height: bodyView.size.width * 0.45)
                                }
                            }
                            Spacer(minLength: 150)
                        }
                        HStack(spacing: 0) {
                            Spacer(minLength: 0)
                            PublicManager.AdView().frame(maxWidth: bodyView.size.width, maxHeight: 50)
                            Spacer(minLength: 0)
                        }.background(Color(red:0.2,green:0.2,blue:0.2))
                    }
                }
                .background(ConstValue.colorBg)
                //.navigationBarTitle("")
                .navigationBarHidden(true)
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .navigationBarHidden(true)
        .onChange(of: self.pub.isDice4) { _ in    //SettingViewからの戻り
            self.pub.diceCount = 4
        }
        .onDisappear {     //アプリ終了時
            self.destroyFlag = true
        }
    }
    
    //start button on click
    private func startAction() {
        if self.busyFlag {
            return
        }
        self.busyFlag = true
        //
        self.timeLine = 0
        self.timeLineAnimation()
    }

    //animation
    private func timeLineAnimation() {
        withAnimation {
            if self.destroyFlag {
                return
            }
            self.timeLine += 1
            if self.timeLine > 30 {
                self.setImageResult()
                self.busyFlag = false
                return
            }
            self.setImage()
            DispatchQueue.global().async {
                Thread.sleep(forTimeInterval: 0.02)
                DispatchQueue.main.sync {
                    if self.destroyFlag == false {
                        self.timeLineAnimation()
                    }
                }
            }
        }
    }

    private func setImage() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage4 = self.diceImagePrefix + String(Int.random(in: 7...12))
    }

    private func setImageResult() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage4 = self.diceImagePrefix + String(Int.random(in: 1...6))
    }

}

struct Dice4View_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            Dice4View().environmentObject(PublicManager())
        }
    }
}

Dice5View.swift

//
//  Dice9View.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI
import GoogleMobileAds

struct Dice5View: View {
    @EnvironmentObject var pub: PublicManager
    @State private var diceImage1: String = "dice7"
    @State private var diceImage2: String = "dice8"
    @State private var diceImage3: String = "dice9"
    @State private var diceImage4: String = "dice10"
    @State private var diceImage5: String = "dice11"
    private var diceImagePrefix: String = "dice"
    @State private var timeLine: Int = 0
    @State private var busyFlag: Bool = false   //実行中
    @State private var destroyFlag: Bool = false
    //
    var body: some View {
        NavigationView {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    HStack(spacing: 0) {
                        Button(action:{
                            self.startAction()
                        }){
                            Text("start")
                                .frame(width:bodyView.size.width / 4 * 3, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorStart)
                                .foregroundColor(Color.white)
                        }
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height / 6)
                        Button(action:{
                            if self.busyFlag {
                                return
                            }
                            self.pub.isDice5 = false
                        }){
                            Text("back")
                                .frame(width: bodyView.size.width / 4, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorSetting)
                                .foregroundColor(Color.white)
                        }
                        .background(ConstValue.colorSetting)
                    }
                    .frame(width:bodyView.size.width, height:bodyView.size.height / 6)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    ZStack(alignment: .bottom) {
                        ScrollView {
                            VStack {
                                Spacer(minLength: bodyView.size.height * 0.09)
                                HStack {
                                    Image(self.diceImage1).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage2).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage3).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                                HStack {
                                    Image(self.diceImage4).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage5).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                            }
                            Spacer(minLength: 150)
                        }
                        HStack(spacing: 0) {
                            Spacer(minLength: 0)
                            PublicManager.AdView().frame(maxWidth: bodyView.size.width, maxHeight: 50)
                            Spacer(minLength: 0)
                        }.background(Color(red:0.2,green:0.2,blue:0.2))
                    }
                }
                .background(ConstValue.colorBg)
                //.navigationBarTitle("")
                .navigationBarHidden(true)
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .navigationBarHidden(true)
        .onDisappear {     //アプリ終了時
            self.destroyFlag = true
        }
    }
    
    //start button on click
    private func startAction() {
        if self.busyFlag {
            return
        }
        self.busyFlag = true
        //
        self.timeLine = 0
        self.timeLineAnimation()
    }

    //animation
    private func timeLineAnimation() {
        withAnimation {
            if self.destroyFlag {
                return
            }
            self.timeLine += 1
            if self.timeLine > 30 {
                self.setImageResult()
                self.busyFlag = false
                return
            }
            self.setImage()
            DispatchQueue.global().async {
                Thread.sleep(forTimeInterval: 0.02)
                DispatchQueue.main.sync {
                    if self.destroyFlag == false {
                        self.timeLineAnimation()
                    }
                }
            }
        }
    }

    private func setImage() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage4 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage5 = self.diceImagePrefix + String(Int.random(in: 7...12))
    }

    private func setImageResult() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage4 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage5 = self.diceImagePrefix + String(Int.random(in: 1...6))
    }

}

struct Dice5View_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            Dice5View().environmentObject(PublicManager())
        }
    }
}

Dice6View.swift

//
//  Dice9View.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI
import GoogleMobileAds

struct Dice6View: View {
    @EnvironmentObject var pub: PublicManager
    @State private var diceImage1: String = "dice7"
    @State private var diceImage2: String = "dice8"
    @State private var diceImage3: String = "dice9"
    @State private var diceImage4: String = "dice10"
    @State private var diceImage5: String = "dice11"
    @State private var diceImage6: String = "dice12"
    private var diceImagePrefix: String = "dice"
    @State private var timeLine: Int = 0
    @State private var busyFlag: Bool = false   //実行中
    @State private var destroyFlag: Bool = false
    //
    var body: some View {
        NavigationView {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    HStack(spacing: 0) {
                        Button(action:{
                            self.startAction()
                        }){
                            Text("start")
                                .frame(width:bodyView.size.width / 4 * 3, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorStart)
                                .foregroundColor(Color.white)
                        }
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height / 6)
                        Button(action:{
                            if self.busyFlag {
                                return
                            }
                            self.pub.isDice6 = false
                        }){
                            Text("back")
                                .frame(width: bodyView.size.width / 4, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorSetting)
                                .foregroundColor(Color.white)
                        }
                        .background(ConstValue.colorSetting)
                    }
                    .frame(width:bodyView.size.width, height:bodyView.size.height / 6)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    ZStack(alignment: .bottom) {
                        ScrollView {
                            VStack {
                                Spacer(minLength: bodyView.size.height * 0.09)
                                HStack {
                                    Image(self.diceImage1).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage2).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage3).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                                HStack {
                                    Image(self.diceImage4).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage5).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage6).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                            }
                            Spacer(minLength: 150)
                        }
                        HStack(spacing: 0) {
                            Spacer(minLength: 0)
                            PublicManager.AdView().frame(maxWidth: bodyView.size.width, maxHeight: 50)
                            Spacer(minLength: 0)
                        }.background(Color(red:0.2,green:0.2,blue:0.2))
                    }
                }
                .background(ConstValue.colorBg)
                //.navigationBarTitle("")
                .navigationBarHidden(true)
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .navigationBarHidden(true)
        .onDisappear {     //アプリ終了時
            self.destroyFlag = true
        }
    }
    
    //start button on click
    private func startAction() {
        if self.busyFlag {
            return
        }
        self.busyFlag = true
        //
        self.timeLine = 0
        self.timeLineAnimation()
    }

    //animation
    private func timeLineAnimation() {
        withAnimation {
            if self.destroyFlag {
                return
            }
            self.timeLine += 1
            if self.timeLine > 30 {
                self.setImageResult()
                self.busyFlag = false
                return
            }
            self.setImage()
            DispatchQueue.global().async {
                Thread.sleep(forTimeInterval: 0.02)
                DispatchQueue.main.sync {
                    if self.destroyFlag == false {
                        self.timeLineAnimation()
                    }
                }
            }
        }
    }

    private func setImage() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage4 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage5 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage6 = self.diceImagePrefix + String(Int.random(in: 7...12))
    }

    private func setImageResult() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage4 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage5 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage6 = self.diceImagePrefix + String(Int.random(in: 1...6))
    }

}

struct Dice6View_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            Dice6View().environmentObject(PublicManager())
        }
    }
}

Dice7View.swift

//
//  Dice9View.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI
import GoogleMobileAds

struct Dice7View: View {
    @EnvironmentObject var pub: PublicManager
    @State private var diceImage1: String = "dice7"
    @State private var diceImage2: String = "dice8"
    @State private var diceImage3: String = "dice9"
    @State private var diceImage4: String = "dice10"
    @State private var diceImage5: String = "dice11"
    @State private var diceImage6: String = "dice12"
    @State private var diceImage7: String = "dice7"
    private var diceImagePrefix: String = "dice"
    @State private var timeLine: Int = 0
    @State private var busyFlag: Bool = false   //実行中
    @State private var destroyFlag: Bool = false
    //
    var body: some View {
        NavigationView {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    HStack(spacing: 0) {
                        Button(action:{
                            self.startAction()
                        }){
                            Text("start")
                                .frame(width:bodyView.size.width / 4 * 3, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorStart)
                                .foregroundColor(Color.white)
                        }
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height / 6)
                        Button(action:{
                            if self.busyFlag {
                                return
                            }
                            self.pub.isDice7 = false
                        }){
                            Text("back")
                                .frame(width: bodyView.size.width / 4, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorSetting)
                                .foregroundColor(Color.white)
                        }
                        .background(ConstValue.colorSetting)
                    }
                    .frame(width:bodyView.size.width, height:bodyView.size.height / 6)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    ZStack(alignment: .bottom) {
                        ScrollView {
                            VStack {
                                Spacer(minLength: bodyView.size.height * 0.05)
                                HStack {
                                    Image(self.diceImage1).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage2).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage3).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                                HStack {
                                    Image(self.diceImage4).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage5).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage6).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                                HStack {
                                    Image(self.diceImage7).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                            }
                            Spacer(minLength: 150)
                        }
                        HStack(spacing: 0) {
                            Spacer(minLength: 0)
                            PublicManager.AdView().frame(maxWidth: bodyView.size.width, maxHeight: 50)
                            Spacer(minLength: 0)
                        }.background(Color(red:0.2,green:0.2,blue:0.2))
                    }
                }
                .background(ConstValue.colorBg)
                //.navigationBarTitle("")
                .navigationBarHidden(true)
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .navigationBarHidden(true)
        .onDisappear {     //アプリ終了時
            self.destroyFlag = true
        }
    }
    
    //start button on click
    private func startAction() {
        if self.busyFlag {
            return
        }
        self.busyFlag = true
        //
        self.timeLine = 0
        self.timeLineAnimation()
    }

    //animation
    private func timeLineAnimation() {
        withAnimation {
            if self.destroyFlag {
                return
            }
            self.timeLine += 1
            if self.timeLine > 30 {
                self.setImageResult()
                self.busyFlag = false
                return
            }
            self.setImage()
            DispatchQueue.global().async {
                Thread.sleep(forTimeInterval: 0.02)
                DispatchQueue.main.sync {
                    if self.destroyFlag == false {
                        self.timeLineAnimation()
                    }
                }
            }
        }
    }

    private func setImage() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage4 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage5 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage6 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage7 = self.diceImagePrefix + String(Int.random(in: 7...12))
    }

    private func setImageResult() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage4 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage5 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage6 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage7 = self.diceImagePrefix + String(Int.random(in: 1...6))
    }

}

struct Dice7View_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            Dice7View().environmentObject(PublicManager())
        }
    }
}

Dice8View.swift

//
//  Dice9View.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI
import GoogleMobileAds

struct Dice8View: View {
    @EnvironmentObject var pub: PublicManager
    @State private var diceImage1: String = "dice7"
    @State private var diceImage2: String = "dice8"
    @State private var diceImage3: String = "dice9"
    @State private var diceImage4: String = "dice10"
    @State private var diceImage5: String = "dice11"
    @State private var diceImage6: String = "dice12"
    @State private var diceImage7: String = "dice7"
    @State private var diceImage8: String = "dice8"
    private var diceImagePrefix: String = "dice"
    @State private var timeLine: Int = 0
    @State private var busyFlag: Bool = false   //実行中
    @State private var destroyFlag: Bool = false
    //
    var body: some View {
        NavigationView {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    HStack(spacing: 0) {
                        Button(action:{
                            self.startAction()
                        }){
                            Text("start")
                                .frame(width:bodyView.size.width / 4 * 3, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorStart)
                                .foregroundColor(Color.white)
                        }
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height / 6)
                        Button(action:{
                            if self.busyFlag {
                                return
                            }
                            self.pub.isDice8 = false
                        }){
                            Text("back")
                                .frame(width: bodyView.size.width / 4, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorSetting)
                                .foregroundColor(Color.white)
                        }
                        .background(ConstValue.colorSetting)
                    }
                    .frame(width:bodyView.size.width, height:bodyView.size.height / 6)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    ZStack(alignment: .bottom) {
                        ScrollView {
                            VStack {
                                Spacer(minLength: bodyView.size.height * 0.05)
                                HStack {
                                    Image(self.diceImage1).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage2).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage3).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                                HStack {
                                    Image(self.diceImage4).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage5).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage6).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                                HStack {
                                    Image(self.diceImage7).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage8).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                            }
                            Spacer(minLength: 150)
                        }
                        HStack(spacing: 0) {
                            Spacer(minLength: 0)
                            PublicManager.AdView().frame(maxWidth: bodyView.size.width, maxHeight: 50)
                            Spacer(minLength: 0)
                        }.background(Color(red:0.2,green:0.2,blue:0.2))
                    }
                }
                .background(ConstValue.colorBg)
                //.navigationBarTitle("")
                .navigationBarHidden(true)
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .navigationBarHidden(true)
        .onDisappear {     //アプリ終了時
            self.destroyFlag = true
        }
    }
    
    //start button on click
    private func startAction() {
        if self.busyFlag {
            return
        }
        self.busyFlag = true
        //
        self.timeLine = 0
        self.timeLineAnimation()
    }

    //animation
    private func timeLineAnimation() {
        withAnimation {
            if self.destroyFlag {
                return
            }
            self.timeLine += 1
            if self.timeLine > 30 {
                self.setImageResult()
                self.busyFlag = false
                return
            }
            self.setImage()
            DispatchQueue.global().async {
                Thread.sleep(forTimeInterval: 0.02)
                DispatchQueue.main.sync {
                    if self.destroyFlag == false {
                        self.timeLineAnimation()
                    }
                }
            }
        }
    }

    private func setImage() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage4 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage5 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage6 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage7 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage8 = self.diceImagePrefix + String(Int.random(in: 7...12))
    }

    private func setImageResult() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage4 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage5 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage6 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage7 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage8 = self.diceImagePrefix + String(Int.random(in: 1...6))
    }

}

struct Dice8View_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            Dice8View().environmentObject(PublicManager())
        }
    }
}

Dice9View.swift

//
//  Dice9View.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI
import GoogleMobileAds

struct Dice9View: View {
    @EnvironmentObject var pub: PublicManager
    @State private var diceImage1: String = "dice7"
    @State private var diceImage2: String = "dice8"
    @State private var diceImage3: String = "dice9"
    @State private var diceImage4: String = "dice10"
    @State private var diceImage5: String = "dice11"
    @State private var diceImage6: String = "dice12"
    @State private var diceImage7: String = "dice7"
    @State private var diceImage8: String = "dice8"
    @State private var diceImage9: String = "dice9"
    private var diceImagePrefix: String = "dice"
    @State private var timeLine: Int = 0
    @State private var busyFlag: Bool = false   //実行中
    @State private var destroyFlag: Bool = false
    //
    var body: some View {
        NavigationView {
            GeometryReader { bodyView in
                VStack(spacing: 0) {
                    HStack(spacing: 0) {
                        Button(action:{
                            self.startAction()
                        }){
                            Text("start")
                                .frame(width:bodyView.size.width / 4 * 3, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorStart)
                                .foregroundColor(Color.white)
                        }
                        Rectangle().fill(Color.white).frame(width: 1,height: bodyView.size.height / 6)
                        Button(action:{
                            if self.busyFlag {
                                return
                            }
                            self.pub.isDice9 = false
                        }){
                            Text("back")
                                .frame(width: bodyView.size.width / 4, height: bodyView.size.height / 6, alignment: .center)
                                .background(ConstValue.colorSetting)
                                .foregroundColor(Color.white)
                        }
                        .background(ConstValue.colorSetting)
                    }
                    .frame(width:bodyView.size.width, height:bodyView.size.height / 6)
                    Rectangle().fill(Color.white).frame(width: bodyView.size.width,height: 1)
                    ZStack(alignment: .bottom) {
                        ScrollView {
                            VStack {
                                Spacer(minLength: bodyView.size.height * 0.05)
                                HStack {
                                    Image(self.diceImage1).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage2).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage3).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                                HStack {
                                    Image(self.diceImage4).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage5).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage6).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                                HStack {
                                    Image(self.diceImage7).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage8).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                    Image(self.diceImage9).resizable()
                                        .frame(width: bodyView.size.width * 0.3, height: bodyView.size.width * 0.3)
                                }
                            }
                            Spacer(minLength: 150)
                        }
                        HStack(spacing: 0) {
                            Spacer(minLength: 0)
                            PublicManager.AdView().frame(maxWidth: bodyView.size.width, maxHeight: 50)
                            Spacer(minLength: 0)
                        }.background(Color(red:0.2,green:0.2,blue:0.2))
                    }
                }
                .background(ConstValue.colorBg)
                //.navigationBarTitle("")
                .navigationBarHidden(true)
            }
        }
        .navigationViewStyle(StackNavigationViewStyle())
        .navigationBarHidden(true)
        .onDisappear {     //アプリ終了時
            self.destroyFlag = true
        }
    }
    
    //start button on click
    private func startAction() {
        if self.busyFlag {
            return
        }
        self.busyFlag = true
        //
        self.timeLine = 0
        self.timeLineAnimation()
    }

    //animation
    private func timeLineAnimation() {
        withAnimation {
            if self.destroyFlag {
                return
            }
            self.timeLine += 1
            if self.timeLine > 30 {
                self.setImageResult()
                self.busyFlag = false
                return
            }
            self.setImage()
            DispatchQueue.global().async {
                Thread.sleep(forTimeInterval: 0.02)
                DispatchQueue.main.sync {
                    if self.destroyFlag == false {
                        self.timeLineAnimation()
                    }
                }
            }
        }
    }

    private func setImage() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage4 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage5 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage6 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage7 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage8 = self.diceImagePrefix + String(Int.random(in: 7...12))
        self.diceImage9 = self.diceImagePrefix + String(Int.random(in: 7...12))
    }

    private func setImageResult() {
        self.diceImage1 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage2 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage3 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage4 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage5 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage6 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage7 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage8 = self.diceImagePrefix + String(Int.random(in: 1...6))
        self.diceImage9 = self.diceImagePrefix + String(Int.random(in: 1...6))
    }

}

struct Dice9View_Previews: PreviewProvider {
    static var previews: some View {
        Group {
            Dice9View().environmentObject(PublicManager())
        }
    }
}

DiceApp.swift

//
//  DiceApp.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI
import UIKit
import GoogleMobileAds

// AppDelegateクラスを定義する
class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

        // Mobile Ads SDKを初期化する
        GADMobileAds.sharedInstance().start(completionHandler: nil)
        
        return true
    }
}


@main
struct DiceApp: App {
    // SwiftUI AppライフサイクルにAppDelegateクラスを注入する
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene {
        WindowGroup {
            ContentView().environmentObject(PublicManager())
        }
    }
}

PublicManager.swift

//
//  PublicManager.swift
//  Dice
//
//  Created by akira ohmachi on 2021/04/08.
//

import SwiftUI
import GoogleMobileAds

class PublicManager: ObservableObject {
    
    @Published var isDice1: Bool = false
    @Published var isDice2: Bool = false
    @Published var isDice3: Bool = false
    @Published var isDice4: Bool = false
    @Published var isDice5: Bool = false
    @Published var isDice6: Bool = false
    @Published var isDice7: Bool = false
    @Published var isDice8: Bool = false
    @Published var isDice9: Bool = false

    @AppStorage("diceCount") var diceCount: Int = 1

    //--------------------------------------------------
    //adMob
    
    struct AdView: UIViewRepresentable {
        func makeUIView(context: Context) -> GADBannerView {
            let banner = GADBannerView(adSize: kGADAdSizeBanner)
            #if DEBUG
            banner.adUnitID = "ca-app-pub-3940256099942544/2934735716"
            #else
            banner.adUnitID = "ca-app-pub-0000000000000000/0000000000"
            #endif
            banner.rootViewController = UIApplication.shared.windows.first?.rootViewController
            banner.load(GADRequest())
            return banner
        }

        func updateUIView(_ uiView: GADBannerView, context: Context) {
        }
    }

    //--------------------------------------------------

}