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())
}
}
}