3
\$\begingroup\$

I've been working on this probability game that has a gun with 5/6 bullets. When there's a dodge the game removes a bullet and then the game continues, the goal being to get to 0 bullets.

I don't use a var to keep the score counts because it's easier to flush it by adding the new sentence in. Are there any big mistakes in my code, or things that should be done better?

import Cocoa

  let appWindow = NSWindow()
 let gunTrigger = NSButton(frame: CGRect(x: 155, y: 5, width: 210, height: 19))

 class ShootMeSomelexhoe: NSObject, NSApplicationDelegate{
func applicationDidFinishLaunching(_ notification: Notification) {
    appWindow.setContentSize(NSSize(width: 520, height: 30))
    appWindow.titlebarAppearsTransparent = true
    appWindow.backgroundColor =  NSColor.white
    appWindow.isMovableByWindowBackground = true
    appWindow.contentView?.addSubview(gunTrigger)
    appWindow.title = "πŸ”« = 5/6 ⁍ ☠️ Dodge = 1 less ⁍ πŸ”« Empty without ☠️ = Win!"
    appWindow.setFrameAutosaveName(NSWindow.FrameAutosaveName(rawValue: "fun-roulette"))
    appWindow.makeKeyAndOrderFront(nil)
    gunTrigger.bezelStyle = .roundRect
    gunTrigger.title = "⁍⁍⁍⁍⁍"
    gunTrigger.action = #selector(clickedTrigger)
}

@objc func clickedTrigger(){
    if !(arc4random_uniform(6) + 1  > gunTrigger.title.count){
        gunTrigger.title = "⁍⁍⁍⁍⁍"
        appWindow.title = "saddly u died :(" + String(appWindow.title.components(separatedBy: "​").count) + " attemp(s)." + String(repeating: "​", count: appWindow.title.components(separatedBy: "​").count) //Adds "U+200B" for attempps count.
    }
    else{
        if gunTrigger.title.count != 1{
            gunTrigger.title = String(gunTrigger.title.dropLast())
            appWindow.title = "u dodged death! lets keep playing our luck" + String(appWindow.title.components(separatedBy: "​").count) + " attemp(s)." + String(repeating: "​", count: appWindow.title.components(separatedBy: "​").count) //Adds "U+200B" for attempps count.
        }
        else{
            gunTrigger.title = "⁍⁍⁍⁍⁍"
            NSSound(named: NSSound.Name(rawValue: "Glass"))?.play()
            appWindow.title = "Congradulation u just won the game of life. enjoy!!!!" + String(appWindow.title.components(separatedBy: "​").count) + " attempts."
        }
    }
}
}
\$\endgroup\$

Your Answer

By clicking β€œPost Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.