diff --git a/.DS_Store b/.DS_Store index 1e2f90a..14bec38 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/5l_ChukarkovKonstantin.playground/Contents.swift b/5l_ChukarkovKonstantin.playground/Contents.swift deleted file mode 100644 index f95aa9e..0000000 --- a/5l_ChukarkovKonstantin.playground/Contents.swift +++ /dev/null @@ -1,204 +0,0 @@ -import UIKit - -enum ChangeIgnition: String { - case start = "запущен" - case stop = "заглушен" -} - -enum ChangeWidows: String { - case open = "открыты" - case close = "закрыты" -} - - -protocol Car { - - - var model: String { get set } - var age: Int { get set } - var ignition: ChangeIgnition { get set } - var windows: ChangeWidows { get set } - - mutating func changeIgnition() - mutating func changeWidows() -} - - -extension Car { - - - - mutating func changeIgnition(properties: ChangeIgnition) { - switch properties { - case .start: self.ignition = .start - print("У \(self.model) двигатель \(self.ignition.rawValue)") - case .stop: self.ignition = .stop - print("У \(self.model) двигатель \(self.ignition.rawValue)") - } - } - - mutating func changeWidows(properties: ChangeWidows) { - switch properties { - case .open: self.windows = .open - print("У \(self.model) окна \(self.windows.rawValue)") - case .close: self.windows = .close - print("У \(self.model) окна \(self.windows.rawValue)") - } - } -} - -class TrunkCar: Car { - - func changeWidows() { - } - - func changeIgnition() { - } - - - var model: String = "" - var age: Int = 0 - var ignition: ChangeIgnition = .stop - var windows: ChangeWidows = .close - - enum TypeCar: String { - case sport = "Спортивной" - case truck = "Грузовой" - } - - - let type: TypeCar = .truck - - var bootVolume: Int - - - init(model: String, age: Int, bootVolume: Int) { - self.bootVolume = bootVolume - self.model = model - self.age = age - } - - var trunkVolume: Int = 0 - - enum ChangeTrunkStatus { - case load - case upload - } - - func changeTrunkVolume(act: ChangeTrunkStatus,trunkVolume: Int) { - switch act { - case .load: - self.trunkVolume += trunkVolume - if self.trunkVolume > self.bootVolume { - let unnecessary = self.trunkVolume - self.bootVolume - self.trunkVolume = self.bootVolume - print("Ошибка, слишком большой объем пытаетесь загрузить. Объем багажа \(self.model) заполнен на максимум: \(self.trunkVolume)/\(self.bootVolume) и осталось незагруженно: \(unnecessary)") - } - else { - print("Погрузка в \(self.model) прошла успешна, багажник заполнен на \(self.trunkVolume) из \(self.bootVolume)") - } - case .upload: - self.trunkVolume -= trunkVolume - if self.trunkVolume < 0 { - self.trunkVolume += trunkVolume - print("Ошибка, из \(self.model) невозможно выгрузить \(trunkVolume) литров, там всего \(self.trunkVolume) литров") - } - else { - print("Выгрузка из \(self.model) прошла успешна, багажник заполнен на \(self.trunkVolume) из \(self.bootVolume)") - } - } - } - -} - -extension TrunkCar: CustomStringConvertible { - var description: String { - return "Марка \(self.type.rawValue) машины: \(self.model), год выпуска: \(self.age), объем багажника: \(self.trunkVolume)/\(self.bootVolume) литров, двигатель \(self.ignition.rawValue), окна \(self.windows.rawValue)" - } -} - - -class SportCar: Car { - func changeWidows() { - } - - func changeIgnition() { - } - - enum TypeCar: String { - case sport = "Спортивной" - case truck = "Грузовой" - } - - var model: String = "" - var age: Int = 0 - var ignition: ChangeIgnition = .stop - var windows: ChangeWidows = .close - - let type: TypeCar = .sport - - var topNitro: Int - - var nitro: Int = 0 - - init(model: String, age: Int, topNitro: Int) { - self.topNitro = topNitro - self.nitro = topNitro - self.model = model - self.age = age - } - - - enum ChangeNitro { - case refill - case use - } - - func changeNitro(act: ChangeNitro, nitro: Int) { - switch act { - case .refill: - self.nitro += nitro - if self.nitro > self.topNitro { - let unnecessary = self.nitro - self.topNitro - self.nitro = self.topNitro - print("Ошибка, слишком большой объем пытаетесь загрузить. Бак нитро \(self.model) заполнен на максимум: \(self.nitro)/\(self.topNitro) литров, и осталось незагруженно: \(unnecessary)") - } - else { - print("Добавка нитро в \(self.model) прошла успешна, бак нитро заполнен на \(self.nitro) из \(self.topNitro)") - } - case .use: - self.nitro -= nitro - if self.nitro < 0 { - self.nitro += nitro - print("Ошибка, \(self.model) не может использовать \(nitro) литров, там всего \(self.nitro) литров") - } - else { - print("Использование \(self.model) нитро прошла успешна, бак нитро заполнен на \(self.nitro) из \(self.topNitro)") - } - } - } -} - -extension SportCar: CustomStringConvertible { -var description: String { - return "Марка \(self.type.rawValue) машины: \(self.model), год выпуска: \(self.age), бак нитро: \(self.nitro)/\(self.topNitro) литров, двигатель \(self.ignition.rawValue), окна \(self.windows.rawValue)" - } -} - -var ladaLargus = TrunkCar(model: "Lada Largus", age: 2014, bootVolume: 560) -var mazda = SportCar(model: "Mazda", age: 2009, topNitro: 5) -var largus = TrunkCar(model: "Lada", age: 2007, bootVolume: 350) -var mazda3 = SportCar(model: "Mazda 3", age: 2018, topNitro: 10) - -print(ladaLargus.description) -print(mazda3.description) -ladaLargus.changeTrunkVolume(act: .load, trunkVolume: 300) -print(ladaLargus.description) -mazda3.changeNitro(act: .use, nitro: 5) -mazda3.changeNitro(act: .refill, nitro: 7) -largus.changeWidows(properties: .open) -mazda.changeIgnition(properties: .start) -largus.changeTrunkVolume(act: .load, trunkVolume: 400) -mazda.changeNitro(act: .use, nitro: 3) -print(ladaLargus.description) -print(mazda.description) diff --git a/5l_ChukarkovKonstantin.playground/contents.xcplayground b/5l_ChukarkovKonstantin.playground/contents.xcplayground deleted file mode 100644 index 5da2641..0000000 --- a/5l_ChukarkovKonstantin.playground/contents.xcplayground +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/6l_ChukarkovKonstantin.playground/Contents.swift b/6l_ChukarkovKonstantin.playground/Contents.swift deleted file mode 100644 index d8b0348..0000000 --- a/6l_ChukarkovKonstantin.playground/Contents.swift +++ /dev/null @@ -1,45 +0,0 @@ - -struct Stack { - - var items = [Element]() - mutating func push(_ item: Element) { - items.append(item) - } - - mutating func pop() -> Element { - return items.removeLast() - } - - mutating func append(_ item: Element) { - self.push(item) - } - - - var count: Int { - return items.count - } - - subscript(i: Int) -> Element? { - if i < items.count { - return items[i] - } - return nil - } - -} - - -var stack = Stack() - -stack.push("кот") -stack.push("бегемот") -stack.push("жираф") -stack.push("крыса") - -stack.pop() - -print(stack.count) - - -print(stack[1]!) -print(stack[4] as Any) diff --git a/6l_ChukarkovKonstantin.playground/contents.xcplayground b/6l_ChukarkovKonstantin.playground/contents.xcplayground deleted file mode 100644 index 5da2641..0000000 --- a/6l_ChukarkovKonstantin.playground/contents.xcplayground +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/LessonSnake/.DS_Store b/LessonSnake/.DS_Store new file mode 100644 index 0000000..4efdfa1 Binary files /dev/null and b/LessonSnake/.DS_Store differ diff --git a/LessonSnake/LessonSnake.xcodeproj/project.pbxproj b/LessonSnake/LessonSnake.xcodeproj/project.pbxproj new file mode 100644 index 0000000..5dd5fc9 --- /dev/null +++ b/LessonSnake/LessonSnake.xcodeproj/project.pbxproj @@ -0,0 +1,613 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + B589B17D248FF1B9007474F1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B589B17C248FF1B9007474F1 /* AppDelegate.swift */; }; + B589B183248FF1B9007474F1 /* GameScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = B589B182248FF1B9007474F1 /* GameScene.swift */; }; + B589B185248FF1B9007474F1 /* GameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B589B184248FF1B9007474F1 /* GameViewController.swift */; }; + B589B188248FF1B9007474F1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B589B186248FF1B9007474F1 /* Main.storyboard */; }; + B589B18A248FF1C0007474F1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B589B189248FF1C0007474F1 /* Assets.xcassets */; }; + B589B18D248FF1C0007474F1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B589B18B248FF1C0007474F1 /* LaunchScreen.storyboard */; }; + B589B198248FF1C0007474F1 /* LessonSnakeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B589B197248FF1C0007474F1 /* LessonSnakeTests.swift */; }; + B589B1A3248FF1C0007474F1 /* LessonSnakeUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B589B1A2248FF1C0007474F1 /* LessonSnakeUITests.swift */; }; + B589B1B224901BE5007474F1 /* Apple.swift in Sources */ = {isa = PBXBuildFile; fileRef = B589B1B124901BE5007474F1 /* Apple.swift */; }; + B589B1B424901F1A007474F1 /* SnakeBodyPart.swift in Sources */ = {isa = PBXBuildFile; fileRef = B589B1B324901F1A007474F1 /* SnakeBodyPart.swift */; }; + B589B1B6249020DF007474F1 /* SnakeHead.swift in Sources */ = {isa = PBXBuildFile; fileRef = B589B1B5249020DF007474F1 /* SnakeHead.swift */; }; + B589B1B82490AB59007474F1 /* Snake.swift in Sources */ = {isa = PBXBuildFile; fileRef = B589B1B72490AB59007474F1 /* Snake.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + B589B194248FF1C0007474F1 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = B589B171248FF1B8007474F1 /* Project object */; + proxyType = 1; + remoteGlobalIDString = B589B178248FF1B9007474F1; + remoteInfo = LessonSnake; + }; + B589B19F248FF1C0007474F1 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = B589B171248FF1B8007474F1 /* Project object */; + proxyType = 1; + remoteGlobalIDString = B589B178248FF1B9007474F1; + remoteInfo = LessonSnake; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + B589B179248FF1B9007474F1 /* LessonSnake.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LessonSnake.app; sourceTree = BUILT_PRODUCTS_DIR; }; + B589B17C248FF1B9007474F1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + B589B182248FF1B9007474F1 /* GameScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameScene.swift; sourceTree = ""; }; + B589B184248FF1B9007474F1 /* GameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameViewController.swift; sourceTree = ""; }; + B589B187248FF1B9007474F1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + B589B189248FF1C0007474F1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + B589B18C248FF1C0007474F1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + B589B18E248FF1C0007474F1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + B589B193248FF1C0007474F1 /* LessonSnakeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LessonSnakeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + B589B197248FF1C0007474F1 /* LessonSnakeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LessonSnakeTests.swift; sourceTree = ""; }; + B589B199248FF1C0007474F1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + B589B19E248FF1C0007474F1 /* LessonSnakeUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LessonSnakeUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + B589B1A2248FF1C0007474F1 /* LessonSnakeUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LessonSnakeUITests.swift; sourceTree = ""; }; + B589B1A4248FF1C0007474F1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + B589B1B124901BE5007474F1 /* Apple.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Apple.swift; sourceTree = ""; }; + B589B1B324901F1A007474F1 /* SnakeBodyPart.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnakeBodyPart.swift; sourceTree = ""; }; + B589B1B5249020DF007474F1 /* SnakeHead.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnakeHead.swift; sourceTree = ""; }; + B589B1B72490AB59007474F1 /* Snake.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Snake.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + B589B176248FF1B9007474F1 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + B589B190248FF1C0007474F1 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + B589B19B248FF1C0007474F1 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + B589B170248FF1B8007474F1 = { + isa = PBXGroup; + children = ( + B589B17B248FF1B9007474F1 /* LessonSnake */, + B589B196248FF1C0007474F1 /* LessonSnakeTests */, + B589B1A1248FF1C0007474F1 /* LessonSnakeUITests */, + B589B17A248FF1B9007474F1 /* Products */, + ); + sourceTree = ""; + }; + B589B17A248FF1B9007474F1 /* Products */ = { + isa = PBXGroup; + children = ( + B589B179248FF1B9007474F1 /* LessonSnake.app */, + B589B193248FF1C0007474F1 /* LessonSnakeTests.xctest */, + B589B19E248FF1C0007474F1 /* LessonSnakeUITests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + B589B17B248FF1B9007474F1 /* LessonSnake */ = { + isa = PBXGroup; + children = ( + B589B1B024901B8B007474F1 /* Node */, + B589B17C248FF1B9007474F1 /* AppDelegate.swift */, + B589B182248FF1B9007474F1 /* GameScene.swift */, + B589B184248FF1B9007474F1 /* GameViewController.swift */, + B589B186248FF1B9007474F1 /* Main.storyboard */, + B589B189248FF1C0007474F1 /* Assets.xcassets */, + B589B18B248FF1C0007474F1 /* LaunchScreen.storyboard */, + B589B18E248FF1C0007474F1 /* Info.plist */, + ); + path = LessonSnake; + sourceTree = ""; + }; + B589B196248FF1C0007474F1 /* LessonSnakeTests */ = { + isa = PBXGroup; + children = ( + B589B197248FF1C0007474F1 /* LessonSnakeTests.swift */, + B589B199248FF1C0007474F1 /* Info.plist */, + ); + path = LessonSnakeTests; + sourceTree = ""; + }; + B589B1A1248FF1C0007474F1 /* LessonSnakeUITests */ = { + isa = PBXGroup; + children = ( + B589B1A2248FF1C0007474F1 /* LessonSnakeUITests.swift */, + B589B1A4248FF1C0007474F1 /* Info.plist */, + ); + path = LessonSnakeUITests; + sourceTree = ""; + }; + B589B1B024901B8B007474F1 /* Node */ = { + isa = PBXGroup; + children = ( + B589B1B124901BE5007474F1 /* Apple.swift */, + B589B1B324901F1A007474F1 /* SnakeBodyPart.swift */, + B589B1B5249020DF007474F1 /* SnakeHead.swift */, + B589B1B72490AB59007474F1 /* Snake.swift */, + ); + path = Node; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + B589B178248FF1B9007474F1 /* LessonSnake */ = { + isa = PBXNativeTarget; + buildConfigurationList = B589B1A7248FF1C0007474F1 /* Build configuration list for PBXNativeTarget "LessonSnake" */; + buildPhases = ( + B589B175248FF1B9007474F1 /* Sources */, + B589B176248FF1B9007474F1 /* Frameworks */, + B589B177248FF1B9007474F1 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = LessonSnake; + productName = LessonSnake; + productReference = B589B179248FF1B9007474F1 /* LessonSnake.app */; + productType = "com.apple.product-type.application"; + }; + B589B192248FF1C0007474F1 /* LessonSnakeTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = B589B1AA248FF1C0007474F1 /* Build configuration list for PBXNativeTarget "LessonSnakeTests" */; + buildPhases = ( + B589B18F248FF1C0007474F1 /* Sources */, + B589B190248FF1C0007474F1 /* Frameworks */, + B589B191248FF1C0007474F1 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + B589B195248FF1C0007474F1 /* PBXTargetDependency */, + ); + name = LessonSnakeTests; + productName = LessonSnakeTests; + productReference = B589B193248FF1C0007474F1 /* LessonSnakeTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + B589B19D248FF1C0007474F1 /* LessonSnakeUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = B589B1AD248FF1C0007474F1 /* Build configuration list for PBXNativeTarget "LessonSnakeUITests" */; + buildPhases = ( + B589B19A248FF1C0007474F1 /* Sources */, + B589B19B248FF1C0007474F1 /* Frameworks */, + B589B19C248FF1C0007474F1 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + B589B1A0248FF1C0007474F1 /* PBXTargetDependency */, + ); + name = LessonSnakeUITests; + productName = LessonSnakeUITests; + productReference = B589B19E248FF1C0007474F1 /* LessonSnakeUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + B589B171248FF1B8007474F1 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1150; + LastUpgradeCheck = 1150; + ORGANIZATIONNAME = Konstantin; + TargetAttributes = { + B589B178248FF1B9007474F1 = { + CreatedOnToolsVersion = 11.5; + }; + B589B192248FF1C0007474F1 = { + CreatedOnToolsVersion = 11.5; + TestTargetID = B589B178248FF1B9007474F1; + }; + B589B19D248FF1C0007474F1 = { + CreatedOnToolsVersion = 11.5; + TestTargetID = B589B178248FF1B9007474F1; + }; + }; + }; + buildConfigurationList = B589B174248FF1B8007474F1 /* Build configuration list for PBXProject "LessonSnake" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = B589B170248FF1B8007474F1; + productRefGroup = B589B17A248FF1B9007474F1 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + B589B178248FF1B9007474F1 /* LessonSnake */, + B589B192248FF1C0007474F1 /* LessonSnakeTests */, + B589B19D248FF1C0007474F1 /* LessonSnakeUITests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + B589B177248FF1B9007474F1 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + B589B188248FF1B9007474F1 /* Main.storyboard in Resources */, + B589B18A248FF1C0007474F1 /* Assets.xcassets in Resources */, + B589B18D248FF1C0007474F1 /* LaunchScreen.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + B589B191248FF1C0007474F1 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + B589B19C248FF1C0007474F1 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + B589B175248FF1B9007474F1 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + B589B1B6249020DF007474F1 /* SnakeHead.swift in Sources */, + B589B1B224901BE5007474F1 /* Apple.swift in Sources */, + B589B183248FF1B9007474F1 /* GameScene.swift in Sources */, + B589B185248FF1B9007474F1 /* GameViewController.swift in Sources */, + B589B1B424901F1A007474F1 /* SnakeBodyPart.swift in Sources */, + B589B1B82490AB59007474F1 /* Snake.swift in Sources */, + B589B17D248FF1B9007474F1 /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + B589B18F248FF1C0007474F1 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + B589B198248FF1C0007474F1 /* LessonSnakeTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + B589B19A248FF1C0007474F1 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + B589B1A3248FF1C0007474F1 /* LessonSnakeUITests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + B589B195248FF1C0007474F1 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = B589B178248FF1B9007474F1 /* LessonSnake */; + targetProxy = B589B194248FF1C0007474F1 /* PBXContainerItemProxy */; + }; + B589B1A0248FF1C0007474F1 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = B589B178248FF1B9007474F1 /* LessonSnake */; + targetProxy = B589B19F248FF1C0007474F1 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + B589B186248FF1B9007474F1 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + B589B187248FF1B9007474F1 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + B589B18B248FF1C0007474F1 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + B589B18C248FF1C0007474F1 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + B589B1A5248FF1C0007474F1 /* 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.5; + 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; + }; + B589B1A6248FF1C0007474F1 /* 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.5; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + B589B1A8248FF1C0007474F1 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = LessonSnake/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.ckost9n.LessonSnake; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + B589B1A9248FF1C0007474F1 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = LessonSnake/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.ckost9n.LessonSnake; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + B589B1AB248FF1C0007474F1 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = LessonSnakeTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.5; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.ckost9n.LessonSnakeTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LessonSnake.app/LessonSnake"; + }; + name = Debug; + }; + B589B1AC248FF1C0007474F1 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = LessonSnakeTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 13.5; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.ckost9n.LessonSnakeTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/LessonSnake.app/LessonSnake"; + }; + name = Release; + }; + B589B1AE248FF1C0007474F1 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = LessonSnakeUITests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.ckost9n.LessonSnakeUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = LessonSnake; + }; + name = Debug; + }; + B589B1AF248FF1C0007474F1 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + CODE_SIGN_STYLE = Automatic; + INFOPLIST_FILE = LessonSnakeUITests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.ckost9n.LessonSnakeUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = LessonSnake; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + B589B174248FF1B8007474F1 /* Build configuration list for PBXProject "LessonSnake" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + B589B1A5248FF1C0007474F1 /* Debug */, + B589B1A6248FF1C0007474F1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + B589B1A7248FF1C0007474F1 /* Build configuration list for PBXNativeTarget "LessonSnake" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + B589B1A8248FF1C0007474F1 /* Debug */, + B589B1A9248FF1C0007474F1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + B589B1AA248FF1C0007474F1 /* Build configuration list for PBXNativeTarget "LessonSnakeTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + B589B1AB248FF1C0007474F1 /* Debug */, + B589B1AC248FF1C0007474F1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + B589B1AD248FF1C0007474F1 /* Build configuration list for PBXNativeTarget "LessonSnakeUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + B589B1AE248FF1C0007474F1 /* Debug */, + B589B1AF248FF1C0007474F1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = B589B171248FF1B8007474F1 /* Project object */; +} diff --git a/LessonSnake/LessonSnake.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/LessonSnake/LessonSnake.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..bb6aabe --- /dev/null +++ b/LessonSnake/LessonSnake.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/LessonSnake/LessonSnake.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/LessonSnake/LessonSnake.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/LessonSnake/LessonSnake.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/LessonSnake/LessonSnake.xcodeproj/project.xcworkspace/xcuserdata/konstantin.xcuserdatad/UserInterfaceState.xcuserstate b/LessonSnake/LessonSnake.xcodeproj/project.xcworkspace/xcuserdata/konstantin.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..a1be6d9 Binary files /dev/null and b/LessonSnake/LessonSnake.xcodeproj/project.xcworkspace/xcuserdata/konstantin.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/LessonSnake/LessonSnake.xcodeproj/xcuserdata/konstantin.xcuserdatad/xcschemes/xcschememanagement.plist b/LessonSnake/LessonSnake.xcodeproj/xcuserdata/konstantin.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..f940495 --- /dev/null +++ b/LessonSnake/LessonSnake.xcodeproj/xcuserdata/konstantin.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + LessonSnake.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/LessonSnake/LessonSnake/Actions.sks b/LessonSnake/LessonSnake/Actions.sks new file mode 100644 index 0000000..0530520 Binary files /dev/null and b/LessonSnake/LessonSnake/Actions.sks differ diff --git a/LessonSnake/LessonSnake/AppDelegate.swift b/LessonSnake/LessonSnake/AppDelegate.swift new file mode 100644 index 0000000..93a499d --- /dev/null +++ b/LessonSnake/LessonSnake/AppDelegate.swift @@ -0,0 +1,41 @@ +// +// AppDelegate.swift +// LessonSnake +// +// Created by Konstantin on 09.06.2020. +// Copyright © 2020 Konstantin. 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/LessonSnake/LessonSnake/Assets.xcassets/AppIcon.appiconset/Contents.json b/LessonSnake/LessonSnake/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..9221b9b --- /dev/null +++ b/LessonSnake/LessonSnake/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/LessonSnake/LessonSnake/Assets.xcassets/Contents.json b/LessonSnake/LessonSnake/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/LessonSnake/LessonSnake/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/LessonSnake/LessonSnake/Base.lproj/LaunchScreen.storyboard b/LessonSnake/LessonSnake/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..865e932 --- /dev/null +++ b/LessonSnake/LessonSnake/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LessonSnake/LessonSnake/Base.lproj/Main.storyboard b/LessonSnake/LessonSnake/Base.lproj/Main.storyboard new file mode 100644 index 0000000..2cc971a --- /dev/null +++ b/LessonSnake/LessonSnake/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LessonSnake/LessonSnake/GameScene.sks b/LessonSnake/LessonSnake/GameScene.sks new file mode 100644 index 0000000..4fe4d9f Binary files /dev/null and b/LessonSnake/LessonSnake/GameScene.sks differ diff --git a/LessonSnake/LessonSnake/GameScene.swift b/LessonSnake/LessonSnake/GameScene.swift new file mode 100644 index 0000000..a86f487 --- /dev/null +++ b/LessonSnake/LessonSnake/GameScene.swift @@ -0,0 +1,155 @@ +// +// GameScene.swift +// LessonSnake +// +// Created by Konstantin on 09.06.2020. +// Copyright © 2020 Konstantin. All rights reserved. +// + +import SpriteKit +import GameplayKit + +struct CollisionCategories { + static let Snake: UInt32 = 0x1 << 0 + static let SnekeHead: UInt32 = 0x1 << 1 + static let Apple: UInt32 = 0x1 << 2 + static let EdgeBody: UInt32 = 0x1 << 3 +} + +class GameScene: SKScene { + + var snake: Snake? + + + override func didMove(to view: SKView) { + + backgroundColor = SKColor.black + self.physicsWorld.gravity = CGVector(dx: 0, dy: 0) + self.physicsBody = SKPhysicsBody(edgeLoopFrom: frame) + self.physicsBody?.allowsRotation = false + view.showsPhysics = true + + self.physicsWorld.contactDelegate = self + + + let counterClockwiseButton = SKShapeNode() + + counterClockwiseButton.path = UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 45, height: 45)).cgPath + + counterClockwiseButton.position = CGPoint(x: view.scene!.frame.minX+30, y: view.scene!.frame.minY+30) + + counterClockwiseButton.fillColor = UIColor.gray + + counterClockwiseButton.strokeColor = UIColor.gray + counterClockwiseButton.lineWidth = 10 + + counterClockwiseButton.name = "counterClockwiseButton" + + self.addChild(counterClockwiseButton) + + 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) + clockwiseButton.fillColor = UIColor.gray + clockwiseButton.strokeColor = UIColor.gray + + clockwiseButton.lineWidth = 10 + + clockwiseButton.name = "clockwiseButton" + self.addChild(clockwiseButton) + + createApple() + + snake = Snake(atPoint: CGPoint(x: view.scene!.frame.midX, y: view.scene!.frame.midY)) + + self.addChild(snake!) + + self.physicsBody?.categoryBitMask = CollisionCategories.EdgeBody + self.physicsBody?.collisionBitMask = CollisionCategories.Snake | CollisionCategories.SnekeHead + + } + + func createApple() { + let randX = CGFloat(arc4random_uniform(UInt32(view!.scene!.frame.maxX-25))) + + let randY = CGFloat(arc4random_uniform(UInt32(view!.scene!.frame.maxY-25))) + + let apple = Apple(position: CGPoint(x: randX, y: randY)) + self.addChild(apple) + + } + + + override func touchesBegan(_ touches: Set, with event: UIEvent?) { + + for touch in touches { + + let touchLocation = touch.location(in: self) + + guard let touchNode = self.atPoint(touchLocation) as? SKShapeNode, touchNode.name == "counterClockwiseButton" || touchNode.name == "clockwiseButton" else { + return + } + + touchNode.fillColor = .green + + } + + } + + + override func touchesEnded(_ touches: Set, with event: UIEvent?) { + + for touch in touches { + + let touchLocation = touch.location(in: self) + + guard let touchNode = self.atPoint(touchLocation) as? SKShapeNode, touchNode.name == "counterClockwiseButton" || touchNode.name == "clockwiseButton" else { + return + } + + touchNode.fillColor = .gray + + if touchNode.name == "counterClockwiseButton" { + snake!.moveCounterClockwise() + } else if touchNode.name == "clockwiseButton" { + snake!.moveClockwise() + } + + } + + } + + override func touchesCancelled(_ touches: Set, with event: UIEvent?) { + + } + + + override func update(_ currentTime: TimeInterval) { + snake!.move() + } +} + + +extension GameScene: SKPhysicsContactDelegate { + func didBegin(_ contact: SKPhysicsContact) { + + let bodyes = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask + let collisionObject = bodyes ^ CollisionCategories.SnekeHead + + switch collisionObject { + case CollisionCategories.Apple: + let apple = contact.bodyA.node is Apple ? contact.bodyA.node : contact.bodyB.node + snake?.addBodyPart() + apple?.removeFromParent() + createApple() + case CollisionCategories.EdgeBody: + let _ = contact.bodyA.node is GameScene ? contact.bodyA.node : contact.bodyB.node + let gameScene = GameScene(size: self.size) + self.view?.presentScene(gameScene) + default: + break + } + + + } +} diff --git a/LessonSnake/LessonSnake/GameViewController.swift b/LessonSnake/LessonSnake/GameViewController.swift new file mode 100644 index 0000000..28e5643 --- /dev/null +++ b/LessonSnake/LessonSnake/GameViewController.swift @@ -0,0 +1,46 @@ +// +// GameViewController.swift +// LessonSnake +// +// Created by Konstantin on 09.06.2020. +// Copyright © 2020 Konstantin. 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.showsFPS = true + skView.showsNodeCount = 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/LessonSnake/LessonSnake/Info.plist b/LessonSnake/LessonSnake/Info.plist new file mode 100644 index 0000000..870f784 --- /dev/null +++ b/LessonSnake/LessonSnake/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/LessonSnake/LessonSnake/Node/Apple.swift b/LessonSnake/LessonSnake/Node/Apple.swift new file mode 100644 index 0000000..fa689fd --- /dev/null +++ b/LessonSnake/LessonSnake/Node/Apple.swift @@ -0,0 +1,33 @@ +// +// Apple.swift +// LessonSnake +// +// Created by Konstantin on 09.06.2020. +// Copyright © 2020 Konstantin. All rights reserved. +// + +import UIKit +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, center: CGPoint(x: 5, y: 5)) + + self.physicsBody?.categoryBitMask = CollisionCategories.Apple + + + } + +} diff --git a/LessonSnake/LessonSnake/Node/Snake.swift b/LessonSnake/LessonSnake/Node/Snake.swift new file mode 100644 index 0000000..1557ee4 --- /dev/null +++ b/LessonSnake/LessonSnake/Node/Snake.swift @@ -0,0 +1,80 @@ +// +// Snake.swift +// LessonSnake +// +// Created by Konstantin on 10.06.2020. +// Copyright © 2020 Konstantin. All rights reserved. +// + +import UIKit +import SpriteKit + +class Snake: SKShapeNode { + + let moveSpeed = 125.0 + 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 move() { + + guard !body.isEmpty else {return} + + let head = body[0] + moveHead(head) + + for index in (0.. 0 { + let previousBodyPart = body[index-1] + let currentBodyPart = body[index] + moveBodyPart(previousBodyPart, c: currentBodyPart) + } + + } + + 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 addBodyPart() { + let newBodyPart = SnakeBodyPart(atPoint: CGPoint(x: body[0].position.x, y: body[0].position.y)) + + body.append(newBodyPart) + addChild(newBodyPart) + } + + func moveClockwise() { + angle += CGFloat(Double.pi/2) + } + + func moveCounterClockwise() { + angle -= CGFloat(Double.pi/2) + } + + +} diff --git a/LessonSnake/LessonSnake/Node/SnakeBodyPart.swift b/LessonSnake/LessonSnake/Node/SnakeBodyPart.swift new file mode 100644 index 0000000..7bdb037 --- /dev/null +++ b/LessonSnake/LessonSnake/Node/SnakeBodyPart.swift @@ -0,0 +1,39 @@ +// +// SnakeBodyPart.swift +// LessonSnake +// +// Created by Konstantin on 09.06.2020. +// Copyright © 2020 Konstantin. All rights reserved. +// + +import UIKit +import SpriteKit + +class SnakeBodyPart: SKShapeNode { + + let diametr = 10.0 + + 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 = CollisionCategories.Snake + + self.physicsBody?.categoryBitMask = CollisionCategories.EdgeBody | CollisionCategories.Apple + + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +} diff --git a/LessonSnake/LessonSnake/Node/SnakeHead.swift b/LessonSnake/LessonSnake/Node/SnakeHead.swift new file mode 100644 index 0000000..ade1668 --- /dev/null +++ b/LessonSnake/LessonSnake/Node/SnakeHead.swift @@ -0,0 +1,26 @@ +// +// SnakeHead.swift +// LessonSnake +// +// Created by Konstantin on 09.06.2020. +// Copyright © 2020 Konstantin. All rights reserved. +// + +import UIKit + + +class SnakeHead: SnakeBodyPart { + override init(atPoint point: CGPoint) { + super.init(atPoint: point) + + self.physicsBody?.categoryBitMask = CollisionCategories.SnekeHead + self.physicsBody?.contactTestBitMask = CollisionCategories.EdgeBody | CollisionCategories.Apple | CollisionCategories.Snake + + } + + + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/LessonSnake/LessonSnakeTests/Info.plist b/LessonSnake/LessonSnakeTests/Info.plist new file mode 100644 index 0000000..64d65ca --- /dev/null +++ b/LessonSnake/LessonSnakeTests/Info.plist @@ -0,0 +1,22 @@ + + + + + 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 + + diff --git a/LessonSnake/LessonSnakeTests/LessonSnakeTests.swift b/LessonSnake/LessonSnakeTests/LessonSnakeTests.swift new file mode 100644 index 0000000..0520430 --- /dev/null +++ b/LessonSnake/LessonSnakeTests/LessonSnakeTests.swift @@ -0,0 +1,34 @@ +// +// LessonSnakeTests.swift +// LessonSnakeTests +// +// Created by Konstantin on 09.06.2020. +// Copyright © 2020 Konstantin. All rights reserved. +// + +import XCTest +@testable import LessonSnake + +class LessonSnakeTests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testPerformanceExample() throws { + // This is an example of a performance test case. + self.measure { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/LessonSnake/LessonSnakeUITests/Info.plist b/LessonSnake/LessonSnakeUITests/Info.plist new file mode 100644 index 0000000..64d65ca --- /dev/null +++ b/LessonSnake/LessonSnakeUITests/Info.plist @@ -0,0 +1,22 @@ + + + + + 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 + + diff --git a/LessonSnake/LessonSnakeUITests/LessonSnakeUITests.swift b/LessonSnake/LessonSnakeUITests/LessonSnakeUITests.swift new file mode 100644 index 0000000..4b4c503 --- /dev/null +++ b/LessonSnake/LessonSnakeUITests/LessonSnakeUITests.swift @@ -0,0 +1,43 @@ +// +// LessonSnakeUITests.swift +// LessonSnakeUITests +// +// Created by Konstantin on 09.06.2020. +// Copyright © 2020 Konstantin. All rights reserved. +// + +import XCTest + +class LessonSnakeUITests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() throws { + // UI tests must launch the application that they test. + let app = XCUIApplication() + app.launch() + + // Use recording to get started writing UI tests. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testLaunchPerformance() throws { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, *) { + // This measures how long it takes to launch your application. + measure(metrics: [XCTOSSignpostMetric.applicationLaunch]) { + XCUIApplication().launch() + } + } + } +} diff --git a/README.md b/README.md index 7415f74..6382685 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# swiftFirstLesson \ No newline at end of file +# swiftFirstLesson +add 6-l