├── AppIcon ├── Artwork.png └── Memorize.pxd │ ├── QuickLook │ ├── Icon.tiff │ └── Thumbnail.tiff │ └── metadata.info ├── Memorize.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── philipp.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── Memorize ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── AppIcon~iOS-Marketing-1024@1x.png │ │ ├── AppIcon~iPad-20@1x.png │ │ ├── AppIcon~iPad-20@2x.png │ │ ├── AppIcon~iPad-29@1x.png │ │ ├── AppIcon~iPad-29@2x.png │ │ ├── AppIcon~iPad-40@1x.png │ │ ├── AppIcon~iPad-40@2x.png │ │ ├── AppIcon~iPad-76@1x.png │ │ ├── AppIcon~iPad-76@2x.png │ │ ├── AppIcon~iPad-83.5@2x.png │ │ ├── AppIcon~iPhone-20@2x.png │ │ ├── AppIcon~iPhone-20@3x.png │ │ ├── AppIcon~iPhone-29@2x.png │ │ ├── AppIcon~iPhone-29@3x.png │ │ ├── AppIcon~iPhone-40@2x.png │ │ ├── AppIcon~iPhone-40@3x.png │ │ ├── AppIcon~iPhone-60@2x.png │ │ ├── AppIcon~iPhone-60@3x.png │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ └── LaunchScreen.storyboard ├── Cardify.swift ├── EmojiMemoryGame.swift ├── EmojiMemoryGameView.swift ├── EmojiMemoryTheme.swift ├── EmojiMemoryThemeChooser.swift ├── EmojiMemoryThemeEditor.swift ├── EmojiMemoryThemeStore.swift ├── Grid.swift ├── GridLayout.swift ├── Info.plist ├── MemorizeExtensions.swift ├── MemoryGame.swift ├── Pie.swift ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json └── SceneDelegate.swift ├── README.md └── Screencapture.gif /AppIcon/Artwork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/AppIcon/Artwork.png -------------------------------------------------------------------------------- /AppIcon/Memorize.pxd/QuickLook/Icon.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/AppIcon/Memorize.pxd/QuickLook/Icon.tiff -------------------------------------------------------------------------------- /AppIcon/Memorize.pxd/QuickLook/Thumbnail.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/AppIcon/Memorize.pxd/QuickLook/Thumbnail.tiff -------------------------------------------------------------------------------- /AppIcon/Memorize.pxd/metadata.info: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/AppIcon/Memorize.pxd/metadata.info -------------------------------------------------------------------------------- /Memorize.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 176861A6249042480088A6E4 /* EmojiMemoryGame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B4AF7524752C8D00C7F78B /* EmojiMemoryGame.swift */; }; 11 | 176861A8249046710088A6E4 /* MemorizeExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 176861A7249046710088A6E4 /* MemorizeExtensions.swift */; }; 12 | 17A3563424864E75001F23AD /* Pie.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A3563324864E75001F23AD /* Pie.swift */; }; 13 | 17A3563624865440001F23AD /* Cardify.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A3563524865440001F23AD /* Cardify.swift */; }; 14 | 17B4AF5C2474422C00C7F78B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B4AF5B2474422C00C7F78B /* AppDelegate.swift */; }; 15 | 17B4AF5E2474422C00C7F78B /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B4AF5D2474422C00C7F78B /* SceneDelegate.swift */; }; 16 | 17B4AF602474422C00C7F78B /* EmojiMemoryGameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B4AF5F2474422C00C7F78B /* EmojiMemoryGameView.swift */; }; 17 | 17B4AF622474423100C7F78B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 17B4AF612474423100C7F78B /* Assets.xcassets */; }; 18 | 17B4AF652474423100C7F78B /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 17B4AF642474423100C7F78B /* Preview Assets.xcassets */; }; 19 | 17B4AF682474423100C7F78B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 17B4AF662474423100C7F78B /* LaunchScreen.storyboard */; }; 20 | 17B4AF7424752A7600C7F78B /* MemoryGame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B4AF7324752A7600C7F78B /* MemoryGame.swift */; }; 21 | 17B4B429247D3A1900116EEE /* Grid.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B4B428247D3A1900116EEE /* Grid.swift */; }; 22 | 17B4B42B247D3AC700116EEE /* GridLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B4B42A247D3AC700116EEE /* GridLayout.swift */; }; 23 | 17F9C3DE2498C33500CDB50D /* EmojiMemoryTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F9C3DD2498C33500CDB50D /* EmojiMemoryTheme.swift */; }; 24 | 17F9C3E02498C39A00CDB50D /* EmojiMemoryThemeStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F9C3DF2498C39A00CDB50D /* EmojiMemoryThemeStore.swift */; }; 25 | 17F9C3E22498C5F300CDB50D /* EmojiMemoryThemeChooser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F9C3E12498C5F300CDB50D /* EmojiMemoryThemeChooser.swift */; }; 26 | 17F9C3E52499465D00CDB50D /* EmojiMemoryThemeEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F9C3E32498F28600CDB50D /* EmojiMemoryThemeEditor.swift */; }; 27 | /* End PBXBuildFile section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | 176861A7249046710088A6E4 /* MemorizeExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemorizeExtensions.swift; sourceTree = ""; }; 31 | 17A3563324864E75001F23AD /* Pie.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pie.swift; sourceTree = ""; }; 32 | 17A3563524865440001F23AD /* Cardify.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cardify.swift; sourceTree = ""; }; 33 | 17B4AF582474422C00C7F78B /* Memorize.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Memorize.app; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | 17B4AF5B2474422C00C7F78B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 35 | 17B4AF5D2474422C00C7F78B /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 36 | 17B4AF5F2474422C00C7F78B /* EmojiMemoryGameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiMemoryGameView.swift; sourceTree = ""; }; 37 | 17B4AF612474423100C7F78B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 38 | 17B4AF642474423100C7F78B /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 39 | 17B4AF672474423100C7F78B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 40 | 17B4AF692474423100C7F78B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | 17B4AF7324752A7600C7F78B /* MemoryGame.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoryGame.swift; sourceTree = ""; }; 42 | 17B4AF7524752C8D00C7F78B /* EmojiMemoryGame.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiMemoryGame.swift; sourceTree = ""; }; 43 | 17B4B428247D3A1900116EEE /* Grid.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Grid.swift; sourceTree = ""; }; 44 | 17B4B42A247D3AC700116EEE /* GridLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GridLayout.swift; sourceTree = ""; }; 45 | 17B4B430247D883F00116EEE /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 46 | 17F9C3DD2498C33500CDB50D /* EmojiMemoryTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiMemoryTheme.swift; sourceTree = ""; }; 47 | 17F9C3DF2498C39A00CDB50D /* EmojiMemoryThemeStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiMemoryThemeStore.swift; sourceTree = ""; }; 48 | 17F9C3E12498C5F300CDB50D /* EmojiMemoryThemeChooser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiMemoryThemeChooser.swift; sourceTree = ""; }; 49 | 17F9C3E32498F28600CDB50D /* EmojiMemoryThemeEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmojiMemoryThemeEditor.swift; sourceTree = ""; }; 50 | /* End PBXFileReference section */ 51 | 52 | /* Begin PBXFrameworksBuildPhase section */ 53 | 17B4AF552474422C00C7F78B /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | ); 58 | runOnlyForDeploymentPostprocessing = 0; 59 | }; 60 | /* End PBXFrameworksBuildPhase section */ 61 | 62 | /* Begin PBXGroup section */ 63 | 17B4AF4F2474422C00C7F78B = { 64 | isa = PBXGroup; 65 | children = ( 66 | 17B4B430247D883F00116EEE /* README.md */, 67 | 17B4AF5A2474422C00C7F78B /* Memorize */, 68 | 17B4AF592474422C00C7F78B /* Products */, 69 | ); 70 | sourceTree = ""; 71 | }; 72 | 17B4AF592474422C00C7F78B /* Products */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 17B4AF582474422C00C7F78B /* Memorize.app */, 76 | ); 77 | name = Products; 78 | sourceTree = ""; 79 | }; 80 | 17B4AF5A2474422C00C7F78B /* Memorize */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | 17B4AF5F2474422C00C7F78B /* EmojiMemoryGameView.swift */, 84 | 17B4AF7524752C8D00C7F78B /* EmojiMemoryGame.swift */, 85 | 17F9C3DD2498C33500CDB50D /* EmojiMemoryTheme.swift */, 86 | 17F9C3DF2498C39A00CDB50D /* EmojiMemoryThemeStore.swift */, 87 | 17F9C3E12498C5F300CDB50D /* EmojiMemoryThemeChooser.swift */, 88 | 17F9C3E32498F28600CDB50D /* EmojiMemoryThemeEditor.swift */, 89 | 17B4AF7324752A7600C7F78B /* MemoryGame.swift */, 90 | 17A3563524865440001F23AD /* Cardify.swift */, 91 | 17A3563324864E75001F23AD /* Pie.swift */, 92 | 17B4B428247D3A1900116EEE /* Grid.swift */, 93 | 17B4B42A247D3AC700116EEE /* GridLayout.swift */, 94 | 176861A7249046710088A6E4 /* MemorizeExtensions.swift */, 95 | 17B4AF5B2474422C00C7F78B /* AppDelegate.swift */, 96 | 17B4AF5D2474422C00C7F78B /* SceneDelegate.swift */, 97 | 17B4AF612474423100C7F78B /* Assets.xcassets */, 98 | 17B4AF662474423100C7F78B /* LaunchScreen.storyboard */, 99 | 17B4AF692474423100C7F78B /* Info.plist */, 100 | 17B4AF632474423100C7F78B /* Preview Content */, 101 | ); 102 | path = Memorize; 103 | sourceTree = ""; 104 | }; 105 | 17B4AF632474423100C7F78B /* Preview Content */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 17B4AF642474423100C7F78B /* Preview Assets.xcassets */, 109 | ); 110 | path = "Preview Content"; 111 | sourceTree = ""; 112 | }; 113 | /* End PBXGroup section */ 114 | 115 | /* Begin PBXNativeTarget section */ 116 | 17B4AF572474422C00C7F78B /* Memorize */ = { 117 | isa = PBXNativeTarget; 118 | buildConfigurationList = 17B4AF6C2474423100C7F78B /* Build configuration list for PBXNativeTarget "Memorize" */; 119 | buildPhases = ( 120 | 17B4AF542474422C00C7F78B /* Sources */, 121 | 17B4AF552474422C00C7F78B /* Frameworks */, 122 | 17B4AF562474422C00C7F78B /* Resources */, 123 | ); 124 | buildRules = ( 125 | ); 126 | dependencies = ( 127 | ); 128 | name = Memorize; 129 | productName = Memorize; 130 | productReference = 17B4AF582474422C00C7F78B /* Memorize.app */; 131 | productType = "com.apple.product-type.application"; 132 | }; 133 | /* End PBXNativeTarget section */ 134 | 135 | /* Begin PBXProject section */ 136 | 17B4AF502474422C00C7F78B /* Project object */ = { 137 | isa = PBXProject; 138 | attributes = { 139 | LastSwiftUpdateCheck = 1140; 140 | LastUpgradeCheck = 1140; 141 | ORGANIZATIONNAME = Philipp; 142 | TargetAttributes = { 143 | 17B4AF572474422C00C7F78B = { 144 | CreatedOnToolsVersion = 11.4.1; 145 | }; 146 | }; 147 | }; 148 | buildConfigurationList = 17B4AF532474422C00C7F78B /* Build configuration list for PBXProject "Memorize" */; 149 | compatibilityVersion = "Xcode 9.3"; 150 | developmentRegion = en; 151 | hasScannedForEncodings = 0; 152 | knownRegions = ( 153 | en, 154 | Base, 155 | ); 156 | mainGroup = 17B4AF4F2474422C00C7F78B; 157 | productRefGroup = 17B4AF592474422C00C7F78B /* Products */; 158 | projectDirPath = ""; 159 | projectRoot = ""; 160 | targets = ( 161 | 17B4AF572474422C00C7F78B /* Memorize */, 162 | ); 163 | }; 164 | /* End PBXProject section */ 165 | 166 | /* Begin PBXResourcesBuildPhase section */ 167 | 17B4AF562474422C00C7F78B /* Resources */ = { 168 | isa = PBXResourcesBuildPhase; 169 | buildActionMask = 2147483647; 170 | files = ( 171 | 17B4AF682474423100C7F78B /* LaunchScreen.storyboard in Resources */, 172 | 17B4AF652474423100C7F78B /* Preview Assets.xcassets in Resources */, 173 | 17B4AF622474423100C7F78B /* Assets.xcassets in Resources */, 174 | ); 175 | runOnlyForDeploymentPostprocessing = 0; 176 | }; 177 | /* End PBXResourcesBuildPhase section */ 178 | 179 | /* Begin PBXSourcesBuildPhase section */ 180 | 17B4AF542474422C00C7F78B /* Sources */ = { 181 | isa = PBXSourcesBuildPhase; 182 | buildActionMask = 2147483647; 183 | files = ( 184 | 17A3563624865440001F23AD /* Cardify.swift in Sources */, 185 | 176861A8249046710088A6E4 /* MemorizeExtensions.swift in Sources */, 186 | 17F9C3E52499465D00CDB50D /* EmojiMemoryThemeEditor.swift in Sources */, 187 | 17A3563424864E75001F23AD /* Pie.swift in Sources */, 188 | 17B4AF5C2474422C00C7F78B /* AppDelegate.swift in Sources */, 189 | 17B4AF5E2474422C00C7F78B /* SceneDelegate.swift in Sources */, 190 | 17F9C3DE2498C33500CDB50D /* EmojiMemoryTheme.swift in Sources */, 191 | 17B4AF7424752A7600C7F78B /* MemoryGame.swift in Sources */, 192 | 17F9C3E22498C5F300CDB50D /* EmojiMemoryThemeChooser.swift in Sources */, 193 | 17F9C3E02498C39A00CDB50D /* EmojiMemoryThemeStore.swift in Sources */, 194 | 17B4AF602474422C00C7F78B /* EmojiMemoryGameView.swift in Sources */, 195 | 17B4B42B247D3AC700116EEE /* GridLayout.swift in Sources */, 196 | 17B4B429247D3A1900116EEE /* Grid.swift in Sources */, 197 | 176861A6249042480088A6E4 /* EmojiMemoryGame.swift in Sources */, 198 | ); 199 | runOnlyForDeploymentPostprocessing = 0; 200 | }; 201 | /* End PBXSourcesBuildPhase section */ 202 | 203 | /* Begin PBXVariantGroup section */ 204 | 17B4AF662474423100C7F78B /* LaunchScreen.storyboard */ = { 205 | isa = PBXVariantGroup; 206 | children = ( 207 | 17B4AF672474423100C7F78B /* Base */, 208 | ); 209 | name = LaunchScreen.storyboard; 210 | sourceTree = ""; 211 | }; 212 | /* End PBXVariantGroup section */ 213 | 214 | /* Begin XCBuildConfiguration section */ 215 | 17B4AF6A2474423100C7F78B /* Debug */ = { 216 | isa = XCBuildConfiguration; 217 | buildSettings = { 218 | ALWAYS_SEARCH_USER_PATHS = NO; 219 | CLANG_ANALYZER_NONNULL = YES; 220 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 221 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 222 | CLANG_CXX_LIBRARY = "libc++"; 223 | CLANG_ENABLE_MODULES = YES; 224 | CLANG_ENABLE_OBJC_ARC = YES; 225 | CLANG_ENABLE_OBJC_WEAK = YES; 226 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 227 | CLANG_WARN_BOOL_CONVERSION = YES; 228 | CLANG_WARN_COMMA = YES; 229 | CLANG_WARN_CONSTANT_CONVERSION = YES; 230 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 231 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 232 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 233 | CLANG_WARN_EMPTY_BODY = YES; 234 | CLANG_WARN_ENUM_CONVERSION = YES; 235 | CLANG_WARN_INFINITE_RECURSION = YES; 236 | CLANG_WARN_INT_CONVERSION = YES; 237 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 238 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 239 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 240 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 241 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 242 | CLANG_WARN_STRICT_PROTOTYPES = YES; 243 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 244 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 245 | CLANG_WARN_UNREACHABLE_CODE = YES; 246 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 247 | COPY_PHASE_STRIP = NO; 248 | DEBUG_INFORMATION_FORMAT = dwarf; 249 | ENABLE_STRICT_OBJC_MSGSEND = YES; 250 | ENABLE_TESTABILITY = YES; 251 | GCC_C_LANGUAGE_STANDARD = gnu11; 252 | GCC_DYNAMIC_NO_PIC = NO; 253 | GCC_NO_COMMON_BLOCKS = YES; 254 | GCC_OPTIMIZATION_LEVEL = 0; 255 | GCC_PREPROCESSOR_DEFINITIONS = ( 256 | "DEBUG=1", 257 | "$(inherited)", 258 | ); 259 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 260 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 261 | GCC_WARN_UNDECLARED_SELECTOR = YES; 262 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 263 | GCC_WARN_UNUSED_FUNCTION = YES; 264 | GCC_WARN_UNUSED_VARIABLE = YES; 265 | IPHONEOS_DEPLOYMENT_TARGET = 13.4; 266 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 267 | MTL_FAST_MATH = YES; 268 | ONLY_ACTIVE_ARCH = YES; 269 | SDKROOT = iphoneos; 270 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 271 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 272 | }; 273 | name = Debug; 274 | }; 275 | 17B4AF6B2474423100C7F78B /* Release */ = { 276 | isa = XCBuildConfiguration; 277 | buildSettings = { 278 | ALWAYS_SEARCH_USER_PATHS = NO; 279 | CLANG_ANALYZER_NONNULL = YES; 280 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 281 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 282 | CLANG_CXX_LIBRARY = "libc++"; 283 | CLANG_ENABLE_MODULES = YES; 284 | CLANG_ENABLE_OBJC_ARC = YES; 285 | CLANG_ENABLE_OBJC_WEAK = YES; 286 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 287 | CLANG_WARN_BOOL_CONVERSION = YES; 288 | CLANG_WARN_COMMA = YES; 289 | CLANG_WARN_CONSTANT_CONVERSION = YES; 290 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 291 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 292 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 293 | CLANG_WARN_EMPTY_BODY = YES; 294 | CLANG_WARN_ENUM_CONVERSION = YES; 295 | CLANG_WARN_INFINITE_RECURSION = YES; 296 | CLANG_WARN_INT_CONVERSION = YES; 297 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 298 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 299 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 300 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 301 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 302 | CLANG_WARN_STRICT_PROTOTYPES = YES; 303 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 304 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 305 | CLANG_WARN_UNREACHABLE_CODE = YES; 306 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 307 | COPY_PHASE_STRIP = NO; 308 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 309 | ENABLE_NS_ASSERTIONS = NO; 310 | ENABLE_STRICT_OBJC_MSGSEND = YES; 311 | GCC_C_LANGUAGE_STANDARD = gnu11; 312 | GCC_NO_COMMON_BLOCKS = YES; 313 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 314 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 315 | GCC_WARN_UNDECLARED_SELECTOR = YES; 316 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 317 | GCC_WARN_UNUSED_FUNCTION = YES; 318 | GCC_WARN_UNUSED_VARIABLE = YES; 319 | IPHONEOS_DEPLOYMENT_TARGET = 13.4; 320 | MTL_ENABLE_DEBUG_INFO = NO; 321 | MTL_FAST_MATH = YES; 322 | SDKROOT = iphoneos; 323 | SWIFT_COMPILATION_MODE = wholemodule; 324 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 325 | VALIDATE_PRODUCT = YES; 326 | }; 327 | name = Release; 328 | }; 329 | 17B4AF6D2474423100C7F78B /* Debug */ = { 330 | isa = XCBuildConfiguration; 331 | buildSettings = { 332 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 333 | CODE_SIGN_STYLE = Automatic; 334 | DEVELOPMENT_ASSET_PATHS = "\"Memorize/Preview Content\""; 335 | DEVELOPMENT_TEAM = P8CC95REUG; 336 | ENABLE_PREVIEWS = YES; 337 | INFOPLIST_FILE = Memorize/Info.plist; 338 | LD_RUNPATH_SEARCH_PATHS = ( 339 | "$(inherited)", 340 | "@executable_path/Frameworks", 341 | ); 342 | PRODUCT_BUNDLE_IDENTIFIER = com.yourcompany.stanford.Memorize; 343 | PRODUCT_NAME = "$(TARGET_NAME)"; 344 | SWIFT_VERSION = 5.0; 345 | TARGETED_DEVICE_FAMILY = "1,2"; 346 | }; 347 | name = Debug; 348 | }; 349 | 17B4AF6E2474423100C7F78B /* Release */ = { 350 | isa = XCBuildConfiguration; 351 | buildSettings = { 352 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 353 | CODE_SIGN_STYLE = Automatic; 354 | DEVELOPMENT_ASSET_PATHS = "\"Memorize/Preview Content\""; 355 | DEVELOPMENT_TEAM = P8CC95REUG; 356 | ENABLE_PREVIEWS = YES; 357 | INFOPLIST_FILE = Memorize/Info.plist; 358 | LD_RUNPATH_SEARCH_PATHS = ( 359 | "$(inherited)", 360 | "@executable_path/Frameworks", 361 | ); 362 | PRODUCT_BUNDLE_IDENTIFIER = com.yourcompany.stanford.Memorize; 363 | PRODUCT_NAME = "$(TARGET_NAME)"; 364 | SWIFT_VERSION = 5.0; 365 | TARGETED_DEVICE_FAMILY = "1,2"; 366 | }; 367 | name = Release; 368 | }; 369 | /* End XCBuildConfiguration section */ 370 | 371 | /* Begin XCConfigurationList section */ 372 | 17B4AF532474422C00C7F78B /* Build configuration list for PBXProject "Memorize" */ = { 373 | isa = XCConfigurationList; 374 | buildConfigurations = ( 375 | 17B4AF6A2474423100C7F78B /* Debug */, 376 | 17B4AF6B2474423100C7F78B /* Release */, 377 | ); 378 | defaultConfigurationIsVisible = 0; 379 | defaultConfigurationName = Release; 380 | }; 381 | 17B4AF6C2474423100C7F78B /* Build configuration list for PBXNativeTarget "Memorize" */ = { 382 | isa = XCConfigurationList; 383 | buildConfigurations = ( 384 | 17B4AF6D2474423100C7F78B /* Debug */, 385 | 17B4AF6E2474423100C7F78B /* Release */, 386 | ); 387 | defaultConfigurationIsVisible = 0; 388 | defaultConfigurationName = Release; 389 | }; 390 | /* End XCConfigurationList section */ 391 | }; 392 | rootObject = 17B4AF502474422C00C7F78B /* Project object */; 393 | } 394 | -------------------------------------------------------------------------------- /Memorize.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Memorize.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Memorize.xcodeproj/xcuserdata/philipp.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Memorize.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Memorize/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 19.05.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | // MARK: UISceneSession Lifecycle 22 | 23 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 24 | // Called when a new scene session is being created. 25 | // Use this method to select a configuration to create the new scene with. 26 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 27 | } 28 | 29 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 30 | // Called when the user discards a scene session. 31 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 32 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 33 | } 34 | 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iOS-Marketing-1024@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iOS-Marketing-1024@1x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-20@1x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-20@2x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-29@1x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-29@2x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-40@1x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-40@2x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-76@1x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-76@2x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPad-83.5@2x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-20@2x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-20@3x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-29@2x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-29@3x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-40@2x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-40@3x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-60@2x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Memorize/Assets.xcassets/AppIcon.appiconset/AppIcon~iPhone-60@3x.png -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "AppIcon~iPhone-20@2x.png", 5 | "idiom" : "iphone", 6 | "scale" : "2x", 7 | "size" : "20x20" 8 | }, 9 | { 10 | "filename" : "AppIcon~iPhone-20@3x.png", 11 | "idiom" : "iphone", 12 | "scale" : "3x", 13 | "size" : "20x20" 14 | }, 15 | { 16 | "filename" : "AppIcon~iPhone-29@2x.png", 17 | "idiom" : "iphone", 18 | "scale" : "2x", 19 | "size" : "29x29" 20 | }, 21 | { 22 | "filename" : "AppIcon~iPhone-29@3x.png", 23 | "idiom" : "iphone", 24 | "scale" : "3x", 25 | "size" : "29x29" 26 | }, 27 | { 28 | "filename" : "AppIcon~iPhone-40@2x.png", 29 | "idiom" : "iphone", 30 | "scale" : "2x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "filename" : "AppIcon~iPhone-40@3x.png", 35 | "idiom" : "iphone", 36 | "scale" : "3x", 37 | "size" : "40x40" 38 | }, 39 | { 40 | "filename" : "AppIcon~iPhone-60@2x.png", 41 | "idiom" : "iphone", 42 | "scale" : "2x", 43 | "size" : "60x60" 44 | }, 45 | { 46 | "filename" : "AppIcon~iPhone-60@3x.png", 47 | "idiom" : "iphone", 48 | "scale" : "3x", 49 | "size" : "60x60" 50 | }, 51 | { 52 | "filename" : "AppIcon~iPad-20@1x.png", 53 | "idiom" : "ipad", 54 | "scale" : "1x", 55 | "size" : "20x20" 56 | }, 57 | { 58 | "filename" : "AppIcon~iPad-20@2x.png", 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "20x20" 62 | }, 63 | { 64 | "filename" : "AppIcon~iPad-29@1x.png", 65 | "idiom" : "ipad", 66 | "scale" : "1x", 67 | "size" : "29x29" 68 | }, 69 | { 70 | "filename" : "AppIcon~iPad-29@2x.png", 71 | "idiom" : "ipad", 72 | "scale" : "2x", 73 | "size" : "29x29" 74 | }, 75 | { 76 | "filename" : "AppIcon~iPad-40@1x.png", 77 | "idiom" : "ipad", 78 | "scale" : "1x", 79 | "size" : "40x40" 80 | }, 81 | { 82 | "filename" : "AppIcon~iPad-40@2x.png", 83 | "idiom" : "ipad", 84 | "scale" : "2x", 85 | "size" : "40x40" 86 | }, 87 | { 88 | "filename" : "AppIcon~iPad-76@1x.png", 89 | "idiom" : "ipad", 90 | "scale" : "1x", 91 | "size" : "76x76" 92 | }, 93 | { 94 | "filename" : "AppIcon~iPad-76@2x.png", 95 | "idiom" : "ipad", 96 | "scale" : "2x", 97 | "size" : "76x76" 98 | }, 99 | { 100 | "filename" : "AppIcon~iPad-83.5@2x.png", 101 | "idiom" : "ipad", 102 | "scale" : "2x", 103 | "size" : "83.5x83.5" 104 | }, 105 | { 106 | "filename" : "AppIcon~iOS-Marketing-1024@1x.png", 107 | "idiom" : "ios-marketing", 108 | "scale" : "1x", 109 | "size" : "1024x1024" 110 | } 111 | ], 112 | "info" : { 113 | "author" : "xcode", 114 | "version" : 1 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /Memorize/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Memorize/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Memorize/Cardify.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Cardify.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 02.06.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct Cardify: AnimatableModifier { 12 | var rotation: Double 13 | 14 | var isFaceUp: Bool { 15 | rotation < 90 16 | } 17 | 18 | var animatableData: Double { 19 | get { rotation } 20 | set { rotation = newValue } 21 | } 22 | 23 | init(isFaceUp: Bool) { 24 | rotation = isFaceUp ? 0 : 180 25 | } 26 | 27 | func body(content: Content) -> some View { 28 | ZStack { 29 | Group { 30 | RoundedRectangle(cornerRadius: cornerRadius) 31 | .fill(Color.white) 32 | RoundedRectangle(cornerRadius: cornerRadius) 33 | .stroke(lineWidth: edgeLineWidth) 34 | content 35 | } 36 | .opacity(isFaceUp ? 1 : 0) 37 | 38 | Group { 39 | RoundedRectangle(cornerRadius: cornerRadius) 40 | .fill(LinearGradient(gradient: Gradient(colors: [Color.accentColor.opacity(0.1), Color.accentColor]), 41 | startPoint: .bottom, endPoint: .top)) 42 | RoundedRectangle(cornerRadius: cornerRadius) 43 | .stroke(lineWidth: 1) 44 | } 45 | .opacity(isFaceUp ? 0 : 1) 46 | } 47 | .rotation3DEffect(.degrees(rotation), axis: (x: 0, y: 1, z: 0)) 48 | } 49 | 50 | private let cornerRadius: CGFloat = 10 51 | private let edgeLineWidth: CGFloat = 3 52 | } 53 | 54 | extension View { 55 | func cardify(isFaceUp: Bool) -> some View { 56 | self.modifier(Cardify(isFaceUp: isFaceUp)) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Memorize/EmojiMemoryGame.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EmojiMemoryGame.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 20.05.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | class EmojiMemoryGame: ObservableObject { 12 | 13 | @Published private var model: MemoryGame 14 | private(set) var theme: EmojiMemoryTheme 15 | 16 | init(theme: EmojiMemoryTheme? = nil) { 17 | self.theme = theme ?? EmojiMemoryTheme.themes.randomElement()! 18 | let emoji = self.theme.emoji.shuffled() 19 | model = MemoryGame(numberOfPairsOfCards: self.theme.numberOfPairs) { emoji[$0] } 20 | } 21 | 22 | // MARK: - Access to the Model 23 | 24 | var cards: [MemoryGame.Card] { 25 | model.cards 26 | } 27 | 28 | var score: Int { 29 | model.score 30 | } 31 | 32 | // MARK: - Intent(s) 33 | 34 | func choose(card: MemoryGame.Card) { 35 | model.choose(card: card) 36 | } 37 | 38 | func restart() { 39 | let emoji = theme.emoji.shuffled() 40 | let numberOfPairs: Int = theme.numberOfPairs 41 | model = MemoryGame(numberOfPairsOfCards: numberOfPairs) { emoji[$0] } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Memorize/EmojiMemoryGameView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EmojiMemoryGameView.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 19.05.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct EmojiMemoryGameView: View { 12 | @ObservedObject var viewModel: EmojiMemoryGame 13 | 14 | var body: some View { 15 | VStack { 16 | Grid(viewModel.cards) { card in 17 | CardView(card: card) 18 | .padding(5) 19 | .onTapGesture { 20 | withAnimation(.linear(duration: 0.6)) { 21 | self.viewModel.choose(card: card) 22 | } 23 | } 24 | } 25 | .padding() 26 | .foregroundColor(viewModel.theme.color) 27 | 28 | restartButton 29 | } 30 | .accentColor(viewModel.theme.color) 31 | .padding() 32 | .navigationBarTitle(Text(viewModel.theme.name), displayMode: .large) 33 | .navigationBarItems(trailing: Text("\(viewModel.score)").font(.largeTitle)) 34 | } 35 | 36 | private var restartButton: some View { 37 | Button(action: restart) { 38 | Text("New Game") 39 | .font(.headline) 40 | .padding() 41 | .foregroundColor(Color.white) 42 | .background( 43 | RoundedRectangle(cornerRadius: 8) 44 | .fill(viewModel.theme.color)) 45 | .overlay( 46 | RoundedRectangle(cornerRadius: 8) 47 | .stroke(Color.primary, lineWidth: 1)) 48 | .shadow(radius: 5) 49 | } 50 | } 51 | 52 | private func restart() { 53 | withAnimation(.easeInOut) { 54 | viewModel.restart() 55 | } 56 | } 57 | } 58 | 59 | struct CardView: View { 60 | let card: MemoryGame.Card 61 | 62 | var body: some View { 63 | GeometryReader { proxy in 64 | self.body(for: proxy.size) 65 | } 66 | } 67 | 68 | @State private var animatedBonusRemaining: Double = 0 69 | 70 | private func startBonusTimeAnimation() { 71 | animatedBonusRemaining = card.bonusRemaining 72 | withAnimation(.linear(duration: card.bonusTimeRemaining)) { 73 | animatedBonusRemaining = 0 74 | } 75 | } 76 | 77 | @ViewBuilder 78 | private func body(for size: CGSize) -> some View { 79 | if card.isFaceUp || !card.isMatched { 80 | ZStack { 81 | Group { 82 | if card.isConsumingBonusTime { 83 | Pie(startAngle: .degrees(0-90), endAngle: .degrees(-animatedBonusRemaining*360-90), clockwise: true) 84 | .onAppear { 85 | self.startBonusTimeAnimation() 86 | } 87 | } 88 | else { 89 | Pie(startAngle: .degrees(0-90), endAngle: .degrees(-card.bonusRemaining*360-90), clockwise: true) 90 | } 91 | } 92 | .padding(5) 93 | .opacity(0.4) 94 | .transition(.identity) 95 | 96 | Text(card.content) 97 | .font(fontSize(for: size)) 98 | .rotationEffect(Angle.degrees(card.isMatched ? 360 : 0)) 99 | .animation(card.isMatched ? Animation.linear(duration: 1) 100 | .repeatForever(autoreverses: false) : .default) 101 | } 102 | .cardify(isFaceUp: card.isFaceUp) 103 | .transition(AnyTransition.scale) 104 | } 105 | } 106 | 107 | // MARK: - Drawing Constants 108 | 109 | private func fontSize(for size: CGSize) -> Font { 110 | Font.system(size: min(size.width, size.height) * 0.70) 111 | } 112 | } 113 | 114 | 115 | 116 | struct ContentView_Previews: PreviewProvider { 117 | static var previews: some View { 118 | let game = EmojiMemoryGame() 119 | game.choose(card: game.cards[0]) 120 | return NavigationView { 121 | EmojiMemoryGameView(viewModel: game) 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Memorize/EmojiMemoryTheme.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EmojiMemoryTheme.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 16.06.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SwiftUI 11 | 12 | struct EmojiMemoryTheme: Codable, Identifiable { 13 | var id: String { name } 14 | let name: String 15 | let emoji: [String] 16 | let colorRGB: UIColor.RGB 17 | let numberOfPairs: Int 18 | 19 | var color: Color { 20 | Color(colorRGB) 21 | } 22 | 23 | var json: Data? { 24 | try? JSONEncoder().encode(self) 25 | } 26 | 27 | init(name: String, emoji: [String], colorRGB: UIColor.RGB, numberOfPairs: Int) { 28 | self.name = name 29 | self.emoji = emoji 30 | self.colorRGB = colorRGB 31 | self.numberOfPairs = numberOfPairs 32 | } 33 | 34 | init?(json: Data?) { 35 | if let json = json, let newEmojiTheme = try? JSONDecoder().decode(EmojiMemoryTheme.self, from: json) { 36 | self = newEmojiTheme 37 | } 38 | else { 39 | return nil 40 | } 41 | } 42 | 43 | static var themes: [EmojiMemoryTheme] = [ 44 | EmojiMemoryTheme(name: "Animals", emoji: ["🐶","🐯","🐱","🐭","🦊","🐻","🐼","🐷","🐨","🐵","🦁", "🐔"], colorRGB: UIColor.blue.rgb, numberOfPairs: 8), 45 | EmojiMemoryTheme(name: "Halloween", emoji: ["👻","🎃","🧟","🕷","🕸", "🦇", "🪓", "🔪", "⛓", "⚰️"], colorRGB: UIColor.orange.rgb, numberOfPairs: 6), 46 | EmojiMemoryTheme(name: "Suites", emoji: ["♠️","♣️","♥️","♦️"], colorRGB: UIColor.gray.rgb, numberOfPairs: 4), 47 | EmojiMemoryTheme(name: "Sport", emoji: ["⚽️","🏀","🏈","⚾️","🎾","🏐","🎱", "🏉", "🏓", "🥎", "🥇", "🏆"], colorRGB: UIColor.red.rgb, numberOfPairs: 6), 48 | EmojiMemoryTheme(name: "Food", emoji: ["🍏","🍎","🍊","🍋","🍌","🥑","🥝","🍇","🍐","🍓","🍒","🍉"], colorRGB: UIColor.blue.rgb, numberOfPairs: 8), 49 | EmojiMemoryTheme(name: "Vehicles", emoji: ["🚕","🚌","🚓","🚑","🚒","🚜","🚚","🚛","🚠","🚋","🚄","✈️","🛳","🚁","🚂"], colorRGB: UIColor.purple.rgb, numberOfPairs: 5), 50 | EmojiMemoryTheme(name: "Faces", emoji: ["😃","😂","😍","🙃","😇","😎","🤓","🤩", 51 | "🤬","🥶","🤢","🤠","😷","🤕","😱","😜", 52 | "🥵","🤡","💩","🥳"], 53 | colorRGB: UIColor.systemPink.rgb, numberOfPairs: 7), 54 | ] 55 | 56 | static let template = EmojiMemoryTheme(name: "Untitled", emoji: ["😃", "👍🏻", "🌈", "❤️"], colorRGB: UIColor.systemGreen.rgb, numberOfPairs: 4) 57 | } 58 | -------------------------------------------------------------------------------- /Memorize/EmojiMemoryThemeChooser.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EmojiMemoryThemeChooser.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 16.06.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct EmojiMemoryThemeChooser: View { 12 | @EnvironmentObject var store: EmojiMemoryThemeStore 13 | @State private var editMode: EditMode = .inactive 14 | @State private var showThemeEditor = false 15 | @State private var editingTheme: EmojiMemoryTheme? 16 | 17 | var body: some View { 18 | NavigationView { 19 | List { 20 | ForEach(store.themes) { theme in 21 | ZStack { 22 | EmojiThemeRow(theme: theme, isEditing: self.editMode == .active) { 23 | self.editingTheme = theme 24 | } 25 | 26 | // An empty NavigationLink so that the "navigation chevron" can be hidden, but still the same "row content" is shown 27 | NavigationLink(destination: EmojiMemoryGameView(viewModel: EmojiMemoryGame(theme: theme))) { 28 | Color.clear 29 | } 30 | .opacity(self.editMode.isEditing ? 0 : 1) 31 | } 32 | } 33 | .onDelete { indexSet in 34 | self.store.themes.remove(atOffsets: indexSet) 35 | } 36 | } 37 | .sheet(item: self.$editingTheme, content: { theme in 38 | EmojiMemoryThemeEditor(theme: theme) 39 | .environmentObject(self.store) 40 | }) 41 | .navigationBarTitle("Memorize") 42 | .navigationBarItems( 43 | leading: Button(action: { self.store.themes.append(EmojiMemoryTheme.template) }, 44 | label: { Image(systemName: "plus").imageScale(.large) }) 45 | .opacity(editMode == .inactive ? 1 : 0), 46 | trailing: EditButton()) 47 | .environment(\.editMode, $editMode) 48 | } 49 | } 50 | } 51 | 52 | struct EmojiMemoryThemeChooser_Previews: PreviewProvider { 53 | static var previews: some View { 54 | EmojiMemoryThemeChooser() 55 | .environmentObject(EmojiMemoryThemeStore()) 56 | } 57 | } 58 | 59 | struct EmojiThemeRow: View { 60 | let theme: EmojiMemoryTheme 61 | let isEditing: Bool 62 | let editTheme: ()->Void 63 | 64 | var body: some View { 65 | HStack { 66 | VStack(alignment: .leading) { 67 | Text(theme.name) 68 | .font(.title) 69 | .foregroundColor(self.isEditing ? Color.primary : theme.color) 70 | 71 | HStack { 72 | Text("\(theme.numberOfPairs == theme.emoji.count ? "All" : "\(theme.numberOfPairs)") of \(theme.emoji.joined())") 73 | .truncationMode(.tail) 74 | .lineLimit(1) 75 | } 76 | } 77 | Spacer() 78 | 79 | if self.isEditing { 80 | Button(action: editTheme) { 81 | Image(systemName: "pencil.circle.fill") 82 | .imageScale(.large) 83 | } 84 | .buttonStyle(PlainButtonStyle()) 85 | .foregroundColor(theme.color) 86 | } 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Memorize/EmojiMemoryThemeEditor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EmojiMemoryThemeEditor.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 16.06.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct EmojiMemoryThemeEditor: View { 12 | @Environment(\.presentationMode) var presentationMode 13 | @EnvironmentObject var store: EmojiMemoryThemeStore 14 | 15 | let theme: EmojiMemoryTheme 16 | 17 | @State private var name: String = "" 18 | @State private var emojis: [String] = ["❤️"] 19 | @State private var numberOfPairs: Int = 4 20 | @State private var color: UIColor = .brown 21 | @State private var addEmoji: String = "" 22 | 23 | var body: some View { 24 | NavigationView { 25 | Form { 26 | nameSection 27 | 28 | addEmojiSection 29 | 30 | emojisSection 31 | 32 | cardCountSection 33 | 34 | colorSection 35 | } 36 | .onAppear() { 37 | self.name = self.theme.name 38 | self.emojis = self.theme.emoji 39 | self.numberOfPairs = self.theme.numberOfPairs 40 | self.color = UIColor(self.theme.colorRGB) 41 | } 42 | .navigationBarTitle(Text(self.theme.name), displayMode: .inline) 43 | .navigationBarItems( 44 | leading: Button(action: cancel, label: { Text("Cancel") }), 45 | trailing: Button(action: saveTheme, label: { Text("Done") }) 46 | .disabled(cannotSave) 47 | ) 48 | } 49 | } 50 | 51 | var nameSection: some View { 52 | Section { 53 | TextField("Theme Name", text: $name) 54 | } 55 | } 56 | 57 | var addEmojiSection: some View { 58 | Section(header: Text("Add Emoji").font(.headline)) { 59 | HStack { 60 | TextField("Emoji", text: $addEmoji) 61 | Button(action: { 62 | let newEmojis = self.addEmoji.trimmingCharacters(in: .whitespacesAndNewlines) 63 | self.emojis.insert(contentsOf: Set(newEmojis.map{String($0)}), at: 0) 64 | self.addEmoji = "" 65 | }) { 66 | Text("Add") 67 | } 68 | .buttonStyle(BorderlessButtonStyle()) 69 | } 70 | } 71 | } 72 | 73 | var emojisSection: some View { 74 | Section(header: HStack { 75 | Text("Emojis").font(.headline) 76 | Spacer() 77 | Text("tap emoji to exclude") 78 | }) { 79 | Grid(self.emojis, id: \.self, viewForItem: emojiItemView) 80 | .frame(height: self.emojiGridHeight) 81 | } 82 | } 83 | 84 | func emojiItemView(_ emoji: String) -> some View { 85 | Text(emoji) 86 | .font(Font.system(size: self.emojiGridFontSize)) 87 | .onTapGesture { 88 | self.emojis.removeAll(where: { $0 == emoji }) 89 | self.numberOfPairs = min(self.emojis.count, self.numberOfPairs) 90 | } 91 | } 92 | 93 | var cardCountSection: some View { 94 | Section(header: Text("Card Count").font(.headline)) { 95 | Stepper("\(numberOfPairs) pairs", value: $numberOfPairs, in: min(emojis.count, 2)...emojis.count) 96 | .disabled(emojis.count < 2) 97 | } 98 | } 99 | 100 | // List of available colors to choose from 101 | static let colorPatches: [UIColor] = [ 102 | .label, .secondaryLabel, .systemGray3, .systemYellow, .systemOrange, .systemRed, .systemPink, 103 | .systemGreen, .systemTeal,.systemBlue, 104 | .systemIndigo, .systemPurple, 105 | ] 106 | 107 | var colorSection: some View { 108 | Section(header: Text("Color").font(.headline)) { 109 | Grid(Self.colorPatches, id: \.self, viewForItem: colorItemView) 110 | .frame(height: self.colorGridHeight) 111 | } 112 | } 113 | 114 | // A color patch representing a color to choose. 115 | // The selection is shown using a filled checkmark symbol 116 | private func colorItemView(_ color: UIColor) -> some View { 117 | // determine "brightness" of the color to influence the checkmark color 118 | var brightness: CGFloat = .zero 119 | color.getWhite(&brightness, alpha: nil) 120 | 121 | return RoundedRectangle(cornerRadius: 4) 122 | .foregroundColor(Color(color)) 123 | .padding(2) 124 | .overlay(Group { 125 | if color.rgb == self.color.rgb { 126 | Image(systemName: "checkmark.circle.fill") 127 | .foregroundColor(brightness < 0.55 ? .white : .black) 128 | } 129 | }) 130 | .onTapGesture { 131 | self.color = color 132 | } 133 | } 134 | 135 | // MARK: - Confirmation actions 136 | 137 | private var cannotSave: Bool { 138 | name.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || 139 | emojis.count < 2 140 | } 141 | 142 | private func saveTheme() { 143 | name = name.trimmingCharacters(in: .whitespacesAndNewlines) 144 | store.updateTheme(for: theme, name: name, emoji: emojis, colorRGB: color.rgb, numberOfPairs: numberOfPairs) 145 | presentationMode.wrappedValue.dismiss() 146 | } 147 | 148 | private func cancel() { 149 | presentationMode.wrappedValue.dismiss() 150 | } 151 | 152 | // MARK: - Drawing Constants 153 | 154 | private let emojiGridFontSize: CGFloat = 40 155 | private var emojiGridHeight: CGFloat { 156 | CGFloat((emojis.count - 1 ) / 6 * 70 + 70) 157 | } 158 | 159 | private var colorGridHeight: CGFloat { 160 | CGFloat((Self.colorPatches.count - 1 ) / 5 * 70 + 70) 161 | } 162 | } 163 | 164 | struct EmojiMemoryThemeEditor_Previews: PreviewProvider { 165 | static var previews: some View { 166 | EmojiMemoryThemeEditor(theme: .template) 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /Memorize/EmojiMemoryThemeStore.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EmojiMemoryThemeStore.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 16.06.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Combine 11 | 12 | class EmojiMemoryThemeStore: ObservableObject { 13 | 14 | private var autosave: AnyCancellable? 15 | @Published var themes: [EmojiMemoryTheme] 16 | 17 | init() { 18 | let defaultsKey = "EmojiMemoryThemeStore" 19 | themes = (UserDefaults.standard.object(forKey: defaultsKey) as? [Data])? 20 | .compactMap({ EmojiMemoryTheme(json: $0) }) ?? EmojiMemoryTheme.themes 21 | autosave = $themes.sink { themes in 22 | UserDefaults.standard.set(themes.map{$0.json}, forKey: defaultsKey) 23 | } 24 | } 25 | 26 | // MARK: - Intents 27 | func updateTheme(for theme: EmojiMemoryTheme, name: String, emoji: [String], colorRGB: UIColor.RGB, numberOfPairs: Int) { 28 | let newTheme = EmojiMemoryTheme(name: name, emoji: emoji, colorRGB: colorRGB, numberOfPairs: numberOfPairs) 29 | if let index = themes.firstIndex(matching: theme) { 30 | themes[index] = newTheme 31 | } 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Memorize/Grid.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Grid.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 26.05.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct Grid: View where ID: Hashable, ItemView: View { 12 | private var items: [Item] 13 | private var id: KeyPath 14 | private var viewForItem: (Item) -> ItemView 15 | 16 | init(_ items: [Item], id: KeyPath, viewForItem: @escaping (Item) -> ItemView) { 17 | self.items = items 18 | self.id = id 19 | self.viewForItem = viewForItem 20 | } 21 | 22 | var body: some View { 23 | GeometryReader { proxy in 24 | self.body(for: GridLayout(itemCount: self.items.count, in: proxy.size)) 25 | } 26 | } 27 | 28 | private func body(for layout: GridLayout) -> some View{ 29 | ForEach(items, id: id) { item in 30 | self.body(for: item, in: layout) 31 | } 32 | } 33 | 34 | private func body(for item: Item, in layout: GridLayout) -> some View { 35 | let index = items.firstIndex(where: { item[keyPath: id] == $0[keyPath: id] })! 36 | return viewForItem(item) 37 | .frame(width: layout.itemSize.width, height: layout.itemSize.height) 38 | .position(layout.location(ofItemAt: index)) 39 | } 40 | } 41 | 42 | extension Grid where Item: Identifiable, ID == Item.ID { 43 | init(_ items: [Item], viewForItems: @escaping (Item) -> ItemView) { 44 | self.init(items, id: \Item.id, viewForItem: viewForItems) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Memorize/GridLayout.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GridLayout.swift 3 | // Memorize 4 | // 5 | // Created by CS193p Instructor. 6 | // Copyright © 2020 Stanford University. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct GridLayout { 12 | private(set) var size: CGSize 13 | private(set) var rowCount: Int = 0 14 | private(set) var columnCount: Int = 0 15 | 16 | init(itemCount: Int, nearAspectRatio desiredAspectRatio: Double = 1, in size: CGSize) { 17 | self.size = size 18 | // if our size is zero width or height or the itemCount is not > 0 19 | // then we have no work to do (because our rowCount & columnCount will be zero) 20 | guard size.width != 0, size.height != 0, itemCount > 0 else { return } 21 | // find the bestLayout 22 | // i.e., one which results in cells whose aspectRatio 23 | // has the smallestVariance from desiredAspectRatio 24 | // not necessarily most optimal code to do this, but easy to follow (hopefully) 25 | var bestLayout: (rowCount: Int, columnCount: Int) = (1, itemCount) 26 | var smallestVariance: Double? 27 | let sizeAspectRatio = abs(Double(size.width/size.height)) 28 | for rows in 1...itemCount { 29 | let columns = (itemCount / rows) + (itemCount % rows > 0 ? 1 : 0) 30 | if (rows - 1) * columns < itemCount { 31 | let itemAspectRatio = sizeAspectRatio * (Double(rows)/Double(columns)) 32 | let variance = abs(itemAspectRatio - desiredAspectRatio) 33 | if smallestVariance == nil || variance < smallestVariance! { 34 | smallestVariance = variance 35 | bestLayout = (rowCount: rows, columnCount: columns) 36 | } 37 | } 38 | } 39 | rowCount = bestLayout.rowCount 40 | columnCount = bestLayout.columnCount 41 | } 42 | 43 | var itemSize: CGSize { 44 | if rowCount == 0 || columnCount == 0 { 45 | return CGSize.zero 46 | } else { 47 | return CGSize( 48 | width: size.width / CGFloat(columnCount), 49 | height: size.height / CGFloat(rowCount) 50 | ) 51 | } 52 | } 53 | 54 | func location(ofItemAt index: Int) -> CGPoint { 55 | if rowCount == 0 || columnCount == 0 { 56 | return CGPoint.zero 57 | } else { 58 | return CGPoint( 59 | x: (CGFloat(index % columnCount) + 0.5) * itemSize.width, 60 | y: (CGFloat(index / columnCount) + 0.5) * itemSize.height 61 | ) 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Memorize/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | 37 | 38 | 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UISupportedInterfaceOrientations~ipad 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationPortraitUpsideDown 56 | UIInterfaceOrientationLandscapeLeft 57 | UIInterfaceOrientationLandscapeRight 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Memorize/MemorizeExtensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MemorizeExtensions.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 10.06.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import SwiftUI 11 | 12 | extension Array where Element: Identifiable { 13 | // find the index of the first element matching the ID of the given item 14 | func firstIndex(matching item: Element) -> Int? { 15 | if let index = self.firstIndex(where: {item.id == $0.id}) { 16 | return index 17 | } 18 | return nil 19 | } 20 | } 21 | 22 | extension Array { 23 | // return the one and only element or nil 24 | var only: Element? { 25 | count == 1 ? first : nil 26 | } 27 | } 28 | 29 | extension Data { 30 | // just a simple converter from a Data to a String 31 | var utf8: String? { String(data: self, encoding: .utf8 ) } 32 | } 33 | 34 | extension Color { 35 | // Construct a Color 36 | init(_ rgb: UIColor.RGB) { 37 | self.init(UIColor(rgb)) 38 | } 39 | } 40 | 41 | extension UIColor { 42 | // Codable struct to store the RGBA color values 43 | public struct RGB: Hashable, Codable { 44 | var red: CGFloat 45 | var green: CGFloat 46 | var blue: CGFloat 47 | var alpha: CGFloat 48 | } 49 | 50 | // Initializer to create a UIColor based on the struct 51 | convenience init(_ rgb: RGB) { 52 | self.init(red: rgb.red, green: rgb.green, blue: rgb.blue, alpha: rgb.alpha) 53 | } 54 | 55 | // computed variable returning the RGBA structure representing the current color 56 | public var rgb: RGB { 57 | var red: CGFloat = 0 58 | var green: CGFloat = 0 59 | var blue: CGFloat = 0 60 | var alpha: CGFloat = 0 61 | 62 | getRed(&red, green: &green, blue: &blue, alpha: &alpha) 63 | return RGB(red: red, green: green, blue: blue, alpha: alpha) 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Memorize/MemoryGame.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MemoryGame.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 20.05.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct MemoryGame where CardContent: Equatable { 12 | private(set) var cards: [Card] 13 | private(set) var score = 0 14 | private var seenCards = [Card]() 15 | private var firstCardTimestamp : TimeInterval = 0 16 | 17 | private var indexOfTheOneAndOnlyFaceUpCard: Int? { 18 | get { 19 | cards.indices.filter { cards[$0].isFaceUp }.only 20 | } 21 | set { 22 | for index in cards.indices { 23 | if cards[index].isFaceUp { 24 | seenCards.append(cards[index]) 25 | } 26 | cards[index].isFaceUp = index == newValue 27 | } 28 | } 29 | } 30 | 31 | mutating func choose(card: Card) { 32 | if let chosenIndex = cards.firstIndex(matching: card), !cards[chosenIndex].isMatched { 33 | if let potentialMatchIndex = indexOfTheOneAndOnlyFaceUpCard, potentialMatchIndex != chosenIndex { 34 | if cards[chosenIndex].content == cards[potentialMatchIndex].content { 35 | cards[chosenIndex].isMatched = true 36 | cards[potentialMatchIndex].isMatched = true 37 | 38 | let currentCardTimestamp = Date().timeIntervalSinceReferenceDate 39 | let multiplier = max(5 - (currentCardTimestamp - firstCardTimestamp), 1) 40 | score += Int(2 * multiplier) 41 | } 42 | else { 43 | score += seenCards.firstIndex(matching: cards[potentialMatchIndex]) != nil ? -1 : 0 44 | score += seenCards.firstIndex(matching: cards[chosenIndex]) != nil ? -1 : 0 45 | } 46 | cards[chosenIndex].isFaceUp = true 47 | } 48 | else { 49 | indexOfTheOneAndOnlyFaceUpCard = chosenIndex 50 | firstCardTimestamp = Date().timeIntervalSinceReferenceDate 51 | } 52 | } 53 | } 54 | 55 | init(numberOfPairsOfCards: Int, cardContentFactory: (Int) -> CardContent) { 56 | cards = [] 57 | for pairIndex in 0.. 0 && bonusTimeRemaining > 0) ? bonusTimeRemaining/bonusTimeLimit : 0 118 | } 119 | // whether the card was matched during the bonus time period 120 | var hasEarnedBonus: Bool { 121 | isMatched && bonusTimeRemaining > 0 122 | } 123 | // whether we are currently face up, unmatched and have not yet used up the bonus window 124 | var isConsumingBonusTime: Bool { 125 | isFaceUp && !isMatched && bonusTimeRemaining > 0 126 | } 127 | 128 | // called when the card transitions to face up state 129 | private mutating func startUsingBonusTime() { 130 | if isConsumingBonusTime, lastFaceUpDate == nil { 131 | lastFaceUpDate = Date() 132 | } 133 | } 134 | 135 | // called when the card goes back face down (or gets matched) 136 | private mutating func stopUsingBonusTime() { 137 | pastFaceUpTime = faceUpTime 138 | self.lastFaceUpDate = nil 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /Memorize/Pie.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Pie.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 02.06.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct Pie: Shape { 12 | var startAngle: Angle 13 | var endAngle: Angle 14 | var clockwise: Bool = false 15 | 16 | var animatableData: AnimatablePair { 17 | get { 18 | AnimatablePair(startAngle.radians, endAngle.radians) 19 | } 20 | 21 | set { 22 | startAngle = Angle.radians(newValue.first) 23 | endAngle = Angle.radians(newValue.second) 24 | } 25 | } 26 | 27 | func path(in rect: CGRect) -> Path { 28 | let center = CGPoint(x: rect.midX, y: rect.midY) 29 | let radius = min(rect.width, rect.height) / 2 30 | let start = CGPoint( 31 | x: center.x + radius * cos(CGFloat(startAngle.radians)), 32 | y: center.y + radius * sin(CGFloat(startAngle.radians)) 33 | ) 34 | 35 | var p = Path() 36 | p.move(to: center) 37 | p.addLine(to: start) 38 | p.addArc(center: center, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: clockwise) 39 | p.addLine(to: center) 40 | 41 | return p 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Memorize/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Memorize/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // Memorize 4 | // 5 | // Created by Philipp on 19.05.20. 6 | // Copyright © 2020 Philipp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SwiftUI 11 | 12 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 18 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 19 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 20 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 21 | 22 | // Create the SwiftUI view that provides the window contents. 23 | let contentView = EmojiMemoryThemeChooser() 24 | .environmentObject(EmojiMemoryThemeStore()) 25 | 26 | // Use a UIHostingController as window root view controller. 27 | if let windowScene = scene as? UIWindowScene { 28 | let window = UIWindow(windowScene: windowScene) 29 | window.rootViewController = UIHostingController(rootView: contentView) 30 | self.window = window 31 | window.makeKeyAndVisible() 32 | } 33 | } 34 | 35 | func sceneDidDisconnect(_ scene: UIScene) { 36 | // Called as the scene is being released by the system. 37 | // This occurs shortly after the scene enters the background, or when its session is discarded. 38 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 39 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 40 | } 41 | 42 | func sceneDidBecomeActive(_ scene: UIScene) { 43 | // Called when the scene has moved from an inactive state to an active state. 44 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 45 | } 46 | 47 | func sceneWillResignActive(_ scene: UIScene) { 48 | // Called when the scene will move from an active state to an inactive state. 49 | // This may occur due to temporary interruptions (ex. an incoming phone call). 50 | } 51 | 52 | func sceneWillEnterForeground(_ scene: UIScene) { 53 | // Called as the scene transitions from the background to the foreground. 54 | // Use this method to undo the changes made on entering the background. 55 | } 56 | 57 | func sceneDidEnterBackground(_ scene: UIScene) { 58 | // Called as the scene transitions from the foreground to the background. 59 | // Use this method to save data, release shared resources, and store enough scene-specific state information 60 | // to restore the scene back to its current state. 61 | } 62 | 63 | 64 | } 65 | 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Memorize 2 | 3 | A small game written using SwiftUI, based on the [Stanford University's course CS193p](https://cs193p.sites.stanford.edu) (Developing Applications for iOS using SwiftUI) of Spring 2020. 4 | 5 | Currently (Spring 2021) a reimplementation based on the latest course (SwiftUI, iOS 14) is ongoing and can be found on the [`main-2021-spring` branch](../../tree/main-2021-spring). 6 | 7 | ![Screen capture](Screencapture.gif) 8 | -------------------------------------------------------------------------------- /Screencapture.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pd95/CS193p-Memorize/9b842bf7e6dbf5220fd1446a699a5f6c57c84f31/Screencapture.gif --------------------------------------------------------------------------------