//
//  ViewController.swift
//  6. Heads or Tails
//
//  Created by Bermotech on 11/05/2018.
//  Copyright © 2018 App for Apple. All rights reserved.
//

import UIKit
import AVFoundation


class ViewController: UIViewController

{
    var musicPlayer = AVAudioPlayer()
    
    @IBOutlet weak var myCoin: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    
    override func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?)
    {
        do
    {
        let url = Bundle.main.path(forResource: "coin-drop-2", ofType: "wav")
        
        self.musicPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: url!),fileTypeHint: nil)
        musicPlayer.prepareToPlay()
        self.musicPlayer.numberOfLoops = 0
        musicPlayer.play()
    }
    catch
    {
        
        }
        
        let r = arc4random()%2
        
        if (r == 1)
        {
            myCoin.image = UIImage(named: "heads")
        }
        else
        {
            myCoin.image = UIImage(named: "tails")
        }
        
    }

   
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}


