Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SwiftUI
- struct ContentView: View {
- @State private var timer: Timer?
- @State var Reload: Bool = false
- @State private var Money: Int = 0
- @State private var PerClick: Int = 1
- @State private var PerSecond: Int = 0
- @State private var DevValue1: String = ""
- var body: some View {
- VStack {
- DisclosureGroup("Admin") {
- Button("Reload") {
- Reload = true
- Reload = false
- }
- DisclosureGroup("Money") {
- TextField("Amount Of Money", text: $DevValue1)
- Button("Set") {
- Money = Int(DevValue1) ?? Money
- }
- Button("Add") {
- Money += Int(DevValue1) ?? 0
- }
- Button("Remove") {
- Money -= Int(DevValue1) ?? 0
- }
- }
- }
- GroupBox() {
- Button("+"+String(PerClick)+"$") {
- Money += PerClick
- }
- }
- Text("Hello, world!")
- let Shop1 = GroupBox() {
- Button("+1 Per Click - 80$") {
- if Money >= 80 {
- Money -= 80
- PerClick += 1
- }
- }
- Text("\n")
- Button("+5 Per Click - 350$") {
- if Money >= 350 {
- Money -= 350
- PerClick += 5
- }
- }
- }
- let Shop2 = GroupBox() {
- Button("+1 Per Second - 170$") {
- if Money >= 170 {
- Money -= 170
- PerSecond += 1
- updateTimerInterval()
- }
- }
- Text("\n")
- Button("+5 Per Second - 800$") {
- if Money >= 800 {
- Money -= 800
- PerSecond += 5
- updateTimerInterval()
- }
- }
- }
- GroupBox("Stats") {
- LabeledContent("Money: ") {
- Text(String(Money))
- }
- LabeledContent("Per Click: ") {
- Text(String(PerClick))
- }
- LabeledContent("Per Second: ") {
- Text(String(PerSecond))
- }
- }
- GroupBox("Shop") {
- TabView(selection: .constant(1)) {
- Shop1.tabItem { Text("Per Click") }.tag(1)
- Shop2.tabItem { Text("Per Second") }.tag(2)
- }
- }
- }
- // Start the timer when the view appears
- .onAppear(perform: startTimer)
- // Stop the timer when the view disappears
- .onDisappear(perform: stopTimer)
- }
- func startTimer() {
- // Use a timer to execute a closure with a dynamic interval
- timer = Timer.scheduledTimer(withTimeInterval: 1.0 / Double(PerSecond), repeats: true) { _ in
- // Increase money every second
- Money += 1
- }
- }
- func stopTimer() {
- timer?.invalidate()
- }
- func updateTimerInterval() {
- // Stop the current timer
- stopTimer()
- // Start a new timer with the updated interval
- startTimer()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement