diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..221edc8 Binary files /dev/null and b/.DS_Store differ diff --git a/lesson06/.DS_Store b/lesson06/.DS_Store index 9503165..c07ddfc 100644 Binary files a/lesson06/.DS_Store and b/lesson06/.DS_Store differ diff --git a/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate index 75f6125..b56272f 100644 Binary files a/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate and b/lesson06/6L_RaskinSergey/6L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/lesson07/.DS_Store b/lesson07/.DS_Store new file mode 100644 index 0000000..6f20cb1 Binary files /dev/null and b/lesson07/.DS_Store differ diff --git a/lesson07/7L_RaskinSergey/.DS_Store b/lesson07/7L_RaskinSergey/.DS_Store new file mode 100644 index 0000000..c9ebb83 Binary files /dev/null and b/lesson07/7L_RaskinSergey/.DS_Store differ diff --git a/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/project.pbxproj b/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/project.pbxproj new file mode 100644 index 0000000..527155b --- /dev/null +++ b/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/project.pbxproj @@ -0,0 +1,289 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 914E8AC7239E3C400020FFD0 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 914E8AC6239E3C400020FFD0 /* main.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 914E8AC1239E3C400020FFD0 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 914E8AC3239E3C400020FFD0 /* 7L_RaskinSergey */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = 7L_RaskinSergey; sourceTree = BUILT_PRODUCTS_DIR; }; + 914E8AC6239E3C400020FFD0 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 914E8AC0239E3C400020FFD0 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 914E8ABA239E3C400020FFD0 = { + isa = PBXGroup; + children = ( + 914E8AC5239E3C400020FFD0 /* 7L_RaskinSergey */, + 914E8AC4239E3C400020FFD0 /* Products */, + ); + sourceTree = ""; + }; + 914E8AC4239E3C400020FFD0 /* Products */ = { + isa = PBXGroup; + children = ( + 914E8AC3239E3C400020FFD0 /* 7L_RaskinSergey */, + ); + name = Products; + sourceTree = ""; + }; + 914E8AC5239E3C400020FFD0 /* 7L_RaskinSergey */ = { + isa = PBXGroup; + children = ( + 914E8AC6239E3C400020FFD0 /* main.swift */, + ); + path = 7L_RaskinSergey; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 914E8AC2239E3C400020FFD0 /* 7L_RaskinSergey */ = { + isa = PBXNativeTarget; + buildConfigurationList = 914E8ACA239E3C400020FFD0 /* Build configuration list for PBXNativeTarget "7L_RaskinSergey" */; + buildPhases = ( + 914E8ABF239E3C400020FFD0 /* Sources */, + 914E8AC0239E3C400020FFD0 /* Frameworks */, + 914E8AC1239E3C400020FFD0 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = 7L_RaskinSergey; + productName = 7L_RaskinSergey; + productReference = 914E8AC3239E3C400020FFD0 /* 7L_RaskinSergey */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 914E8ABB239E3C400020FFD0 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1120; + LastUpgradeCheck = 1120; + ORGANIZATIONNAME = "raskin-sa"; + TargetAttributes = { + 914E8AC2239E3C400020FFD0 = { + CreatedOnToolsVersion = 11.2.1; + }; + }; + }; + buildConfigurationList = 914E8ABE239E3C400020FFD0 /* Build configuration list for PBXProject "7L_RaskinSergey" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 914E8ABA239E3C400020FFD0; + productRefGroup = 914E8AC4239E3C400020FFD0 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 914E8AC2239E3C400020FFD0 /* 7L_RaskinSergey */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 914E8ABF239E3C400020FFD0 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 914E8AC7239E3C400020FFD0 /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 914E8AC8239E3C400020FFD0 /* 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; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 914E8AC9239E3C400020FFD0 /* 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; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 914E8ACB239E3C400020FFD0 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 5C3KKHP5ML; + ENABLE_HARDENED_RUNTIME = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 914E8ACC239E3C400020FFD0 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 5C3KKHP5ML; + ENABLE_HARDENED_RUNTIME = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 914E8ABE239E3C400020FFD0 /* Build configuration list for PBXProject "7L_RaskinSergey" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 914E8AC8239E3C400020FFD0 /* Debug */, + 914E8AC9239E3C400020FFD0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 914E8ACA239E3C400020FFD0 /* Build configuration list for PBXNativeTarget "7L_RaskinSergey" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 914E8ACB239E3C400020FFD0 /* Debug */, + 914E8ACC239E3C400020FFD0 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 914E8ABB239E3C400020FFD0 /* Project object */; +} diff --git a/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..7f9cada --- /dev/null +++ b/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate b/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..23fbf55 Binary files /dev/null and b/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcschemes/xcschememanagement.plist b/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..704dd8b --- /dev/null +++ b/lesson07/7L_RaskinSergey/7L_RaskinSergey.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + 7L_RaskinSergey.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/lesson07/7L_RaskinSergey/7L_RaskinSergey/main.swift b/lesson07/7L_RaskinSergey/7L_RaskinSergey/main.swift new file mode 100644 index 0000000..50b969d --- /dev/null +++ b/lesson07/7L_RaskinSergey/7L_RaskinSergey/main.swift @@ -0,0 +1,78 @@ +// +// main.swift +// 7L_RaskinSergey +// +// Created by raskin-sa on 09/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +enum dealerCenterError: Error { + case invalidSelection (modelRequested:String) + case insufficientAmonut(amountNeeded:Double) + case outOfStock +} + +struct autoItem{ + var price:Double //в миллионах + var count:Int +} + +class dealerCenter{ + var car = [ + "Polo": autoItem(price: 0.9, count: 20), + "Jetta": autoItem(price: 1.2, count: 25), + "Golf": autoItem(price: 2.0, count: 0) + ] + + var amountPaid = 0.0 + + func buyAuto(autoItem name:String) throws{ + guard let autoItem = car[name] else { + throw dealerCenterError.invalidSelection (modelRequested: name) + } + guard autoItem.count > 0 else { + throw dealerCenterError.outOfStock + } + guard autoItem.price <= amountPaid else { + throw dealerCenterError.insufficientAmonut(amountNeeded: autoItem.price - amountPaid) + } + + amountPaid -= autoItem.price + + var newItem = autoItem + newItem.count -= 1 + car[name] = newItem + print("Выдали: \(name)") + + }//func buyAuto throws +}//class dealerCenter + +let favoriteCar = [ + "Ivan":"Golf", + "Katya":"Polo", + "Oleg":"Tiguan", //его нет = ошибка +] + +func byFavoriteCar(person: String, carToBuy: dealerCenter) throws -> String { + let carName = favoriteCar[person] ?? "other" + try carToBuy.buyAuto(autoItem: carName) + return carName //не используется, но как пример синтаксиса +} + +var localDealer = dealerCenter() +localDealer.amountPaid = 2.0 + + +do{ + + try byFavoriteCar(person: "Oleg", carToBuy: localDealer) +}catch dealerCenterError.invalidSelection(let carName) { + //к сожалению внутри catch переменные не умеют использовать значения, полученные в try. Результат можно использовать только вовне do-try-catch + print("ошибка выбора. В салоне нет такой модели \(carName)") +} catch dealerCenterError.outOfStock{ + print("Автомобилей больше нет") +} catch dealerCenterError.insufficientAmonut(let amountNeeded){ + print ("Недостаточно средств. Пожалуйста добавьте еще \(amountNeeded) рублей") +} + + diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/project.pbxproj b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/project.pbxproj new file mode 100644 index 0000000..f383e0a --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/project.pbxproj @@ -0,0 +1,367 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 915D02BB23A223ED0007F011 /* EdgeBody.swift in Sources */ = {isa = PBXBuildFile; fileRef = 915D02BA23A223ED0007F011 /* EdgeBody.swift */; }; + 91CDC15D23A130E20082565D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC15C23A130E20082565D /* AppDelegate.swift */; }; + 91CDC16323A130E20082565D /* GameScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC16223A130E20082565D /* GameScene.swift */; }; + 91CDC16523A130E20082565D /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC16423A130E20082565D /* GameViewController.swift */; }; + 91CDC16823A130E20082565D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 91CDC16623A130E20082565D /* Main.storyboard */; }; + 91CDC16A23A130E30082565D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 91CDC16923A130E30082565D /* Assets.xcassets */; }; + 91CDC16D23A130E30082565D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 91CDC16B23A130E30082565D /* LaunchScreen.storyboard */; }; + 91CDC17523A13A350082565D /* Apple.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC17423A13A350082565D /* Apple.swift */; }; + 91CDC17723A13EFB0082565D /* SnakeBodyPart.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC17623A13EFB0082565D /* SnakeBodyPart.swift */; }; + 91CDC17923A140B10082565D /* SnakeHead.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC17823A140B10082565D /* SnakeHead.swift */; }; + 91CDC17B23A141730082565D /* Snake.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC17A23A141730082565D /* Snake.swift */; }; + 91CDC17F23A221040082565D /* GameMessages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 91CDC17E23A221040082565D /* GameMessages.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 915D02BA23A223ED0007F011 /* EdgeBody.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EdgeBody.swift; sourceTree = ""; }; + 91CDC15923A130E20082565D /* 8L_RaskinSergey_snake.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = 8L_RaskinSergey_snake.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 91CDC15C23A130E20082565D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 91CDC16223A130E20082565D /* GameScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameScene.swift; sourceTree = ""; }; + 91CDC16423A130E20082565D /* GameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewController.swift; sourceTree = ""; }; + 91CDC16723A130E20082565D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 91CDC16923A130E30082565D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 91CDC16C23A130E30082565D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 91CDC16E23A130E30082565D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 91CDC17423A13A350082565D /* Apple.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Apple.swift; sourceTree = ""; }; + 91CDC17623A13EFB0082565D /* SnakeBodyPart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnakeBodyPart.swift; sourceTree = ""; }; + 91CDC17823A140B10082565D /* SnakeHead.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnakeHead.swift; sourceTree = ""; }; + 91CDC17A23A141730082565D /* Snake.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Snake.swift; sourceTree = ""; }; + 91CDC17E23A221040082565D /* GameMessages.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GameMessages.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 91CDC15623A130E20082565D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 91CDC15023A130E20082565D = { + isa = PBXGroup; + children = ( + 91CDC15B23A130E20082565D /* 8L_RaskinSergey_snake */, + 91CDC15A23A130E20082565D /* Products */, + ); + sourceTree = ""; + }; + 91CDC15A23A130E20082565D /* Products */ = { + isa = PBXGroup; + children = ( + 91CDC15923A130E20082565D /* 8L_RaskinSergey_snake.app */, + ); + name = Products; + sourceTree = ""; + }; + 91CDC15B23A130E20082565D /* 8L_RaskinSergey_snake */ = { + isa = PBXGroup; + children = ( + 91CDC17E23A221040082565D /* GameMessages.swift */, + 91CDC15C23A130E20082565D /* AppDelegate.swift */, + 91CDC16223A130E20082565D /* GameScene.swift */, + 91CDC16423A130E20082565D /* GameViewController.swift */, + 91CDC16623A130E20082565D /* Main.storyboard */, + 91CDC16923A130E30082565D /* Assets.xcassets */, + 91CDC16B23A130E30082565D /* LaunchScreen.storyboard */, + 91CDC16E23A130E30082565D /* Info.plist */, + 91CDC17423A13A350082565D /* Apple.swift */, + 91CDC17623A13EFB0082565D /* SnakeBodyPart.swift */, + 91CDC17823A140B10082565D /* SnakeHead.swift */, + 91CDC17A23A141730082565D /* Snake.swift */, + 915D02BA23A223ED0007F011 /* EdgeBody.swift */, + ); + path = 8L_RaskinSergey_snake; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 91CDC15823A130E20082565D /* 8L_RaskinSergey_snake */ = { + isa = PBXNativeTarget; + buildConfigurationList = 91CDC17123A130E30082565D /* Build configuration list for PBXNativeTarget "8L_RaskinSergey_snake" */; + buildPhases = ( + 91CDC15523A130E20082565D /* Sources */, + 91CDC15623A130E20082565D /* Frameworks */, + 91CDC15723A130E20082565D /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = 8L_RaskinSergey_snake; + productName = 8L_RaskinSergey_snake; + productReference = 91CDC15923A130E20082565D /* 8L_RaskinSergey_snake.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 91CDC15123A130E20082565D /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1130; + LastUpgradeCheck = 1130; + ORGANIZATIONNAME = "raskin-sa"; + TargetAttributes = { + 91CDC15823A130E20082565D = { + CreatedOnToolsVersion = 11.3; + }; + }; + }; + buildConfigurationList = 91CDC15423A130E20082565D /* Build configuration list for PBXProject "8L_RaskinSergey_snake" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 91CDC15023A130E20082565D; + productRefGroup = 91CDC15A23A130E20082565D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 91CDC15823A130E20082565D /* 8L_RaskinSergey_snake */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 91CDC15723A130E20082565D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 91CDC16823A130E20082565D /* Main.storyboard in Resources */, + 91CDC16A23A130E30082565D /* Assets.xcassets in Resources */, + 91CDC16D23A130E30082565D /* LaunchScreen.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 91CDC15523A130E20082565D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 91CDC17923A140B10082565D /* SnakeHead.swift in Sources */, + 91CDC17523A13A350082565D /* Apple.swift in Sources */, + 91CDC17F23A221040082565D /* GameMessages.swift in Sources */, + 91CDC16323A130E20082565D /* GameScene.swift in Sources */, + 91CDC16523A130E20082565D /* GameViewController.swift in Sources */, + 91CDC17723A13EFB0082565D /* SnakeBodyPart.swift in Sources */, + 91CDC17B23A141730082565D /* Snake.swift in Sources */, + 91CDC15D23A130E20082565D /* AppDelegate.swift in Sources */, + 915D02BB23A223ED0007F011 /* EdgeBody.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 91CDC16623A130E20082565D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 91CDC16723A130E20082565D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 91CDC16B23A130E30082565D /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 91CDC16C23A130E30082565D /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 91CDC16F23A130E30082565D /* 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.2; + 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; + }; + 91CDC17023A130E30082565D /* 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.2; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 91CDC17223A130E30082565D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 5C3KKHP5ML; + INFOPLIST_FILE = 8L_RaskinSergey_snake/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "home.-L-RaskinSergey-snake"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 91CDC17323A130E30082565D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_TEAM = 5C3KKHP5ML; + INFOPLIST_FILE = 8L_RaskinSergey_snake/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "home.-L-RaskinSergey-snake"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 91CDC15423A130E20082565D /* Build configuration list for PBXProject "8L_RaskinSergey_snake" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 91CDC16F23A130E30082565D /* Debug */, + 91CDC17023A130E30082565D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 91CDC17123A130E30082565D /* Build configuration list for PBXNativeTarget "8L_RaskinSergey_snake" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 91CDC17223A130E30082565D /* Debug */, + 91CDC17323A130E30082565D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 91CDC15123A130E20082565D /* Project object */; +} diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..72e3bfc --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..29a4c03 Binary files /dev/null and b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/project.xcworkspace/xcuserdata/raskin-sa.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcschemes/xcschememanagement.plist b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..fcf4a07 --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake.xcodeproj/xcuserdata/raskin-sa.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + 8L_RaskinSergey_snake.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/AppDelegate.swift b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/AppDelegate.swift new file mode 100644 index 0000000..6fad8c1 --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/AppDelegate.swift @@ -0,0 +1,41 @@ +// +// AppDelegate.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + // Override point for customization after application launch. + return true + } + + func applicationWillResignActive(_ application: UIApplication) { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(_ application: UIApplication) { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + } + + func applicationWillEnterForeground(_ application: UIApplication) { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(_ application: UIApplication) { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + +} + diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Apple.swift b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Apple.swift new file mode 100644 index 0000000..275210d --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Apple.swift @@ -0,0 +1,30 @@ +// +// Apple.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import Foundation +import SpriteKit + +class Apple: SKShapeNode { + convenience init(position: CGPoint) { + self.init() + + path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 10, height:10 )).cgPath + + fillColor = UIColor.red + strokeColor = UIColor.red + lineWidth = 5 + + self.position = position + + // придаем яблоку параметры физического тела + self.physicsBody = SKPhysicsBody(circleOfRadius: 10.0, center: CGPoint(x:5, y:5)) + self.physicsBody?.categoryBitMask = CollisionCategory.Apple + } + +} + diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Assets.xcassets/AppIcon.appiconset/Contents.json b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..d8db8d6 --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Assets.xcassets/Contents.json b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Base.lproj/LaunchScreen.storyboard b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Base.lproj/Main.storyboard b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Base.lproj/Main.storyboard new file mode 100644 index 0000000..2cc971a --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/EdgeBody.swift b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/EdgeBody.swift new file mode 100644 index 0000000..f3179d0 --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/EdgeBody.swift @@ -0,0 +1,37 @@ +// +// EdgeBody.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 12/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import Foundation +import SpriteKit + +class EdgeBody: SKShapeNode{ + + + init(atPoint point: CGPoint){ + super.init() + + // path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: diametr, height: diametr)).cgPath + path = UIBezierPath(rect: CGRect(x: 0, y: 0, width: 100, height: 100)).cgPath + + fillColor = UIColor.green + strokeColor = UIColor.green + + lineWidth = 5 + self.position = point + +// self.physicsBody = SKPhysicsBody(circleOfRadius: CGFloat(diametr-4), center: CGPoint(x: 5, y: 5)) + self.physicsBody = SKPhysicsBody(edgeLoopFrom: (path!)) + self.physicsBody?.isDynamic = true + self.physicsBody?.categoryBitMask = CollisionCategory.EdgeBody + self.physicsBody?.contactTestBitMask = CollisionCategory.SnakeHead | CollisionCategory.Apple + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/GameScene.swift b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/GameScene.swift new file mode 100644 index 0000000..cd4efc7 --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/GameScene.swift @@ -0,0 +1,269 @@ +// +// GameScene.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import SpriteKit +import GameplayKit + +struct CollisionCategory{ + static let Snake: UInt32 = 0x1 << 0 + static let SnakeHead:UInt32 = 0x1 << 1 + static let Apple:UInt32 = 0x1 << 2 + static let EdgeBody:UInt32 = 0x1 << 3 +} + +class GameScene: SKScene { + + var snake:Snake? + + //private var label : SKLabelNode? + private var spinnyNode : SKShapeNode? + private var isEndGame: Bool = false + + let shiftForButton:CGFloat = 45 + //края игры + private var xStartPosition:CGFloat = 0.0 + private var yStartPosition:CGFloat = 0.0 + private var gameRectWidth:CGFloat = 0.0 + private var gameRectHeight:CGFloat = 0.0 + private var gameRect:CGRect = CGRect(x: 0, y: 0, width: 0, height: 0) + //текстовое поле в центре экрана + var risedTextNode = SKLabelNode(fontNamed: "Chalkduster") + var risedScoreNode = SKLabelNode(fontNamed: "Chalkduster") + + + //счет игры + var score:Int = 0 + + var apple : SKShapeNode? + + override func didMove(to view: SKView) { + // первое появление сцены на экране + backgroundColor = SKColor.black + + self.physicsWorld.gravity = CGVector(dx: 0, dy: 0) + self.physicsWorld.contactDelegate = self + self.physicsBody = SKPhysicsBody(edgeLoopFrom: frame) + self.physicsBody?.allowsRotation = false + + view.showsPhysics = true +////////// +////////// кнопка поворачивает змейку против часовой стрелки +///////// + let leftCounterClockwiseButton = SKShapeNode() + //форма кнопки - круглая + leftCounterClockwiseButton.path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 45, height: 45)).cgPath + //координаты размещения нашей кнопки + leftCounterClockwiseButton.position = CGPoint(x: view.scene!.frame.minX+30, y: view.scene!.frame.minY+30) // 30 - отступ от нижнего левого угла экрана + //цвет кнопки + leftCounterClockwiseButton.fillColor = UIColor.gray + //цвет рамки + leftCounterClockwiseButton.strokeColor = UIColor.gray + //ширина + leftCounterClockwiseButton.lineWidth = 10 + //имя кнопки + leftCounterClockwiseButton.name = "leftCounterClockwiseButton" + //добавляем на экран + self.addChild(leftCounterClockwiseButton) + +////////// +//////////  кнопка поворачивает змейку по часовой стрелки +///////// + let clockWiseButton = SKShapeNode() + //форма кнопки - круглая + clockWiseButton.path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 45, height: 45)).cgPath + //координаты размещения нашей кнопки + clockWiseButton.position = CGPoint(x: view.scene!.frame.maxX-80, y: view.scene!.frame.minY+30) // 30 - отступ от нижнего левого угла экрана + //цвет кнопки + clockWiseButton.fillColor = UIColor.gray + //цвет рамки + clockWiseButton.strokeColor = UIColor.gray + //ширина + clockWiseButton.lineWidth = 10 + //имя кнопки + clockWiseButton.name = "clockWiseButton" + self.addChild(clockWiseButton) + + //края сцены c учетом кнопок + xStartPosition = view.scene!.frame.minX + yStartPosition = view.scene!.frame.minY+shiftForButton + gameRectWidth = view.scene!.frame.maxX - xStartPosition + gameRectHeight = view.scene!.frame.maxY - yStartPosition - 100 + + gameRect = CGRect(x: xStartPosition, y: yStartPosition, width: gameRectWidth, height: gameRectHeight) + +////////// +//////// физический объект прямоугольник с краями игры, касание которого приводит к окончанию игры +/////// + let quad = SKShapeNode(rect: gameRect) + quad.position = CGPoint(x:xStartPosition, y: yStartPosition) // задаем позицию. + quad.lineWidth = 4 // задаем размер линий. + quad.strokeColor = UIColor.green // задаем цвет контура. + quad.fillColor = UIColor.black // задаем цвет внутренности. + + quad.physicsBody = SKPhysicsBody(edgeLoopFrom: gameRect) + quad.physicsBody?.categoryBitMask = CollisionCategory.EdgeBody //края экрана + quad.physicsBody?.collisionBitMask = CollisionCategory.Snake|CollisionCategory.SnakeHead + quad.name = "Quad" // задаем имя. + self.addChild(quad) // добавляем наш объект на нашу сцену. + +/////////////// + ////////// // текст сообщения о конце игры +//////////// + risedTextNode.position = CGPoint(x: view.scene!.frame.midX, y: view.scene!.frame.midY) // задаем позицию. + risedTextNode.fontSize = 18; // задаем размер шрифта. + risedTextNode.fontColor = UIColor.white // задаем цвет шрифта. + risedTextNode.color = UIColor.blue // задаем цвет (Нужен для сочетание с colorBlendFactor). + risedTextNode.colorBlendFactor = 0.5 // задаем colorBlendFactor (0.0 - 1.0) + risedTextNode.numberOfLines = 3 + risedTextNode.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center // задаем способ выравнивание текста. + risedTextNode.name = "First" // задаем имя спрайта + // !!! но на экран не выводим раньше времени, пока игра не закончилась + +/////////////// +////////// // //текст сообщения о счете игры +//////////// + risedScoreNode.position = CGPoint(x: view.scene!.frame.midX, y: view.scene!.frame.minY+30) // задаем позицию = между двумя кнопками + risedScoreNode.fontSize = 18; // задаем размер шрифта. + risedScoreNode.fontColor = UIColor.white // задаем цвет шрифта. + risedScoreNode.color = UIColor.blue // задаем цвет (Нужен для сочетание с colorBlendFactor). + risedScoreNode.colorBlendFactor = 0.5 // задаем colorBlendFactor (0.0 - 1.0) + risedScoreNode.text = "счет: \(score)" // задаем текст. + risedScoreNode.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.center // задаем способ выравнивание текста. + risedScoreNode.name = "Score" // задаем имя спрайта + self.addChild(risedScoreNode) // добавляем наш спрайт на нашу сцену. + //инициализация змейки и яблока + startGame() + + }//func didMove + + func createApple(){ + let randX = CGFloat(arc4random_uniform(UInt32(gameRect.maxX))) + + var randY:UInt32 + randY = arc4random_uniform(UInt32(gameRect.maxY)) + if randY <= 100{randY = 101} //чтобы яблоко не попадало за пределы прямоугольника + + + apple = Apple(position: CGPoint(x: randX, y: CGFloat(randY))) + self.addChild(apple!) + + //отладочный принт + // print("randX = \(randX),randY = \(randY) gameRect.minX = \(gameRect.minX), gameRect.maxX= \(gameRect.maxX), gameRect.minY = \(gameRect.minY),gameRect.maxY = \(gameRect.maxY), gameRect.width = \(gameRect.width), gameRect.height = \(gameRect.height),xStartPosition = \(xStartPosition), yStartPosition = \(yStartPosition), shiftForButton = \(shiftForButton)") + } + + + + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + + for touch in touches{ + let touchLocation = touch.location(in: self) + guard let touchesNode = self.atPoint(touchLocation) as? SKShapeNode, touchesNode.name == "leftCounterClockwiseButton" || touchesNode.name == "clockWiseButton" else{ + return + } + + touchesNode.fillColor = UIColor.green + + //если конец игры наступил, то левая кнопка - начинает игру заново + if touchesNode.name == "leftCounterClockwiseButton"{ + if isEndGame{ + isEndGame = false + startGame() + }else{ + snake!.moveCounterClockwise() + } + }else if touchesNode.name == "clockWiseButton"{ + snake!.moveClockwise() + } + } + }//func touchesBegan + + + + override func touchesEnded(_ touches: Set, with event: UIEvent?) { + //если касаемся кнопки - красим кнопку в зеленый цвет + for touch in touches{ + let touchLocation = touch.location(in: self) + guard let touchesNode = self.atPoint(touchLocation) as? SKShapeNode, touchesNode.name == "leftCounterClockwiseButton" || touchesNode.name == "clockWiseButton" else{ + return + } + + touchesNode.fillColor = UIColor.gray + + } + + }//func touchesEnded + + override func touchesCancelled(_ touches: Set, with event: UIEvent?) { + + } + + + override func update(_ currentTime: TimeInterval) { + // если не выставлен флаг конец игры, то змея двигается. Иначе - нет + if !isEndGame{ + snake!.move() + } + } + +//функция инициализирует элементы сцены и вначале и когда надо начать новую игру после поражения + func startGame(){ + risedTextNode.removeFromParent() + snake?.removeFromParent() + apple?.removeFromParent() + score = 0 + riseScoreMessage(iScore: score) + createApple() + // + snake = Snake(atPoint: CGPoint(x: (view?.scene!.frame.midX)!, y: (view?.scene!.frame.midY)!)) + + self.addChild(snake!) + }// func startGame + + func riseMessage(messageText:String) { + risedTextNode.text = messageText // задаем текст. + self.addChild(risedTextNode) // добавляем наш спрайт на нашу сцену. + }// func riseMessage + + func riseScoreMessage(iScore: Int) { + risedScoreNode.text = "счет: \(iScore)" // задаем текст. + }// func riseScoreMessage +}//class GameScene + + +extension GameScene: SKPhysicsContactDelegate { + func didBegin(_ contact: SKPhysicsContact) { + let bodyes = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask + let collisionObject = bodyes ^ CollisionCategory.SnakeHead + var appleNode: SKNode? + + appleNode = contact.bodyA.node is Apple ? contact.bodyA.node : contact.bodyB.node + + switch collisionObject { + case CollisionCategory.Apple: //голова столкнулась с яблоком + + snake?.addBodyPart() + + appleNode?.removeFromParent() + score += 1 + riseScoreMessage(iScore: score) + createApple() + + case CollisionCategory.EdgeBody: + isEndGame = true + appleNode?.removeFromParent() + //к сожалению, для многострочного текста надо вручную будет выставлять координаты каждой последующей строки + //решил код не перегружать, поэтому текст простой + riseMessage(messageText: "Конец игры! Нажмите левую кнопку") + + //передаем управление функции нажатия левой кнопки -> func touchesBegan + + default: break + + }//switch + }//func +}//extension diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/GameViewController.swift b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/GameViewController.swift new file mode 100644 index 0000000..af1d6cb --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/GameViewController.swift @@ -0,0 +1,50 @@ +// +// GameViewController.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import UIKit +import SpriteKit +import GameplayKit + +class GameViewController: UIViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + //создали сцену для игры + let scene = GameScene(size: view.bounds.size) + //создали экран + let skView = view as! SKView + + //показывать кол-во объектов + skView.showsNodeCount = true + skView.showsFPS = true + skView.ignoresSiblingOrder = true + //растянули на весь экран + scene.scaleMode = .resizeFill + //отправили сцену на экран + skView.presentScene(scene) + + + } + + override var shouldAutorotate: Bool { + return true + } + + override var supportedInterfaceOrientations: UIInterfaceOrientationMask { + if UIDevice.current.userInterfaceIdiom == .phone { + return .allButUpsideDown + } else { + return .all + } + } + + override var prefersStatusBarHidden: Bool { + return true + } +} diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Info.plist b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Info.plist new file mode 100644 index 0000000..870f784 --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Info.plist @@ -0,0 +1,47 @@ + + + + + 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 + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UIStatusBarHidden + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Snake.swift b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Snake.swift new file mode 100644 index 0000000..dddea0d --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/Snake.swift @@ -0,0 +1,81 @@ +// +// Snake.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import Foundation +import SpriteKit + +class Snake: SKShapeNode { + + let moveSpeed = 125 + var angle: CGFloat = 0.0 + + + var body = [SnakeBodyPart]() + + convenience init(atPoint point: CGPoint){ + self.init() + + let head = SnakeHead(atPoint: point) + + body.append(head) + addChild(head) + } + + func addBodyPart() { + let newBodyPart = SnakeBodyPart(atPoint: CGPoint(x: body[0].position.x, y: body[0].position.y)) + + body.append(newBodyPart) + + addChild(newBodyPart) + } + +// func removeBodyPart(){ +// body = [SnakeBodyPart]() +// +// } + + + func move(){ + guard !body.isEmpty else {return} + let head = body[0] + + moveHead(head) + + for index in (0.. 0 { + let prevBodyPart = body[index-1] + let curBodyPart = body[index] + + moveBodyPart(prevBodyPart,c: curBodyPart) + } + + } + + func moveHead(_ head: SnakeBodyPart){ + let dx = CGFloat(moveSpeed) * sin(angle) + let dy = CGFloat(moveSpeed) * cos(angle) + + let nextPosition = CGPoint(x: head.position.x + dx, y: head.position.y + dy) + let moveAction = SKAction.move(to: nextPosition, duration: 1.0) + + head.run(moveAction) + } + + func moveBodyPart(_ p: SnakeBodyPart, c: SnakeBodyPart){ + let moveAction = SKAction.move(to: CGPoint(x: p.position.x, y: p.position.y), duration: 0.1) + + c.run(moveAction) + } + + func moveClockwise(){ + angle += CGFloat(Double.pi/2) + } + + func moveCounterClockwise(){ + angle -= CGFloat(Double.pi/2) + } +} diff --git a/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/SnakeBodyPart.swift b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/SnakeBodyPart.swift new file mode 100644 index 0000000..e7d8186 --- /dev/null +++ b/lesson07/lesson08/8L_RaskinSergey_snake/8L_RaskinSergey_snake/SnakeBodyPart.swift @@ -0,0 +1,35 @@ +// +// SnakeBodyPart.swift +// 8L_RaskinSergey_snake +// +// Created by raskin-sa on 11/12/2019. +// Copyright © 2019 raskin-sa. All rights reserved. +// + +import Foundation +import SpriteKit + +class SnakeBodyPart: SKShapeNode{ + let diametr = 10 + + init(atPoint point: CGPoint){ + super.init() + + path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: diametr, height: diametr)).cgPath + + fillColor = UIColor.green + strokeColor = UIColor.green + + lineWidth = 5 + self.position = point + + self.physicsBody = SKPhysicsBody(circleOfRadius: CGFloat(diametr-4), center: CGPoint(x: 5, y: 5)) + self.physicsBody?.isDynamic = true + self.physicsBody?.categoryBitMask = CollisionCategory.Snake + self.physicsBody?.contactTestBitMask = CollisionCategory.EdgeBody | CollisionCategory.Apple + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +}