From 269f00633d7031f64f4f667095757851ef8b6462 Mon Sep 17 00:00:00 2001 From: Denis Cedeno Date: Fri, 28 Aug 2020 00:10:12 -0400 Subject: [PATCH 1/2] Initial Commit, Game of life logic and animation working adding features soon --- ConwaysGameOfLife.xcodeproj/project.pbxproj | 375 ++++++++++++++++++ ConwaysGameOfLife/AppDelegate.swift | 37 ++ .../AppIcon.appiconset/Contents.json | 98 +++++ .../Assets.xcassets/Contents.json | 6 + .../Base.lproj/LaunchScreen.storyboard | 25 ++ ConwaysGameOfLife/Info.plist | 64 +++ ConwaysGameOfLife/Models/Cell.swift | 34 ++ ConwaysGameOfLife/Models/CellState.swift | 22 + ConwaysGameOfLife/Models/Life.swift | 49 +++ ConwaysGameOfLife/SceneDelegate.swift | 53 +++ .../Views/Base.lproj/Main.storyboard | 41 ++ ConwaysGameOfLife/Views/GameBoard.swift | 52 +++ ConwaysGameOfLife/Views/ViewController.swift | 79 ++++ 13 files changed, 935 insertions(+) create mode 100644 ConwaysGameOfLife.xcodeproj/project.pbxproj create mode 100644 ConwaysGameOfLife/AppDelegate.swift create mode 100644 ConwaysGameOfLife/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 ConwaysGameOfLife/Assets.xcassets/Contents.json create mode 100644 ConwaysGameOfLife/Base.lproj/LaunchScreen.storyboard create mode 100644 ConwaysGameOfLife/Info.plist create mode 100644 ConwaysGameOfLife/Models/Cell.swift create mode 100644 ConwaysGameOfLife/Models/CellState.swift create mode 100644 ConwaysGameOfLife/Models/Life.swift create mode 100644 ConwaysGameOfLife/SceneDelegate.swift create mode 100644 ConwaysGameOfLife/Views/Base.lproj/Main.storyboard create mode 100644 ConwaysGameOfLife/Views/GameBoard.swift create mode 100644 ConwaysGameOfLife/Views/ViewController.swift diff --git a/ConwaysGameOfLife.xcodeproj/project.pbxproj b/ConwaysGameOfLife.xcodeproj/project.pbxproj new file mode 100644 index 000000000..b995cdf7a --- /dev/null +++ b/ConwaysGameOfLife.xcodeproj/project.pbxproj @@ -0,0 +1,375 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 125CB1D824F408FA000112A0 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125CB1D724F408FA000112A0 /* AppDelegate.swift */; }; + 125CB1DA24F408FA000112A0 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125CB1D924F408FA000112A0 /* SceneDelegate.swift */; }; + 125CB1DC24F408FA000112A0 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125CB1DB24F408FA000112A0 /* ViewController.swift */; }; + 125CB1DF24F408FA000112A0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 125CB1DD24F408FA000112A0 /* Main.storyboard */; }; + 125CB1E124F408FF000112A0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 125CB1E024F408FF000112A0 /* Assets.xcassets */; }; + 125CB1E424F408FF000112A0 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 125CB1E224F408FF000112A0 /* LaunchScreen.storyboard */; }; + 125CB1EC24F40938000112A0 /* Cell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 125CB1EB24F40938000112A0 /* Cell.swift */; }; + 127E34B824F5C75D00DDDF7E /* CellState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 127E34B724F5C75D00DDDF7E /* CellState.swift */; }; + 127E34BA24F5C7B800DDDF7E /* Life.swift in Sources */ = {isa = PBXBuildFile; fileRef = 127E34B924F5C7B800DDDF7E /* Life.swift */; }; + 127E34BC24F5C8E900DDDF7E /* GameBoard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 127E34BB24F5C8E900DDDF7E /* GameBoard.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 125CB1D424F408FA000112A0 /* ConwaysGameOfLife.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ConwaysGameOfLife.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 125CB1D724F408FA000112A0 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 125CB1D924F408FA000112A0 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 125CB1DB24F408FA000112A0 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 125CB1DE24F408FA000112A0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 125CB1E024F408FF000112A0 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 125CB1E324F408FF000112A0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 125CB1E524F408FF000112A0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 125CB1EB24F40938000112A0 /* Cell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Cell.swift; sourceTree = ""; }; + 127E34B724F5C75D00DDDF7E /* CellState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellState.swift; sourceTree = ""; }; + 127E34B924F5C7B800DDDF7E /* Life.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Life.swift; sourceTree = ""; }; + 127E34BB24F5C8E900DDDF7E /* GameBoard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameBoard.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 125CB1D124F408FA000112A0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 125CB1CB24F408FA000112A0 = { + isa = PBXGroup; + children = ( + 125CB1D624F408FA000112A0 /* ConwaysGameOfLife */, + 125CB1D524F408FA000112A0 /* Products */, + ); + sourceTree = ""; + }; + 125CB1D524F408FA000112A0 /* Products */ = { + isa = PBXGroup; + children = ( + 125CB1D424F408FA000112A0 /* ConwaysGameOfLife.app */, + ); + name = Products; + sourceTree = ""; + }; + 125CB1D624F408FA000112A0 /* ConwaysGameOfLife */ = { + isa = PBXGroup; + children = ( + 125CB1D724F408FA000112A0 /* AppDelegate.swift */, + 125CB1D924F408FA000112A0 /* SceneDelegate.swift */, + 127E34BD24F5D73000DDDF7E /* Views */, + 127E34B624F5C3F300DDDF7E /* Models */, + 125CB1E024F408FF000112A0 /* Assets.xcassets */, + 125CB1E224F408FF000112A0 /* LaunchScreen.storyboard */, + 125CB1E524F408FF000112A0 /* Info.plist */, + ); + path = ConwaysGameOfLife; + sourceTree = ""; + }; + 127E34B624F5C3F300DDDF7E /* Models */ = { + isa = PBXGroup; + children = ( + 125CB1EB24F40938000112A0 /* Cell.swift */, + 127E34B724F5C75D00DDDF7E /* CellState.swift */, + 127E34B924F5C7B800DDDF7E /* Life.swift */, + ); + path = Models; + sourceTree = ""; + }; + 127E34BD24F5D73000DDDF7E /* Views */ = { + isa = PBXGroup; + children = ( + 125CB1DD24F408FA000112A0 /* Main.storyboard */, + 127E34BB24F5C8E900DDDF7E /* GameBoard.swift */, + 125CB1DB24F408FA000112A0 /* ViewController.swift */, + ); + path = Views; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 125CB1D324F408FA000112A0 /* ConwaysGameOfLife */ = { + isa = PBXNativeTarget; + buildConfigurationList = 125CB1E824F408FF000112A0 /* Build configuration list for PBXNativeTarget "ConwaysGameOfLife" */; + buildPhases = ( + 125CB1D024F408FA000112A0 /* Sources */, + 125CB1D124F408FA000112A0 /* Frameworks */, + 125CB1D224F408FA000112A0 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ConwaysGameOfLife; + productName = ConwaysGameOfLife; + productReference = 125CB1D424F408FA000112A0 /* ConwaysGameOfLife.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 125CB1CC24F408FA000112A0 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1140; + LastUpgradeCheck = 1140; + ORGANIZATIONNAME = denisco; + TargetAttributes = { + 125CB1D324F408FA000112A0 = { + CreatedOnToolsVersion = 11.4.1; + }; + }; + }; + buildConfigurationList = 125CB1CF24F408FA000112A0 /* Build configuration list for PBXProject "ConwaysGameOfLife" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 125CB1CB24F408FA000112A0; + productRefGroup = 125CB1D524F408FA000112A0 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 125CB1D324F408FA000112A0 /* ConwaysGameOfLife */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 125CB1D224F408FA000112A0 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 125CB1E424F408FF000112A0 /* LaunchScreen.storyboard in Resources */, + 125CB1E124F408FF000112A0 /* Assets.xcassets in Resources */, + 125CB1DF24F408FA000112A0 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 125CB1D024F408FA000112A0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 125CB1DC24F408FA000112A0 /* ViewController.swift in Sources */, + 127E34B824F5C75D00DDDF7E /* CellState.swift in Sources */, + 125CB1EC24F40938000112A0 /* Cell.swift in Sources */, + 127E34BC24F5C8E900DDDF7E /* GameBoard.swift in Sources */, + 125CB1D824F408FA000112A0 /* AppDelegate.swift in Sources */, + 125CB1DA24F408FA000112A0 /* SceneDelegate.swift in Sources */, + 127E34BA24F5C7B800DDDF7E /* Life.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 125CB1DD24F408FA000112A0 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 125CB1DE24F408FA000112A0 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 125CB1E224F408FF000112A0 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 125CB1E324F408FF000112A0 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 125CB1E624F408FF000112A0 /* 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.4; + 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; + }; + 125CB1E724F408FF000112A0 /* 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.4; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 125CB1E924F408FF000112A0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = WDB2NWAVF2; + INFOPLIST_FILE = ConwaysGameOfLife/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.denis.ConwaysGameOfLife; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 125CB1EA24F408FF000112A0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = WDB2NWAVF2; + INFOPLIST_FILE = ConwaysGameOfLife/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.denis.ConwaysGameOfLife; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 125CB1CF24F408FA000112A0 /* Build configuration list for PBXProject "ConwaysGameOfLife" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 125CB1E624F408FF000112A0 /* Debug */, + 125CB1E724F408FF000112A0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 125CB1E824F408FF000112A0 /* Build configuration list for PBXNativeTarget "ConwaysGameOfLife" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 125CB1E924F408FF000112A0 /* Debug */, + 125CB1EA24F408FF000112A0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 125CB1CC24F408FA000112A0 /* Project object */; +} diff --git a/ConwaysGameOfLife/AppDelegate.swift b/ConwaysGameOfLife/AppDelegate.swift new file mode 100644 index 000000000..cde295fa9 --- /dev/null +++ b/ConwaysGameOfLife/AppDelegate.swift @@ -0,0 +1,37 @@ +// +// AppDelegate.swift +// ConwaysGameOfLife +// +// Created by denis cedeno on 8/24/20. +// Copyright © 2020 denisco. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + // MARK: UISceneSession Lifecycle + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } + + func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. + } + + +} + diff --git a/ConwaysGameOfLife/Assets.xcassets/AppIcon.appiconset/Contents.json b/ConwaysGameOfLife/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..9221b9bb1 --- /dev/null +++ b/ConwaysGameOfLife/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ConwaysGameOfLife/Assets.xcassets/Contents.json b/ConwaysGameOfLife/Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/ConwaysGameOfLife/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/ConwaysGameOfLife/Base.lproj/LaunchScreen.storyboard b/ConwaysGameOfLife/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 000000000..865e9329f --- /dev/null +++ b/ConwaysGameOfLife/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ConwaysGameOfLife/Info.plist b/ConwaysGameOfLife/Info.plist new file mode 100644 index 000000000..2a3483c0d --- /dev/null +++ b/ConwaysGameOfLife/Info.plist @@ -0,0 +1,64 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/ConwaysGameOfLife/Models/Cell.swift b/ConwaysGameOfLife/Models/Cell.swift new file mode 100644 index 000000000..9bb258b23 --- /dev/null +++ b/ConwaysGameOfLife/Models/Cell.swift @@ -0,0 +1,34 @@ +// +// cell.swift +// ConwaysGameOfLife +// +// Created by denis cedeno on 8/24/20. +// Copyright © 2020 denisco. All rights reserved. +// + +import Foundation + +class Cell { + let x: Int + let y: Int + var cellState: CellState + + init(x: Int, y: Int, cellState: CellState) { + self.x = x + self.y = y + self.cellState = cellState + } + + public func isNeighbor(to cell: Cell) -> Bool { + + let xDelta = abs(self.x - cell.x) + let yDelta = abs(self.y - cell.y) + + switch (xDelta, yDelta) { + case (1, 1), (0, 1), (1, 0): + return true + default: + return false + } + } +} diff --git a/ConwaysGameOfLife/Models/CellState.swift b/ConwaysGameOfLife/Models/CellState.swift new file mode 100644 index 000000000..43394c736 --- /dev/null +++ b/ConwaysGameOfLife/Models/CellState.swift @@ -0,0 +1,22 @@ +// +// CellState.swift +// ConwaysGameOfLife +// +// Created by denis cedeno on 8/25/20. +// Copyright © 2020 denisco. All rights reserved. +// + +import Foundation + +enum CellState: Int { + case Living, Dead + + static func randomState() -> CellState { + guard let cellState = CellState(rawValue: Int(arc4random_uniform(3))) else { + return .Dead + } + return cellState + } + + +} diff --git a/ConwaysGameOfLife/Models/Life.swift b/ConwaysGameOfLife/Models/Life.swift new file mode 100644 index 000000000..479a316af --- /dev/null +++ b/ConwaysGameOfLife/Models/Life.swift @@ -0,0 +1,49 @@ +// +// Life.swift +// ConwaysGameOfLife +// +// Created by denis cedeno on 8/25/20. +// Copyright © 2020 denisco. All rights reserved. +// + +import Foundation + +class Life { + var cells: [Cell] + let gridSize: Int = 48 + + + init() { + cells = [Cell]() + for xLoc in 0.. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ConwaysGameOfLife/Views/GameBoard.swift b/ConwaysGameOfLife/Views/GameBoard.swift new file mode 100644 index 000000000..e0d201051 --- /dev/null +++ b/ConwaysGameOfLife/Views/GameBoard.swift @@ -0,0 +1,52 @@ +// +// GameBoard.swift +// ConwaysGameOfLife +// +// Created by denis cedeno on 8/25/20. +// Copyright © 2020 denisco. All rights reserved. +// + +import UIKit + +class GameBoard: UIView { + + let life: Life + + init(createLife: Life) { + life = createLife + super.init(frame: CGRect(x: 0,y: 0,width: 0,height: 0)) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + + override func draw(_ rect: CGRect) { + let currentContext = UIGraphicsGetCurrentContext() + + for cell in life.cells { + currentContext!.setFillColor(colorForCell(cellState: cell.cellState).cgColor) + currentContext!.addRect(frameForCell(cell: cell)) + currentContext!.fillPath() + } + } + + + func colorForCell(cellState: CellState) -> UIColor { + switch cellState { + case .Living: + return UIColor(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0) + case .Dead: + return UIColor(red: 255/255, green: 255.255, blue: 255/255, alpha: 1.0) + } + } + + func frameForCell(cell: Cell) -> CGRect { + let dimensions = CGFloat(self.life.gridSize) + let cellSize = CGSize(width: self.bounds.width/dimensions, height: self.bounds.height/dimensions) + return CGRect(x: CGFloat(cell.x) * cellSize.width, y: CGFloat(cell.y) * cellSize.height, width: cellSize.width, height: cellSize.height) + } + + +} diff --git a/ConwaysGameOfLife/Views/ViewController.swift b/ConwaysGameOfLife/Views/ViewController.swift new file mode 100644 index 000000000..6fcced020 --- /dev/null +++ b/ConwaysGameOfLife/Views/ViewController.swift @@ -0,0 +1,79 @@ +// +// ViewController.swift +// ConwaysGameOfLife +// +// Created by denis cedeno on 8/24/20. +// Copyright © 2020 denisco. All rights reserved. +// + +import UIKit + +class ViewController: UIViewController { + + @IBOutlet weak var boardView: UIView! + @IBOutlet var genLabel: UILabel! + private var testbutton:UIButton = UIButton() + + var life = Life() + let gameBoard: GameBoard + var genCount = 1 + var runAnimation = true + + required init?(coder aDecoder: NSCoder) { + gameBoard = GameBoard(createLife: life) + + super.init(coder: aDecoder ) + } + + override func viewDidLoad() { + super.viewDidLoad() + gameBoard.frame = boardView.frame + gameBoard.center = CGPoint(x: gameBoard.frame.size.width/2, y: gameBoard.frame.size.height/2) + boardView.addSubview(gameBoard) + + let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21)) + label.center = CGPoint(x: 80, y: 105) + label.textAlignment = NSTextAlignment.center + label.text = "Generations" + self.view.addSubview(label) + + self.genLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21)) + self.genLabel.center = CGPoint(x: 300, y: 105) + self.genLabel.textAlignment = NSTextAlignment.center + self.genLabel.text = "\(self.genCount)" + self.view.addSubview(genLabel) + + let testButton = UIButton(type: UIButton.ButtonType.system) as UIButton + testButton.frame = CGRect(x: 40, y: 560, width: 80, height: 20) + testButton.backgroundColor = UIColor.white + testButton.setTitle("Stop", for: UIControl.State.normal) + testButton.addTarget(self, action:#selector(self.testButtonClicked), for: .touchUpInside) + self.view.addSubview(testButton) + + animate() + } + + public func animate() { + if !runAnimation {return} + DispatchQueue.main.asyncAfter(deadline: .now()) { + self.life.updateCells() + self.genCount += 1 + self.genLabel.text = "\(self.genCount)" + self.gameBoard.setNeedsDisplay() + self.animate() + } + } + + + @objc func testButtonClicked(sender:UIButton){ + if runAnimation == true { + runAnimation = false + } else if runAnimation == false { + runAnimation = true + animate() + } + } + + +} + From a1893f55bb20199c7737474ac698c6cf0f91e609 Mon Sep 17 00:00:00 2001 From: Denis Cedeno Date: Mon, 31 Aug 2020 14:57:33 -0400 Subject: [PATCH 2/2] some UI adjustments --- ConwaysGameOfLife/Views/ViewController.swift | 32 ++++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/ConwaysGameOfLife/Views/ViewController.swift b/ConwaysGameOfLife/Views/ViewController.swift index 6fcced020..3e889ae82 100644 --- a/ConwaysGameOfLife/Views/ViewController.swift +++ b/ConwaysGameOfLife/Views/ViewController.swift @@ -12,12 +12,14 @@ class ViewController: UIViewController { @IBOutlet weak var boardView: UIView! @IBOutlet var genLabel: UILabel! - private var testbutton:UIButton = UIButton() + private var playButton:UIButton = UIButton() + + @IBOutlet weak var infoButton: UIBarButtonItem! var life = Life() let gameBoard: GameBoard var genCount = 1 - var runAnimation = true + var runAnimation = false required init?(coder aDecoder: NSCoder) { gameBoard = GameBoard(createLife: life) @@ -30,31 +32,39 @@ class ViewController: UIViewController { gameBoard.frame = boardView.frame gameBoard.center = CGPoint(x: gameBoard.frame.size.width/2, y: gameBoard.frame.size.height/2) boardView.addSubview(gameBoard) + + let titlelabel = UILabel(frame: CGRect(x: 0, y: 0, width: 400, height: 30)) + titlelabel.center = CGPoint(x: 155, y: 80) + titlelabel.textAlignment = NSTextAlignment.center + titlelabel.font = UIFont.boldSystemFont(ofSize: 24) + titlelabel.text = "Conway's Game of life" + self.view.addSubview(titlelabel) let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21)) - label.center = CGPoint(x: 80, y: 105) + label.center = CGPoint(x: 80, y: 128) label.textAlignment = NSTextAlignment.center label.text = "Generations" self.view.addSubview(label) self.genLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21)) - self.genLabel.center = CGPoint(x: 300, y: 105) + self.genLabel.center = CGPoint(x: 160, y: 128) self.genLabel.textAlignment = NSTextAlignment.center self.genLabel.text = "\(self.genCount)" self.view.addSubview(genLabel) - let testButton = UIButton(type: UIButton.ButtonType.system) as UIButton - testButton.frame = CGRect(x: 40, y: 560, width: 80, height: 20) - testButton.backgroundColor = UIColor.white - testButton.setTitle("Stop", for: UIControl.State.normal) - testButton.addTarget(self, action:#selector(self.testButtonClicked), for: .touchUpInside) - self.view.addSubview(testButton) + playButton.frame = CGRect(x: 20, y: 560, width: 100, height: 100) + playButton.setImage(UIImage(systemName: "play.rectangle.fill"), for: .normal) + playButton.setPreferredSymbolConfiguration( .init(scale: .large), forImageIn: .normal) + playButton.tintColor = .black + playButton.addTarget(self, action:#selector(self.testButtonClicked), for: .touchUpInside) + self.view.addSubview(playButton) animate() } public func animate() { if !runAnimation {return} + playButton.setImage(UIImage(systemName: "pause.rectangle.fill"), for: .normal) DispatchQueue.main.asyncAfter(deadline: .now()) { self.life.updateCells() self.genCount += 1 @@ -67,8 +77,10 @@ class ViewController: UIViewController { @objc func testButtonClicked(sender:UIButton){ if runAnimation == true { + playButton.setImage(UIImage(systemName: "play.rectangle.fill"), for: .normal) runAnimation = false } else if runAnimation == false { + playButton.setImage(UIImage(systemName: "pause.rectangle.fill"), for: .normal) runAnimation = true animate() }