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,407 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objects = {
/* Begin PBXBuildFile section */
FA132EFA22A94D9400BD9743 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = FA132EF922A94D9400BD9743 /* MainMenu.xib */; };
FA633E1F22A77D1C00DE6288 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA633E1E22A77D1C00DE6288 /* AppDelegate.swift */; };
FA633E2522A77D1D00DE6288 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FA633E2422A77D1D00DE6288 /* Assets.xcassets */; };
FA633E2822A77D1D00DE6288 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FA633E2722A77D1D00DE6288 /* Preview Assets.xcassets */; };
FA633E2B22A77D1D00DE6288 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FA633E2922A77D1D00DE6288 /* LaunchScreen.storyboard */; };
FA633E3422A77D5700DE6288 /* BlockView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA633E3322A77D5700DE6288 /* BlockView.swift */; };
FA633E3722A7928500DE6288 /* BlockMatrix.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA633E3622A7928400DE6288 /* BlockMatrix.swift */; };
FA633E3922A79AFA00DE6288 /* GameLogic.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA633E3822A79AFA00DE6288 /* GameLogic.swift */; };
FA633E3B22A79B1200DE6288 /* GameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA633E3A22A79B1200DE6288 /* GameView.swift */; };
FA633E3D22A79B3C00DE6288 /* BlockGridView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA633E3C22A79B3C00DE6288 /* BlockGridView.swift */; };
FA633E3F22A7BDBB00DE6288 /* IdentifiedBlock.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA633E3E22A7BDBB00DE6288 /* IdentifiedBlock.swift */; };
FA633E4622A800AB00DE6288 /* Screenshot.png in Resources */ = {isa = PBXBuildFile; fileRef = FA633E4522A800AB00DE6288 /* Screenshot.png */; };
FA633E4822A8019D00DE6288 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = FA633E4722A8019D00DE6288 /* LICENSE */; };
FA6F2B2122A81832009C2D3B /* FunctionalUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA6F2B2022A81832009C2D3B /* FunctionalUtils.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
FA132EF822A90EFD00BD9743 /* SwiftUI2048.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SwiftUI2048.entitlements; sourceTree = "<group>"; };
FA132EF922A94D9400BD9743 /* MainMenu.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = "<group>"; };
FA633E1B22A77D1C00DE6288 /* 2048.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 2048.app; sourceTree = BUILT_PRODUCTS_DIR; };
FA633E1E22A77D1C00DE6288 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
FA633E2422A77D1D00DE6288 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
FA633E2722A77D1D00DE6288 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
FA633E2A22A77D1D00DE6288 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
FA633E2C22A77D1D00DE6288 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
FA633E3322A77D5700DE6288 /* BlockView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockView.swift; sourceTree = "<group>"; };
FA633E3622A7928400DE6288 /* BlockMatrix.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockMatrix.swift; sourceTree = "<group>"; };
FA633E3822A79AFA00DE6288 /* GameLogic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameLogic.swift; sourceTree = "<group>"; };
FA633E3A22A79B1200DE6288 /* GameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameView.swift; sourceTree = "<group>"; };
FA633E3C22A79B3C00DE6288 /* BlockGridView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockGridView.swift; sourceTree = "<group>"; };
FA633E3E22A7BDBB00DE6288 /* IdentifiedBlock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentifiedBlock.swift; sourceTree = "<group>"; };
FA633E4222A7FFD000DE6288 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
FA633E4522A800AB00DE6288 /* Screenshot.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Screenshot.png; sourceTree = "<group>"; };
FA633E4722A8019D00DE6288 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
FA6F2B2022A81832009C2D3B /* FunctionalUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FunctionalUtils.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
FA633E1822A77D1C00DE6288 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
FA633E1222A77D1C00DE6288 = {
isa = PBXGroup;
children = (
FA633E4722A8019D00DE6288 /* LICENSE */,
FA633E4222A7FFD000DE6288 /* README.md */,
FA633E4522A800AB00DE6288 /* Screenshot.png */,
FA633E1D22A77D1C00DE6288 /* SwiftUI2048 */,
FA633E1C22A77D1C00DE6288 /* Products */,
);
sourceTree = "<group>";
};
FA633E1C22A77D1C00DE6288 /* Products */ = {
isa = PBXGroup;
children = (
FA633E1B22A77D1C00DE6288 /* 2048.app */,
);
name = Products;
sourceTree = "<group>";
};
FA633E1D22A77D1C00DE6288 /* SwiftUI2048 */ = {
isa = PBXGroup;
children = (
FA132EF822A90EFD00BD9743 /* SwiftUI2048.entitlements */,
FA6F2B2022A81832009C2D3B /* FunctionalUtils.swift */,
FA633E3522A7926200DE6288 /* Models */,
FA633E3222A77D3400DE6288 /* Views */,
FA633E1E22A77D1C00DE6288 /* AppDelegate.swift */,
FA633E2422A77D1D00DE6288 /* Assets.xcassets */,
FA633E2922A77D1D00DE6288 /* LaunchScreen.storyboard */,
FA132EF922A94D9400BD9743 /* MainMenu.xib */,
FA633E2C22A77D1D00DE6288 /* Info.plist */,
FA633E2622A77D1D00DE6288 /* Preview Content */,
);
path = SwiftUI2048;
sourceTree = "<group>";
};
FA633E2622A77D1D00DE6288 /* Preview Content */ = {
isa = PBXGroup;
children = (
FA633E2722A77D1D00DE6288 /* Preview Assets.xcassets */,
);
path = "Preview Content";
sourceTree = "<group>";
};
FA633E3222A77D3400DE6288 /* Views */ = {
isa = PBXGroup;
children = (
FA633E3322A77D5700DE6288 /* BlockView.swift */,
FA633E3C22A79B3C00DE6288 /* BlockGridView.swift */,
FA633E3A22A79B1200DE6288 /* GameView.swift */,
);
path = Views;
sourceTree = "<group>";
};
FA633E3522A7926200DE6288 /* Models */ = {
isa = PBXGroup;
children = (
FA633E3622A7928400DE6288 /* BlockMatrix.swift */,
FA633E3822A79AFA00DE6288 /* GameLogic.swift */,
FA633E3E22A7BDBB00DE6288 /* IdentifiedBlock.swift */,
);
path = Models;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
FA633E1A22A77D1C00DE6288 /* 2048 */ = {
isa = PBXNativeTarget;
buildConfigurationList = FA633E2F22A77D1D00DE6288 /* Build configuration list for PBXNativeTarget "2048" */;
buildPhases = (
FA633E1722A77D1C00DE6288 /* Sources */,
FA633E1822A77D1C00DE6288 /* Frameworks */,
FA633E1922A77D1C00DE6288 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = 2048;
productName = SwiftUI2048;
productReference = FA633E1B22A77D1C00DE6288 /* 2048.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
FA633E1322A77D1C00DE6288 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1100;
LastUpgradeCheck = 1100;
ORGANIZATIONNAME = Cyandev;
TargetAttributes = {
FA633E1A22A77D1C00DE6288 = {
CreatedOnToolsVersion = 11.0;
};
};
};
buildConfigurationList = FA633E1622A77D1C00DE6288 /* Build configuration list for PBXProject "SwiftUI2048" */;
compatibilityVersion = "Xcode 9.3";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = FA633E1222A77D1C00DE6288;
productRefGroup = FA633E1C22A77D1C00DE6288 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
FA633E1A22A77D1C00DE6288 /* 2048 */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
FA633E1922A77D1C00DE6288 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FA633E2B22A77D1D00DE6288 /* LaunchScreen.storyboard in Resources */,
FA633E2822A77D1D00DE6288 /* Preview Assets.xcassets in Resources */,
FA633E2522A77D1D00DE6288 /* Assets.xcassets in Resources */,
FA633E4622A800AB00DE6288 /* Screenshot.png in Resources */,
FA633E4822A8019D00DE6288 /* LICENSE in Resources */,
FA132EFA22A94D9400BD9743 /* MainMenu.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
FA633E1722A77D1C00DE6288 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FA633E3F22A7BDBB00DE6288 /* IdentifiedBlock.swift in Sources */,
FA6F2B2122A81832009C2D3B /* FunctionalUtils.swift in Sources */,
FA633E3922A79AFA00DE6288 /* GameLogic.swift in Sources */,
FA633E3422A77D5700DE6288 /* BlockView.swift in Sources */,
FA633E3D22A79B3C00DE6288 /* BlockGridView.swift in Sources */,
FA633E1F22A77D1C00DE6288 /* AppDelegate.swift in Sources */,
FA633E3722A7928500DE6288 /* BlockMatrix.swift in Sources */,
FA633E3B22A79B1200DE6288 /* GameView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
FA633E2922A77D1D00DE6288 /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
FA633E2A22A77D1D00DE6288 /* Base */,
);
name = LaunchScreen.storyboard;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
FA633E2D22A77D1D00DE6288 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
FA633E2E22A77D1D00DE6288 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
FA633E3022A77D1D00DE6288 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = SwiftUI2048/SwiftUI2048.entitlements;
"CODE_SIGN_IDENTITY[sdk=*]" = "";
CODE_SIGN_STYLE = Automatic;
DERIVE_UIKITFORMAC_PRODUCT_BUNDLE_IDENTIFIER = YES;
DEVELOPMENT_ASSET_PATHS = "SwiftUI2048/Preview\\ Content";
DEVELOPMENT_TEAM = 9ZS3K56XF5;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = SwiftUI2048/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.cyandev.SwiftUI2048;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_UIKITFORMAC = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
FA633E3122A77D1D00DE6288 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = SwiftUI2048/SwiftUI2048.entitlements;
"CODE_SIGN_IDENTITY[sdk=*]" = "";
CODE_SIGN_STYLE = Automatic;
DERIVE_UIKITFORMAC_PRODUCT_BUNDLE_IDENTIFIER = YES;
DEVELOPMENT_ASSET_PATHS = "SwiftUI2048/Preview\\ Content";
DEVELOPMENT_TEAM = 9ZS3K56XF5;
ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = SwiftUI2048/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.cyandev.SwiftUI2048;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_UIKITFORMAC = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
FA633E1622A77D1C00DE6288 /* Build configuration list for PBXProject "SwiftUI2048" */ = {
isa = XCConfigurationList;
buildConfigurations = (
FA633E2D22A77D1D00DE6288 /* Debug */,
FA633E2E22A77D1D00DE6288 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
FA633E2F22A77D1D00DE6288 /* Build configuration list for PBXNativeTarget "2048" */ = {
isa = XCConfigurationList;
buildConfigurations = (
FA633E3022A77D1D00DE6288 /* Debug */,
FA633E3122A77D1D00DE6288 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = FA633E1322A77D1C00DE6288 /* Project object */;
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:SwiftUI2048.xcodeproj">
</FileRef>
</Workspace>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

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
}
}
}

View File

@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14810.11" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14766.13"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>

View File

@@ -0,0 +1,13 @@
//
// FunctionalUtils.swift
// SwiftUI2048
//
// Created by Hongyu on 6/5/19.
// Copyright © 2019 Cyandev. All rights reserved.
//
import Foundation
func bind<T, U>(_ x: T, _ closure: (T) -> U) -> U {
return closure(x)
}

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>2048</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14810.11" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14766.13"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="AppDelegate" customModule="_048"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<command title="New Game" input="n" id="TrP-zF-WNW">
<keyModifierFlags key="modifierFlags" command="YES"/>
<alternates>
<commandAlternate title="a" actionName="newGame:" id="Fnd-9b-r2T"/>
</alternates>
<connections>
<action selector="newGame:" destination="-2" id="AQs-UV-nU7"/>
</connections>
</command>
</objects>
</document>

View File

@@ -0,0 +1,127 @@
//
// BlockMatrix.swift
// SwiftUI2048
//
// Created by Hongyu on 6/5/19.
// Copyright © 2019 Cyandev. All rights reserved.
//
import Foundation
protocol Block {
associatedtype Value
var number: Value { get set }
}
struct IndexedBlock<T> {
let index: (Int, Int)
let item: T?
}
struct BlockMatrix<T> : CustomDebugStringConvertible where T: Block {
typealias Index = (Int, Int)
fileprivate var matrix: [[T?]]
init() {
matrix = [[T?]]()
for _ in 0..<4 {
var row = [T?]()
for _ in 0..<4 {
row.append(nil)
}
matrix.append(row)
}
}
var debugDescription: String {
matrix.map { row -> String in
row.map {
if $0 == nil {
return " "
} else {
return String(describing: $0!.number)
}
}.joined(separator: "\t")
}.joined(separator: "\n")
}
var flatten: [IndexedBlock<T>] {
return self.matrix.enumerated().flatMap { (y: Int, element: [T?]) in
element.enumerated().map { (x: Int, element: T?) in
return IndexedBlock(index: (x, y), item: element)
}
}
}
subscript(index: Self.Index) -> T? {
guard isIndexValid(index) else {
return nil
}
return matrix[index.1][index.0]
}
/// Move the block to specific location and leave the original location blank.
/// - Parameter from: Source location
/// - Parameter to: Destination location
mutating func move(from: Self.Index, to: Self.Index) {
guard isIndexValid(from) && isIndexValid(to) else {
// TODO: Throw an error?
return
}
guard let source = self[from] else {
return
}
matrix[to.1][to.0] = source
matrix[from.1][from.0] = nil
}
/// Move the block to specific location, change its value and leave the original location blank.
/// - Parameter from: Source location
/// - Parameter to: Destination location
/// - Parameter newValue: The new value
mutating func move(from: Self.Index, to: Self.Index, with newValue: T.Value) {
guard isIndexValid(from) && isIndexValid(to) else {
// TODO: Throw an error?
return
}
guard var source = self[from] else {
return
}
source.number = newValue
matrix[to.1][to.0] = source
matrix[from.1][from.0] = nil
}
/// Place a block to specific location.
/// - Parameter block: The block to place
/// - Parameter to: Destination location
mutating func place(_ block: T?, to: Self.Index) {
matrix[to.1][to.0] = block
}
fileprivate func isIndexValid(_ index: Self.Index) -> Bool {
guard index.0 >= 0 && index.0 < 4 else {
return false
}
guard index.1 >= 0 && index.1 < 4 else {
return false
}
return true
}
}

View File

@@ -0,0 +1,176 @@
//
// GameLogic.swift
// SwiftUI2048
//
// Created by Hongyu on 6/5/19.
// Copyright © 2019 Cyandev. All rights reserved.
//
import Foundation
import SwiftUI
import Combine
final class GameLogic : BindableObject {
enum Direction {
case left
case right
case up
case down
}
typealias BlockMatrixType = BlockMatrix<IdentifiedBlock>
let didChange = PassthroughSubject<GameLogic, Never>()
fileprivate var _blockMatrix: BlockMatrixType!
var blockMatrix: BlockMatrixType {
return _blockMatrix
}
fileprivate var _globalID = 0
fileprivate var newGlobalID: Int {
_globalID += 1
return _globalID
}
init() {
newGame()
}
func newGame() {
_blockMatrix = BlockMatrixType()
generateNewBlocks()
didChange.send(self)
}
func move(_ direction: Direction) {
defer {
didChange.send(self)
}
var moved = false
let axis = direction == .left || direction == .right
for row in 0..<4 {
var rowSnapshot = [IdentifiedBlock?]()
var compactRow = [IdentifiedBlock]()
for col in 0..<4 {
// Transpose if necessary.
if let block = _blockMatrix[axis ? (col, row) : (row, col)] {
rowSnapshot.append(block)
compactRow.append(block)
}
rowSnapshot.append(nil)
}
merge(blocks: &compactRow, reverse: direction == .down || direction == .right)
var newRow = [IdentifiedBlock?]()
compactRow.forEach { newRow.append($0) }
if compactRow.count < 4 {
for _ in 0..<(4 - compactRow.count) {
if direction == .left || direction == .up {
newRow.append(nil)
} else {
newRow.insert(nil, at: 0)
}
}
}
newRow.enumerated().forEach {
if rowSnapshot[$0]?.number != $1?.number {
moved = true
}
_blockMatrix.place($1, to: axis ? ($0, row) : (row, $0))
}
}
if moved {
generateNewBlocks()
}
}
fileprivate func merge(blocks: inout [IdentifiedBlock], reverse: Bool) {
if reverse {
blocks = blocks.reversed()
}
blocks = blocks
.map { (false, $0) }
.reduce([(Bool, IdentifiedBlock)]()) { acc, item in
if acc.last?.0 == false && acc.last?.1.number == item.1.number {
var accPrefix = Array(acc.dropLast())
var mergedBlock = item.1
mergedBlock.number *= 2
accPrefix.append((true, mergedBlock))
return accPrefix
} else {
var accTmp = acc
accTmp.append((false, item.1))
return accTmp
}
}
.map { $0.1 }
if reverse {
blocks = blocks.reversed()
}
}
@discardableResult fileprivate func generateNewBlocks() -> Bool {
var blankLocations = [BlockMatrixType.Index]()
for rowIndex in 0..<4 {
for colIndex in 0..<4 {
let index = (colIndex, rowIndex)
if _blockMatrix[index] == nil {
blankLocations.append(index)
}
}
}
guard blankLocations.count >= 2 else {
return false
}
// Don't forget to sync data.
defer {
didChange.send(self)
}
// Place the first block.
var placeLocIndex = Int.random(in: 0..<blankLocations.count)
_blockMatrix.place(IdentifiedBlock(id: newGlobalID, number: 2), to: blankLocations[placeLocIndex])
// Place the second block.
guard let lastLoc = blankLocations.last else {
return false
}
blankLocations[placeLocIndex] = lastLoc
placeLocIndex = Int.random(in: 0..<(blankLocations.count - 1))
_blockMatrix.place(IdentifiedBlock(id: newGlobalID, number: 2), to: blankLocations[placeLocIndex])
return true
}
// fileprivate func forEachBlockIndices(mode: ForEachMode = .rowByRow,
// reversed: Bool = false,
// _ action: (BlockMatrixType.Index) -> ()) {
// var indices = (0..<4).map { $0 }
// if reversed {
// indices = indices.reversed()
// }
//
// for row in indices {
// for col in indices {
// if mode == .rowByRow {
// action((col, row))
// } else {
// action((row, col)) // transpose
// }
// }
// }
// }
}

View File

@@ -0,0 +1,16 @@
//
// IdentifiedBlock.swift
// SwiftUI2048
//
// Created by Hongyu on 6/5/19.
// Copyright © 2019 Cyandev. All rights reserved.
//
import Foundation
struct IdentifiedBlock: Block {
let id: Int
var number: Int
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>

View File

@@ -0,0 +1,116 @@
//
// BlockGridView.swift
// SwiftUI2048
//
// Created by Hongyu on 6/5/19.
// Copyright © 2019 Cyandev. All rights reserved.
//
import SwiftUI
fileprivate struct IdentifiableIndexedBlock : Identifiable {
typealias ID = String
typealias IdentifiedValue = IndexedBlock<IdentifiedBlock>
static var uniqueBlankId = 0
let indexedBlock: IndexedBlock<IdentifiedBlock>
var id: Self.ID {
if let id = indexedBlock.item?.id {
return "\(id)"
}
// TODO: (Refactor) Don't mix two types of block views.
IdentifiableIndexedBlock.uniqueBlankId += 1
return "Blank_\(IdentifiableIndexedBlock.uniqueBlankId)"
}
var identifiedValue: Self.IdentifiedValue {
return indexedBlock
}
}
extension AnyTransition {
static func blockAppear(from: Edge) -> AnyTransition {
return .asymmetric(
insertion: AnyTransition.opacity
.combined(with: .move(edge: from)),
removal: .identity)
}
}
struct BlockGridView : View {
typealias SupportingMatrix = BlockMatrix<IdentifiedBlock>
let matrix: Self.SupportingMatrix
let blockEnterEdge: Edge
func createBlock(_ block: IdentifiedBlock?) -> some View {
if let block = block {
return BlockView(number: block.number)
}
return BlockView.blank()
}
// FIXME: This is existed as a workaround for a Swift compiler bug.
func zIndex(_ block: IdentifiedBlock?) -> Double {
if block == nil {
return 1
}
return 1000
}
var body: some View {
ZStack {
ForEach(
self.matrix.flatten.map { IdentifiableIndexedBlock(indexedBlock: $0) }
) { block in
self.createBlock(block.item)
.frame(width: 65, height: 65, alignment: .center)
.position(x: CGFloat(block.index.0) * (65 + 12) + 32.5 + 12,
y: CGFloat(block.index.1) * (65 + 12) + 32.5 + 12)
.zIndex(self.zIndex(block.item))
.transition(.blockAppear(from: self.blockEnterEdge))
.animation(block.item == nil ? nil : .spring(mass: 1, stiffness: 400, damping: 56, initialVelocity: 0))
}
}
.frame(width: 320, height: 320, alignment: .center)
.background(
Rectangle()
.fill(Color(red:0.72, green:0.66, blue:0.63, opacity:1.00))
)
.clipped()
.cornerRadius(6)
}
}
#if DEBUG
struct BlockGridView_Previews : PreviewProvider {
static var matrix: BlockGridView.SupportingMatrix {
var _matrix = BlockGridView.SupportingMatrix()
_matrix.place(IdentifiedBlock(id: 1, number: 2), to: (2, 0))
_matrix.place(IdentifiedBlock(id: 2, number: 2), to: (3, 0))
_matrix.place(IdentifiedBlock(id: 3, number: 8), to: (1, 1))
_matrix.place(IdentifiedBlock(id: 4, number: 4), to: (2, 1))
_matrix.place(IdentifiedBlock(id: 5, number: 512), to: (3, 3))
_matrix.place(IdentifiedBlock(id: 6, number: 1024), to: (2, 3))
_matrix.place(IdentifiedBlock(id: 7, number: 16), to: (0, 3))
_matrix.place(IdentifiedBlock(id: 8, number: 8), to: (1, 3))
return _matrix
}
static var previews: some View {
BlockGridView(matrix: matrix, blockEnterEdge: .top)
.previewLayout(.sizeThatFits)
}
}
#endif

View File

@@ -0,0 +1,118 @@
//
// BlockView.swift
// SwiftUI2048
//
// Created by Hongyu on 6/5/19.
// Copyright © 2019 Cyandev. All rights reserved.
//
import SwiftUI
struct BlockView : View {
fileprivate let colorScheme: [(Color, Color)] = [
// 2
(Color(red:0.91, green:0.87, blue:0.83, opacity:1.00), Color(red:0.42, green:0.39, blue:0.35, opacity:1.00)),
// 4
(Color(red:0.90, green:0.86, blue:0.76, opacity:1.00), Color(red:0.42, green:0.39, blue:0.35, opacity:1.00)),
// 8
(Color(red:0.93, green:0.67, blue:0.46, opacity:1.00), Color.white),
// 16
(Color(red:0.94, green:0.57, blue:0.38, opacity:1.00), Color.white),
// 32
(Color(red:0.95, green:0.46, blue:0.33, opacity:1.00), Color.white),
// 64
(Color(red:0.94, green:0.35, blue:0.23, opacity:1.00), Color.white),
// 128
(Color(red:0.91, green:0.78, blue:0.43, opacity:1.00), Color.white),
// 256
(Color(red:0.91, green:0.78, blue:0.37, opacity:1.00), Color.white),
// 512
(Color(red:0.90, green:0.77, blue:0.31, opacity:1.00), Color.white),
// 1024
(Color(red:0.91, green:0.75, blue:0.24, opacity:1.00), Color.white),
// 2048
(Color(red:0.91, green:0.74, blue:0.18, opacity:1.00), Color.white),
]
fileprivate let number: Int?
init(number: Int) {
self.number = number
}
fileprivate init() {
self.number = nil
}
static func blank() -> Self {
return self.init()
}
fileprivate var numberText: String {
guard let number = number else {
return ""
}
return String(number)
}
fileprivate var fontSize: CGFloat {
let textLength = numberText.count
if textLength < 3 {
return 32
} else if textLength < 4 {
return 18
} else {
return 12
}
}
fileprivate var colorPair: (Color, Color) {
guard let number = number else {
return (Color(red:0.78, green:0.73, blue:0.68, opacity:1.00), Color.black)
}
let index = Int(log2(Double(number))) - 1
if index < 0 || index >= colorScheme.count {
fatalError("No color for such number")
}
return colorScheme[index]
}
// MARK: Body
var body: some View {
ZStack {
Rectangle().fill(colorPair.0)
Text(numberText)
.font(Font.system(size: fontSize).bold())
.color(colorPair.1)
.id(numberText)
.transition(AnyTransition.scale(scale: 0.5, anchor: .center).combined(with: .opacity))
.animation(.fluidSpring())
}
.clipped()
.cornerRadius(6)
}
}
// MARK: - Previews
#if DEBUG
struct BlockView_Previews : PreviewProvider {
static var previews: some View {
Group {
ForEach((1...11).map { Int(pow(2, Double($0))) }) { i in
BlockView(number: i)
.previewLayout(.sizeThatFits)
}
BlockView.blank()
.previewLayout(.sizeThatFits)
}
}
}
#endif

View File

@@ -0,0 +1,127 @@
//
// GameView.swift
// SwiftUI2048
//
// Created by Hongyu on 6/5/19.
// Copyright © 2019 Cyandev. All rights reserved.
//
import SwiftUI
extension Edge {
static func from(_ from: GameLogic.Direction) -> Self {
switch from {
case .down:
return .top
case .up:
return .bottom
case .left:
return .trailing
case .right:
return .leading
}
}
}
struct GameView : View {
@State var gestureStartLocation: CGPoint = .zero
@State var lastGestureDirection: GameLogic.Direction = .up
@EnvironmentObject var gameLogic: GameLogic
fileprivate struct LayoutTraits {
let bannerOffset: CGSize
let containerAlignment: Alignment
}
fileprivate func layoutTraits(`for` proxy: GeometryProxy) -> LayoutTraits {
let landscape = proxy.size.width > proxy.size.height
return LayoutTraits(
bannerOffset: landscape
? .init(width: proxy.safeAreaInsets.leading + 32, height: 0)
: .init(width: 0, height: proxy.safeAreaInsets.top + 32),
containerAlignment: landscape ? .leading : .top
)
}
var gesture: some Gesture {
let threshold: CGFloat = 44
let drag = DragGesture()
.onChanged { v in
guard self.gestureStartLocation != v.startLocation else { return }
withTransaction(Transaction()) {
self.gestureStartLocation = v.startLocation
if v.translation.width > threshold {
// Move right
self.gameLogic.move(.right)
self.lastGestureDirection = .right
} else if v.translation.width < -threshold {
// Move left
self.gameLogic.move(.left)
self.lastGestureDirection = .left
} else if v.translation.height > threshold {
// Move down
self.gameLogic.move(.down)
self.lastGestureDirection = .down
} else if v.translation.height < -threshold {
// Move up
self.gameLogic.move(.up)
self.lastGestureDirection = .up
} else {
// Direction cannot be deduced, reset gesture state.
self.gestureStartLocation = .zero
}
}
// After the scene is updated, reset the last gesture direction
// to make sure the animation is right when user starts a new
// game.
OperationQueue.main.addOperation {
self.lastGestureDirection = .up
}
}
return drag
}
var body: some View {
GeometryReader { proxy in
bind(self.layoutTraits(for: proxy)) { layoutTraits in
ZStack(alignment: layoutTraits.containerAlignment) {
Text("2048")
.font(Font.system(size: 48).weight(.black))
.color(Color(red:0.47, green:0.43, blue:0.40, opacity:1.00))
.offset(layoutTraits.bannerOffset)
ZStack(alignment: .top) {
BlockGridView(matrix: self.gameLogic.blockMatrix,
blockEnterEdge: .from(self.lastGestureDirection))
.gesture(self.gesture)
}
.frame(width: proxy.size.width, height: proxy.size.height, alignment: .center)
}
.frame(width: proxy.size.width, height: proxy.size.height, alignment: .center)
.background(
Rectangle().fill(Color(red:0.96, green:0.94, blue:0.90, opacity:1.00))
)
}
}
.edgesIgnoringSafeArea(.all)
}
}
#if DEBUG
struct GameView_Previews : PreviewProvider {
static var previews: some View {
GameView()
.environmentObject(GameLogic())
}
}
#endif