项目初始化
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -38,7 +38,7 @@ DerivedData/
|
||||
*.ipa
|
||||
*.dSYM.zip
|
||||
*.dSYM
|
||||
|
||||
.DS_Store
|
||||
## Playgrounds
|
||||
timeline.xctimeline
|
||||
playground.xcworkspace
|
||||
|
329
Twinmoji.xcodeproj/project.pbxproj
Normal file
329
Twinmoji.xcodeproj/project.pbxproj
Normal file
@@ -0,0 +1,329 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 77;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
DACBF8772D18F53100CCDAA4 /* Twinmoji.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Twinmoji.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFileSystemSynchronizedRootGroup section */
|
||||
DACBF8792D18F53100CCDAA4 /* Twinmoji */ = {
|
||||
isa = PBXFileSystemSynchronizedRootGroup;
|
||||
path = Twinmoji;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXFileSystemSynchronizedRootGroup section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
DACBF8742D18F53100CCDAA4 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
DACBF86E2D18F53100CCDAA4 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
DACBF8792D18F53100CCDAA4 /* Twinmoji */,
|
||||
DACBF8782D18F53100CCDAA4 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
DACBF8782D18F53100CCDAA4 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
DACBF8772D18F53100CCDAA4 /* Twinmoji.app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
DACBF8762D18F53100CCDAA4 /* Twinmoji */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = DACBF8852D18F53300CCDAA4 /* Build configuration list for PBXNativeTarget "Twinmoji" */;
|
||||
buildPhases = (
|
||||
DACBF8732D18F53100CCDAA4 /* Sources */,
|
||||
DACBF8742D18F53100CCDAA4 /* Frameworks */,
|
||||
DACBF8752D18F53100CCDAA4 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
fileSystemSynchronizedGroups = (
|
||||
DACBF8792D18F53100CCDAA4 /* Twinmoji */,
|
||||
);
|
||||
name = Twinmoji;
|
||||
packageProductDependencies = (
|
||||
);
|
||||
productName = Twinmoji;
|
||||
productReference = DACBF8772D18F53100CCDAA4 /* Twinmoji.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
DACBF86F2D18F53100CCDAA4 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
LastSwiftUpdateCheck = 1620;
|
||||
LastUpgradeCheck = 1620;
|
||||
TargetAttributes = {
|
||||
DACBF8762D18F53100CCDAA4 = {
|
||||
CreatedOnToolsVersion = 16.2;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = DACBF8722D18F53100CCDAA4 /* Build configuration list for PBXProject "Twinmoji" */;
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = DACBF86E2D18F53100CCDAA4;
|
||||
minimizedProjectReferenceProxies = 1;
|
||||
preferredProjectObjectVersion = 77;
|
||||
productRefGroup = DACBF8782D18F53100CCDAA4 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
DACBF8762D18F53100CCDAA4 /* Twinmoji */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXResourcesBuildPhase section */
|
||||
DACBF8752D18F53100CCDAA4 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
DACBF8732D18F53100CCDAA4 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
DACBF8832D18F53300CCDAA4 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||
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_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
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;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu17;
|
||||
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 = 18.2;
|
||||
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
|
||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||
MTL_FAST_MATH = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
DACBF8842D18F53300CCDAA4 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||
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_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
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;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu17;
|
||||
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 = 18.2;
|
||||
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
SDKROOT = iphoneos;
|
||||
SWIFT_COMPILATION_MODE = wholemodule;
|
||||
VALIDATE_PRODUCT = YES;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
DACBF8862D18F53300CCDAA4 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"Twinmoji/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = HLUJ3BXM23;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
||||
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
||||
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.stewednoodles.Twinmoji;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
DACBF8872D18F53300CCDAA4 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"Twinmoji/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = HLUJ3BXM23;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
|
||||
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
|
||||
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.stewednoodles.Twinmoji;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
DACBF8722D18F53100CCDAA4 /* Build configuration list for PBXProject "Twinmoji" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
DACBF8832D18F53300CCDAA4 /* Debug */,
|
||||
DACBF8842D18F53300CCDAA4 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
DACBF8852D18F53300CCDAA4 /* Build configuration list for PBXNativeTarget "Twinmoji" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
DACBF8862D18F53300CCDAA4 /* Debug */,
|
||||
DACBF8872D18F53300CCDAA4 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = DACBF86F2D18F53100CCDAA4 /* Project object */;
|
||||
}
|
7
Twinmoji.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
7
Twinmoji.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
11
Twinmoji/Assets.xcassets/AccentColor.colorset/Contents.json
Normal file
11
Twinmoji/Assets.xcassets/AccentColor.colorset/Contents.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
35
Twinmoji/Assets.xcassets/AppIcon.appiconset/Contents.json
Normal file
35
Twinmoji/Assets.xcassets/AppIcon.appiconset/Contents.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"platform" : "ios",
|
||||
"size" : "1024x1024"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"idiom" : "universal",
|
||||
"platform" : "ios",
|
||||
"size" : "1024x1024"
|
||||
},
|
||||
{
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "tinted"
|
||||
}
|
||||
],
|
||||
"idiom" : "universal",
|
||||
"platform" : "ios",
|
||||
"size" : "1024x1024"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
6
Twinmoji/Assets.xcassets/Contents.json
Normal file
6
Twinmoji/Assets.xcassets/Contents.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
47
Twinmoji/CardView.swift
Normal file
47
Twinmoji/CardView.swift
Normal file
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// CardView.swift
|
||||
// Twinmoji
|
||||
//
|
||||
// Created by Zhang Mengxu on 2024/12/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CardView: View {
|
||||
var card: [String]
|
||||
var userCanAnswer: Bool
|
||||
var onSelect: (String) -> Void
|
||||
|
||||
var rows: Int {
|
||||
if card.count == 12 {
|
||||
4
|
||||
} else {
|
||||
3
|
||||
}
|
||||
}
|
||||
var body: some View {
|
||||
Grid(horizontalSpacing: 0, verticalSpacing: 0) {
|
||||
ForEach(0..<rows, id: \.self) { i in
|
||||
GridRow {
|
||||
ForEach(0..<3) { j in
|
||||
let text = card[i * 3 + j]
|
||||
Button(text) {
|
||||
onSelect(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.font(.system(size: 64))
|
||||
.padding()
|
||||
.background(.white)
|
||||
.clipShape(.rect(cornerRadius: 20))
|
||||
.fixedSize()
|
||||
.shadow(radius: 10)
|
||||
.disabled(userCanAnswer == false)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
CardView(card: ["1", "2", "3", "4", "5", "6", "7", "8", "9"], userCanAnswer: true) { _ in }
|
||||
}
|
109
Twinmoji/ContentView.swift
Normal file
109
Twinmoji/ContentView.swift
Normal file
@@ -0,0 +1,109 @@
|
||||
//
|
||||
// ContentView.swift
|
||||
// Twinmoji
|
||||
//
|
||||
// Created by Zhang Mengxu on 2024/12/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
enum GameState {
|
||||
case waiting
|
||||
case player1Answering
|
||||
case player2Answering
|
||||
}
|
||||
|
||||
struct ContentView: View {
|
||||
let allEmoji = Array("😎🥹🥰😔😂😳🧐🙂😇😅😆😙😬🙃😍🥸😣😶🙄🤨😩😉🥲😋😛🤓😏😭😯😵😐😘😢😠").map(String.init)
|
||||
@State private var currentEmoji = [String]()
|
||||
|
||||
@State private var leftCard = [String]()
|
||||
@State private var rightCard = [String]()
|
||||
|
||||
@State private var gameState = GameState.waiting
|
||||
|
||||
@State private var player1Score = 0
|
||||
@State private var player2Score = 0
|
||||
|
||||
@State private var answerColor = Color.clear
|
||||
@State private var answerScale = 1.0
|
||||
@State private var answerAnchor = UnitPoint.center
|
||||
|
||||
var itemCount: Int
|
||||
|
||||
var body: some View {
|
||||
HStack(spacing: 0) {
|
||||
PlayerButton(gameState: gameState, score: player1Score, color: .blue, onSelect: selectPlayer1)
|
||||
|
||||
ZStack {
|
||||
answerColor
|
||||
.scaleEffect(x: answerScale, anchor: answerAnchor)
|
||||
|
||||
if leftCard.isEmpty == false {
|
||||
HStack {
|
||||
CardView(card: leftCard)
|
||||
CardView(card: rightCard)
|
||||
|
||||
}
|
||||
.padding(.horizontal, 10)
|
||||
}
|
||||
}
|
||||
|
||||
PlayerButton(gameState: gameState, score: player2Score, color: .red, onSelect: selectPlayer2)
|
||||
|
||||
}
|
||||
.ignoresSafeArea()
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(Color(white: 0.9))
|
||||
.persistentSystemOverlays(.hidden)
|
||||
.onAppear(perform: createLevel)
|
||||
}
|
||||
|
||||
func createLevel() {
|
||||
currentEmoji = allEmoji.shuffled()
|
||||
withAnimation(.spring(duration: 0.75)) {
|
||||
leftCard = Array(currentEmoji[0..<itemCount]).shuffled()
|
||||
rightCard = Array(currentEmoji[itemCount + 1 ..< itemCount + itemCount] + [currentEmoji[0]]).shuffled()
|
||||
}
|
||||
}
|
||||
|
||||
func selectPlayer1() {
|
||||
guard gameState == .waiting else { return }
|
||||
answerColor = .blue
|
||||
answerAnchor = .leading
|
||||
gameState = .player1Answering
|
||||
runClock()
|
||||
}
|
||||
|
||||
func selectPlayer2() {
|
||||
guard gameState == .waiting else { return }
|
||||
answerColor = .red
|
||||
answerAnchor = .trailing
|
||||
gameState = .player2Answering
|
||||
runClock()
|
||||
}
|
||||
|
||||
func timeOut() {
|
||||
if gameState == .player1Answering {
|
||||
player1Score -= 1
|
||||
} else if gameState == .player2Answering {
|
||||
player2Score -= 1
|
||||
}
|
||||
|
||||
gameState = .waiting
|
||||
}
|
||||
|
||||
func runClock() {
|
||||
answerScale = 1
|
||||
|
||||
withAnimation(.linear(duration: 1)) {
|
||||
answerScale = 0
|
||||
} completion: {
|
||||
timeOut()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ContentView(itemCount: 9)
|
||||
}
|
36
Twinmoji/PlayerButton.swift
Normal file
36
Twinmoji/PlayerButton.swift
Normal file
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// PlayerButton.swift
|
||||
// Twinmoji
|
||||
//
|
||||
// Created by Zhang Mengxu on 2024/12/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct PlayerButton: View {
|
||||
var gameState: GameState
|
||||
var score: Int
|
||||
var color: Color
|
||||
var onSelect: () -> Void
|
||||
|
||||
var body: some View {
|
||||
Button(action: onSelect) {
|
||||
Rectangle()
|
||||
.fill(color)
|
||||
.frame(minWidth: 60)
|
||||
.overlay {
|
||||
Text(String(score))
|
||||
.fixedSize()
|
||||
.foregroundStyle(.white)
|
||||
.font(.system(size: 48).bold())
|
||||
}
|
||||
}
|
||||
.disabled(gameState != .waiting)
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
PlayerButton(gameState: .waiting, score: 5, color: .blue) {
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
17
Twinmoji/TwinmojiApp.swift
Normal file
17
Twinmoji/TwinmojiApp.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// TwinmojiApp.swift
|
||||
// Twinmoji
|
||||
//
|
||||
// Created by Zhang Mengxu on 2024/12/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct TwinmojiApp: App {
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ContentView(itemCount: 9)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user