catchPikatcuApp - My first app on GitHub.

Overview

catchPikatcuApp

My first app on GitHub.

Simulator Screen Shot - iPhone 11 Pro Max - 2021-10-12 at 15 44 37 Simulator Screen Shot - iPhone 11 Pro Max - 2021-10-12 at 15 45 02 Simulator Screen Shot - iPhone 11 Pro Max - 2021-10-12 at 15 45 16 Simulator Screen Shot - iPhone 11 Pro Max - 2021-10-12 at 15 45 52

import UIKit

class ViewController: UIViewController {

self.highScore { self.highScore = self.score highScoreLabel.text = "Highscore: \(self.highScore)" UserDefaults.standard.set(self.highScore, forKey: "highscore") } // Alert let alert = UIAlertController(title: "Time is Over", message: "Do you want to play again?", preferredStyle: UIAlertController.Style.alert) let ok = UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel, handler: nil) let replay = UIAlertAction(title: "Replay", style: UIAlertAction.Style.default) { (UIAlertAction) in // REPLAY ACTION self.score = 0 self.scoreLabel.text = "Score: \(self.score)" self.counter = 30 self.timeLabel.text = String(self.counter) self.time = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.countBack), userInfo: nil, repeats: true) self.hideTimer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(self.hideKendy), userInfo: nil, repeats: true) } alert.addAction(ok) alert.addAction(replay) self.present(alert, animated: true, completion: nil) } } ">
// Variables
var score = 0
var counter = 0
var time = Timer()
var hideTimer = Timer()
var imageArray = [UIImageView] ()
var highScore = 0

// Views
@IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var scoreLabel: UILabel!
@IBOutlet weak var highScoreLabel: UILabel!
@IBOutlet weak var image1: UIImageView!
@IBOutlet weak var image2: UIImageView!
@IBOutlet weak var image3: UIImageView!
@IBOutlet weak var image4: UIImageView!
@IBOutlet weak var image5: UIImageView!
@IBOutlet weak var image6: UIImageView!
@IBOutlet weak var image7: UIImageView!
@IBOutlet weak var image8: UIImageView!
@IBOutlet weak var image9: UIImageView!


override func viewDidLoad() {
    super.viewDidLoad()
    
    scoreLabel.text = "Score: \(score)"
    
    // High Score Check
    let storedHighScore = UserDefaults.standard.object(forKey: "highscore")
    
    if storedHighScore == nil {
        highScore = 0
        highScoreLabel.text = "Highscore: \(highScore)"
    }
    
    if let newScore = storedHighScore as? Int {
        highScore = newScore
        highScoreLabel.text = "Highscore: \(highScore)"
    }
    
    image1.isUserInteractionEnabled = true
    image2.isUserInteractionEnabled = true
    image3.isUserInteractionEnabled = true
    image4.isUserInteractionEnabled = true
    image5.isUserInteractionEnabled = true
    image6.isUserInteractionEnabled = true
    image7.isUserInteractionEnabled = true
    image8.isUserInteractionEnabled = true
    image9.isUserInteractionEnabled = true
    
    let recognize1 = UITapGestureRecognizer(target: self, action: #selector(ViewController.increaseScore))
    let recognize2 = UITapGestureRecognizer(target: self, action: #selector(ViewController.increaseScore))
    let recognize3 = UITapGestureRecognizer(target: self, action: #selector(ViewController.increaseScore))
    let recognize4 = UITapGestureRecognizer(target: self, action: #selector(ViewController.increaseScore))
    let recognize5 = UITapGestureRecognizer(target: self, action: #selector(ViewController.increaseScore))
    let recognize6 = UITapGestureRecognizer(target: self, action: #selector(ViewController.increaseScore))
    let recognize7 = UITapGestureRecognizer(target: self, action: #selector(ViewController.increaseScore))
    let recognize8 = UITapGestureRecognizer(target: self, action: #selector(ViewController.increaseScore))
    let recognize9 = UITapGestureRecognizer(target: self, action: #selector(ViewController.increaseScore))
    
    imageArray = [image1, image2, image3, image4, image5, image6, image7, image8, image9]
    
    //imageArray.append(image1)
    image1.addGestureRecognizer(recognize1)
    image2.addGestureRecognizer(recognize2)
    image3.addGestureRecognizer(recognize3)
    image4.addGestureRecognizer(recognize4)
    image5.addGestureRecognizer(recognize5)
    image6.addGestureRecognizer(recognize6)
    image7.addGestureRecognizer(recognize7)
    image8.addGestureRecognizer(recognize8)
    image9.addGestureRecognizer(recognize9)
   
    //TIMER
    counter = 30
    timeLabel.text = String(counter)
    
    time = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countBack), userInfo: nil, repeats: true)
    hideTimer =  Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(hideKendy), userInfo: nil, repeats: true)

    //CALL FUNCTION
    hideKendy()
    
}

@objc func hideKendy() { // Hide the images when it clicked
    
    for kendy in imageArray {
        kendy.isHidden = true
    }
    
    // Rastgele sayı oluşturmak
    let random = Int(arc4random_uniform(UInt32(imageArray.count - 1)))
    imageArray[random].isHidden = false
}

@objc func increaseScore() { // When we click to image
    
    score = score + 1
    scoreLabel.text = "Score: \(score)"
}

@objc func countBack() { // Need to count the time
    
    counter = counter - 1
    timeLabel.text = String(counter)
    
    if counter == 0 {
        time.invalidate() // Time was stoped
        hideTimer.invalidate()
        
        for kendy in imageArray {
            kendy.isHidden = true
        }
        
        // High Score
        if self.score > self.highScore {
            self.highScore = self.score
            highScoreLabel.text = "Highscore: \(self.highScore)"
            UserDefaults.standard.set(self.highScore, forKey: "highscore")
        }
        
        // Alert
        let alert = UIAlertController(title: "Time is Over", message: "Do you want to play again?", preferredStyle: UIAlertController.Style.alert)
        
        let ok = UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel, handler: nil)
        
        let replay = UIAlertAction(title: "Replay", style: UIAlertAction.Style.default) { (UIAlertAction) in
            
            // REPLAY ACTION
            self.score = 0
            self.scoreLabel.text = "Score: \(self.score)"
            self.counter = 30
            self.timeLabel.text = String(self.counter)
            
            self.time = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.countBack), userInfo: nil, repeats: true)
            self.hideTimer =  Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(self.hideKendy), userInfo: nil, repeats: true)
            
        }
        
        alert.addAction(ok)
        alert.addAction(replay)
        self.present(alert, animated: true, completion: nil)
        
    }
}

}

You might also like...
Green-grass-ios - GitHub Gardener? Start with Green Grass
Green-grass-ios - GitHub Gardener? Start with Green Grass

Green Grass 🌿 Introduction GitHub Gardener? Start with Green Grass! This app ma

Github repo search with using mvvm-c and clean architecture and using combine swift

GitSearchWithMVVM-C-CleanArchitecture Github repo search with using mvvm-c and clean architecture and using combine swift. Content Overview How To Run

GitHub-User is an iOS native application, written in Swift programming language.
GitHub-User is an iOS native application, written in Swift programming language.

#GitHub-User GitHub-User is an iOS native application, written in Swift programming language. This project is an interview take home project. The arch

GitHub Notifications in your pocket.
GitHub Notifications in your pocket.

Gitify Mobile If you are looking for the desktop version - manosim/gitify. Download Available for free on iOS & Android. App Store Google Play Store P

Show off your GitHub contributions from your lock screen 📱
Show off your GitHub contributions from your lock screen 📱

GitHubContributionsiOS V2 NOTICE: V2 is published. It is a complete rewrite using SwiftUI and Catalyst. Source code are now hosted on the version/2.x

Desafio final em grupo do treinamento em desenvolvimento iOS
Desafio final em grupo do treinamento em desenvolvimento iOS "go!dev by Idwall". O projeto consiste em um aplicativo de busca e visualização de repositórios do Github e a possibilidade de favoritá-los.

StarRepo 🎯 Objetivo O objetivo deste projeto é criar um aplicativo iOS, proposto como desafio final do treinamento "go!dev by Idwall", para busca e v

In this mini app covered the concepts like basics of SwiftUI and Navigations and Animations and List with CRUD functions and MVVM and App Launch and App icons adding and also applied persistence using UserDefaults Concept.
In this mini app covered the concepts like basics of SwiftUI and Navigations and Animations and List with CRUD functions and MVVM and App Launch and App icons adding and also applied persistence using UserDefaults Concept.

TodoList In this application used the concepts from the beginner level project of SwiftUI_Evolve_1 The following concepts covered in this mini app Swi

Todo is an iOS App written in Swift. This app is used for an online video training course. This app demonstrates how to use UITableViewController.
Todo is an iOS App written in Swift. This app is used for an online video training course. This app demonstrates how to use UITableViewController.

Todo Todo is an iOS App written in Swift. This app is used for an online video training course. This app demonstrates how to use UITableViewController

Porting the example app from our Advanced iOS App Architecture book from UIKit to SwiftUI.

SwiftUI example app: Koober We're porting the example app from our Advanced iOS App Architecture book from UIKit to SwiftUI and we are sharing the cod

Owner
Beytullah
I'm iOS developer. I live in İstanbul.
Beytullah
Robert Ciotoiu 0 Jan 24, 2022
Trivia about Animal Crossing: New Horizons. My first iOS (iPhone) app.

ACNH-trivia-iOS-app Trivia about Animal Crossing: New Horizons. This is my first iOS (iPhone) app. I am excited to start my journey as an iOS develope

Katie Saramutina 2 Apr 14, 2022
This is my first SwiftUI project, as I decided not to release it I made the codebase available here for anyone to take a look at.

Sunshine This is my first SwiftUI project, as I decided not to release it to the App Store. I made the codebase available here for anyone to take a lo

Maxime Heckel 20 Dec 14, 2022
In this tutorial, you’ll write your very first Core Data application with SwiftUI in Xcode

TodoApp-IOS In this tutorial, you’ll write your very first Core Data application with SwiftUI in Xcode. You’ll see how easy it is to get started with

Noye Samuel 1 Dec 13, 2021
The first affordable AR headset experience

AR MultiPendulum: AR Headset Experience AR MultiPendulum allows users to interact with virtual objects directly with their hand instead of tapping an

Philip Turner 12 Dec 16, 2021
Small app trying to recreate the Github's repos section from the iOS app with RxSwift and .nibs

Github Profile Repos Small app trying to recreate the Github's repos section from the iOS app with RxSwift and .nibs. This project is currently in pro

Leonardo 1 Apr 5, 2022
This is an example project of SwiftUI and Combine using GitHub API.

SwiftUI-Combine-Example This is an example project of SwiftUI and Combine using GitHub GET /search/users API. ?? Requirements Swift5.1 Beta Xcode11.0

Ryo Aoyama 436 Jan 5, 2023
Sample iOS project built by SwiftUI + Flux and Combine framework using GitHub API

SwiftUI-Flux Flux enables us to have unidirectional data flow and make it testable. It's used to be implemented using RxSwift or ReactiveSwift in the

Yusuke Kita 87 Nov 25, 2022
Sample iOS project built by SwiftUI + MVVM and Combine framework using GitHub API

SwiftUI-MVVM One of the biggest idea for having MVVM is that most of data flow can be testable. Data binding in view layer by SwiftUI is awesome. Howe

Yusuke Kita 592 Jan 2, 2023
This is an example project of SwiftUI and Combine using GitHub API.

SwiftUI-Combine-Example This is an example project of SwiftUI and Combine using GitHub GET /search/users API. ?? Requirements Swift5.1 Beta Xcode11.0

Ryo Aoyama 435 Dec 28, 2022