Add 2048 Game

This commit is contained in:
Ivan Vorobei
2019-06-06 22:28:01 +03:00
parent bcedea412a
commit 5eaf1fbc68
20 changed files with 1390 additions and 1 deletions

View File

@@ -0,0 +1,58 @@
//
// AppDelegate.swift
// SwiftUI2048
//
// Created by Hongyu on 6/5/19.
// Copyright © 2019 Cyandev. All rights reserved.
//
import UIKit
import SwiftUI
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var gameLogic: GameLogic!
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
gameLogic = GameLogic()
window = UIWindow(frame: UIScreen.main.bounds)
window!.rootViewController = UIHostingController(rootView:
GameView().environmentObject(gameLogic)
)
window!.makeKeyAndVisible()
self.becomeFirstResponder()
return true
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@objc func newGame(_ sender: AnyObject?) {
gameLogic.newGame()
}
override func buildCommands(with builder: UICommandBuilder) {
builder.remove(menu: .edit)
builder.remove(menu: .format)
builder.remove(menu: .view)
builder.replaceChildren(ofMenu: .file) { oldChildren in
var newChildren = oldChildren
let newGameItem = UIMutableKeyCommand(input: "N",
modifierFlags: .command,
action: #selector(newGame(_:)))
newGameItem.title = "New Game"
newChildren.insert(newGameItem, at: 0)
return newChildren
}
}
}