diff --git a/WordMatchGame/WordMatchGame.xcodeproj/project.pbxproj b/WordMatchGame/WordMatchGame.xcodeproj/project.pbxproj index c9ea326..6662f35 100644 --- a/WordMatchGame/WordMatchGame.xcodeproj/project.pbxproj +++ b/WordMatchGame/WordMatchGame.xcodeproj/project.pbxproj @@ -12,6 +12,16 @@ 4B14265B24F6D4A500F6971D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B14265924F6D4A500F6971D /* Main.storyboard */; }; 4B14265D24F6D4A500F6971D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B14265C24F6D4A500F6971D /* Assets.xcassets */; }; 4B14266024F6D4A500F6971D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4B14265E24F6D4A500F6971D /* LaunchScreen.storyboard */; }; + 7525E4E824F70387008E9897 /* InitialViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7525E4E724F70387008E9897 /* InitialViewController.swift */; }; + 7525E4EA24F70404008E9897 /* WordGuessViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7525E4E924F70404008E9897 /* WordGuessViewController.swift */; }; + 9F4D030024F80F7A0088023E /* wordMatchLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F4D02FF24F80F7A0088023E /* wordMatchLabel.swift */; }; + 9F4D030224F810500088023E /* wordMatchTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F4D030124F810500088023E /* wordMatchTextField.swift */; }; + 9F4D030424F844370088023E /* wordMatchButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F4D030324F844370088023E /* wordMatchButton.swift */; }; + 9F4D030624F852600088023E /* generateWordButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F4D030524F852600088023E /* generateWordButton.swift */; }; + 9F4D030824F8672C0088023E /* instructionLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F4D030724F8672C0088023E /* instructionLabel.swift */; }; + 9F4D030A24F86A650088023E /* keyboardLayoutConstraints.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F4D030924F86A650088023E /* keyboardLayoutConstraints.swift */; }; + 9F631C2E24F6FD27006CFDE5 /* StyleGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F631C2D24F6FD27006CFDE5 /* StyleGuide.swift */; }; + 9F631C3024F6FD41006CFDE5 /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9F631C2F24F6FD41006CFDE5 /* Colors.xcassets */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -22,6 +32,16 @@ 4B14265C24F6D4A500F6971D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 4B14265F24F6D4A500F6971D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 4B14266124F6D4A500F6971D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 7525E4E724F70387008E9897 /* InitialViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InitialViewController.swift; sourceTree = ""; }; + 7525E4E924F70404008E9897 /* WordGuessViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordGuessViewController.swift; sourceTree = ""; }; + 9F4D02FF24F80F7A0088023E /* wordMatchLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = wordMatchLabel.swift; sourceTree = ""; }; + 9F4D030124F810500088023E /* wordMatchTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = wordMatchTextField.swift; sourceTree = ""; }; + 9F4D030324F844370088023E /* wordMatchButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = wordMatchButton.swift; sourceTree = ""; }; + 9F4D030524F852600088023E /* generateWordButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = generateWordButton.swift; sourceTree = ""; }; + 9F4D030724F8672C0088023E /* instructionLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = instructionLabel.swift; sourceTree = ""; }; + 9F4D030924F86A650088023E /* keyboardLayoutConstraints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = keyboardLayoutConstraints.swift; sourceTree = ""; }; + 9F631C2D24F6FD27006CFDE5 /* StyleGuide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StyleGuide.swift; sourceTree = ""; }; + 9F631C2F24F6FD41006CFDE5 /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -54,6 +74,7 @@ 4B14265224F6D4A500F6971D /* WordMatchGame */ = { isa = PBXGroup; children = ( + 9F631C2C24F6FD0C006CFDE5 /* CustomUI */, 4B14266824F6D59B00F6971D /* Views */, 4B14266724F6D57A00F6971D /* Resources */, ); @@ -66,6 +87,7 @@ 4B14265324F6D4A500F6971D /* AppDelegate.swift */, 4B14265524F6D4A500F6971D /* SceneDelegate.swift */, 4B14265C24F6D4A500F6971D /* Assets.xcassets */, + 9F631C2F24F6FD41006CFDE5 /* Colors.xcassets */, 4B14265E24F6D4A500F6971D /* LaunchScreen.storyboard */, 4B14266124F6D4A500F6971D /* Info.plist */, ); @@ -75,11 +97,35 @@ 4B14266824F6D59B00F6971D /* Views */ = { isa = PBXGroup; children = ( + 7525E4E624F7036B008E9897 /* ViewControllers */, 4B14265924F6D4A500F6971D /* Main.storyboard */, ); path = Views; sourceTree = ""; }; + 7525E4E624F7036B008E9897 /* ViewControllers */ = { + isa = PBXGroup; + children = ( + 7525E4E724F70387008E9897 /* InitialViewController.swift */, + 7525E4E924F70404008E9897 /* WordGuessViewController.swift */, + ); + path = ViewControllers; + sourceTree = ""; + }; + 9F631C2C24F6FD0C006CFDE5 /* CustomUI */ = { + isa = PBXGroup; + children = ( + 9F631C2D24F6FD27006CFDE5 /* StyleGuide.swift */, + 9F4D02FF24F80F7A0088023E /* wordMatchLabel.swift */, + 9F4D030124F810500088023E /* wordMatchTextField.swift */, + 9F4D030324F844370088023E /* wordMatchButton.swift */, + 9F4D030524F852600088023E /* generateWordButton.swift */, + 9F4D030724F8672C0088023E /* instructionLabel.swift */, + 9F4D030924F86A650088023E /* keyboardLayoutConstraints.swift */, + ); + path = CustomUI; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -139,6 +185,7 @@ buildActionMask = 2147483647; files = ( 4B14266024F6D4A500F6971D /* LaunchScreen.storyboard in Resources */, + 9F631C3024F6FD41006CFDE5 /* Colors.xcassets in Resources */, 4B14265D24F6D4A500F6971D /* Assets.xcassets in Resources */, 4B14265B24F6D4A500F6971D /* Main.storyboard in Resources */, ); @@ -153,6 +200,15 @@ files = ( 4B14265424F6D4A500F6971D /* AppDelegate.swift in Sources */, 4B14265624F6D4A500F6971D /* SceneDelegate.swift in Sources */, + 9F4D030A24F86A650088023E /* keyboardLayoutConstraints.swift in Sources */, + 9F4D030224F810500088023E /* wordMatchTextField.swift in Sources */, + 7525E4E824F70387008E9897 /* InitialViewController.swift in Sources */, + 9F4D030024F80F7A0088023E /* wordMatchLabel.swift in Sources */, + 9F4D030824F8672C0088023E /* instructionLabel.swift in Sources */, + 9F4D030424F844370088023E /* wordMatchButton.swift in Sources */, + 9F4D030624F852600088023E /* generateWordButton.swift in Sources */, + 9F631C2E24F6FD27006CFDE5 /* StyleGuide.swift in Sources */, + 7525E4EA24F70404008E9897 /* WordGuessViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/WordMatchGame/WordMatchGame/CustomUI/StyleGuide.swift b/WordMatchGame/WordMatchGame/CustomUI/StyleGuide.swift new file mode 100644 index 0000000..55b0403 --- /dev/null +++ b/WordMatchGame/WordMatchGame/CustomUI/StyleGuide.swift @@ -0,0 +1,29 @@ +// +// StyleGuide.swift +// WordMatchGame +// +// Created by Todd Crandall on 8/26/20. +// Copyright © 2020 Ian Becker. All rights reserved. +// + +import UIKit + +extension UIView { + + func addCornerRadius(_ radius: CGFloat = 4) { + self.layer.cornerRadius = radius + } +}//End of Extension + +struct FontNames { + + static let helveticaBold = "Helvetica-Bold" +}//End of Struct + +extension UIColor { + + static let customDarkPurple = UIColor(named: "customDarkPurple")! + static let customGreen = UIColor(named: "customGreen") + static let customPink = UIColor(named: "customPink") + static let customPurple = UIColor(named: "customPurple") +}//End of Extension diff --git a/WordMatchGame/WordMatchGame/CustomUI/generateWordButton.swift b/WordMatchGame/WordMatchGame/CustomUI/generateWordButton.swift new file mode 100644 index 0000000..48dcff6 --- /dev/null +++ b/WordMatchGame/WordMatchGame/CustomUI/generateWordButton.swift @@ -0,0 +1,30 @@ +// +// generateWordButton.swift +// WordMatchGame +// +// Created by Todd Crandall on 8/27/20. +// Copyright © 2020 Ian Becker. All rights reserved. +// + +import UIKit + +class generateWordButton: UIButton { + + override func awakeFromNib() { + super.awakeFromNib() + + setUpViews() + } + + func setUpViews() { + self.backgroundColor = .customGreen + self.setTitleColor(.white, for: .normal) + updateFontTo(font: FontNames.helveticaBold) + addCornerRadius() + } + + func updateFontTo(font: String) { + guard let size = self.titleLabel?.font.pointSize else { return } + self.titleLabel?.font = UIFont(name: font, size: size) + } +}//End of Class diff --git a/WordMatchGame/WordMatchGame/CustomUI/instructionLabel.swift b/WordMatchGame/WordMatchGame/CustomUI/instructionLabel.swift new file mode 100644 index 0000000..6942d80 --- /dev/null +++ b/WordMatchGame/WordMatchGame/CustomUI/instructionLabel.swift @@ -0,0 +1,9 @@ +// +// instructionLabel.swift +// WordMatchGame +// +// Created by Todd Crandall on 8/27/20. +// Copyright © 2020 Ian Becker. All rights reserved. +// + +import Foundation diff --git a/WordMatchGame/WordMatchGame/CustomUI/keyboardLayoutConstraints.swift b/WordMatchGame/WordMatchGame/CustomUI/keyboardLayoutConstraints.swift new file mode 100644 index 0000000..0bdf80f --- /dev/null +++ b/WordMatchGame/WordMatchGame/CustomUI/keyboardLayoutConstraints.swift @@ -0,0 +1,92 @@ +// +// keyboardLayoutConstraints.swift +// WordMatchGame +// +// Created by Todd Crandall on 8/27/20. +// Copyright © 2020 Ian Becker. All rights reserved. +// + +import UIKit + +class KeyboardLayoutConstraint: NSLayoutConstraint { + + var offset : CGFloat = 0 + var keyboardVisibleHeight : CGFloat = 0 + + override func awakeFromNib() { + super.awakeFromNib() + + offset = constant + + NotificationCenter.default.addObserver(self, selector: #selector(KeyboardLayoutConstraint.keyboardWillShowNotification(_:)), name: UIWindow.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(KeyboardLayoutConstraint.keyboardWillHideNotification(_:)), name: UIWindow.keyboardWillHideNotification, object: nil) + } + + deinit { + NotificationCenter.default.removeObserver(self) + } + + // MARK: Notification + + @objc func keyboardWillShowNotification(_ notification: Notification) { + if let userInfo = notification.userInfo { + if let frameValue = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { + let frame = frameValue.cgRectValue + keyboardVisibleHeight = frame.size.height + } + + self.updateConstant() + switch (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber, userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber) { + case let (.some(duration), .some(curve)): + + let options = UIView.AnimationOptions(rawValue: curve.uintValue) + + UIView.animate( + withDuration: TimeInterval(duration.doubleValue), + delay: 0, + options: options, + animations: { + UIApplication.shared.keyWindow?.layoutIfNeeded() + return + }, completion: { finished in + }) + default: + + break + } + + } + + } + + @objc func keyboardWillHideNotification(_ notification: NSNotification) { + keyboardVisibleHeight = 0 + self.updateConstant() + + if let userInfo = notification.userInfo { + + switch (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber, userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber) { + case let (.some(duration), .some(curve)): + + let options = UIView.AnimationOptions(rawValue: curve.uintValue) + + UIView.animate( + withDuration: TimeInterval(duration.doubleValue), + delay: 0, + options: options, + animations: { + UIApplication.shared.keyWindow?.layoutIfNeeded() + return + }, completion: { finished in + }) + default: + break + } + } + } + + func updateConstant() { + self.constant = offset + keyboardVisibleHeight + } + +} diff --git a/WordMatchGame/WordMatchGame/CustomUI/wordMatchButton.swift b/WordMatchGame/WordMatchGame/CustomUI/wordMatchButton.swift new file mode 100644 index 0000000..26f49c5 --- /dev/null +++ b/WordMatchGame/WordMatchGame/CustomUI/wordMatchButton.swift @@ -0,0 +1,30 @@ +// +// wordMatchButton.swift +// WordMatchGame +// +// Created by Todd Crandall on 8/27/20. +// Copyright © 2020 Ian Becker. All rights reserved. +// + +import UIKit + +class wordMatchButton: UIButton { + + override func awakeFromNib() { + super.awakeFromNib() + + setUpViews() + } + + func setUpViews() { + self.backgroundColor = .customDarkPurple + self.setTitleColor(.white, for: .normal) + updateFontTo(font: FontNames.helveticaBold) + addCornerRadius() + } + + func updateFontTo(font: String) { + guard let size = self.titleLabel?.font.pointSize else { return } + self.titleLabel?.font = UIFont(name: font, size: size) + } +}//End of Class diff --git a/WordMatchGame/WordMatchGame/CustomUI/wordMatchLabel.swift b/WordMatchGame/WordMatchGame/CustomUI/wordMatchLabel.swift new file mode 100644 index 0000000..1d21a86 --- /dev/null +++ b/WordMatchGame/WordMatchGame/CustomUI/wordMatchLabel.swift @@ -0,0 +1,24 @@ +// +// wordMatchLabel.swift +// WordMatchGame +// +// Created by Todd Crandall on 8/27/20. +// Copyright © 2020 Ian Becker. All rights reserved. +// + +import UIKit + +class wordMatchLabel: UILabel { + + override func awakeFromNib() { + super.awakeFromNib() + + setUpViews() + } + + func setUpViews() { + self.backgroundColor = .customDarkPurple + self.textColor = .white + self.addCornerRadius() + } +}//End of Class diff --git a/WordMatchGame/WordMatchGame/CustomUI/wordMatchTextField.swift b/WordMatchGame/WordMatchGame/CustomUI/wordMatchTextField.swift new file mode 100644 index 0000000..2dd9842 --- /dev/null +++ b/WordMatchGame/WordMatchGame/CustomUI/wordMatchTextField.swift @@ -0,0 +1,41 @@ +// +// wordMatchTextField.swift +// WordMatchGame +// +// Created by Todd Crandall on 8/27/20. +// Copyright © 2020 Ian Becker. All rights reserved. +// + +import UIKit + +class wordMatchTextField: UITextField { + + override func awakeFromNib() { + super.awakeFromNib() + + setUpUI() + } + + func updateFontTo(fontName: String) { + guard let size = self.font?.pointSize else { return } + self.font = UIFont(name: fontName, size: size) + } + + func updatePlaceHolder() { + + let currentPlaceHolderText = self.placeholder + self.attributedPlaceholder = NSAttributedString(string: currentPlaceHolderText ?? "", attributes: [ + NSAttributedString.Key.foregroundColor : UIColor.white, + NSAttributedString.Key.font : UIFont(name: FontNames.helveticaBold, size: 0)! + ]) + } + + func setUpUI() { + self.backgroundColor = .customPink + self.addCornerRadius() + self.layer.masksToBounds = true + self.textColor = .white + self.updateFontTo(fontName: FontNames.helveticaBold) + self.updatePlaceHolder() + } +}//End of Class diff --git a/WordMatchGame/WordMatchGame/Resources/Assets.xcassets/Asset_3THELASTONE.imageset/Asset_3THELASTONE.png b/WordMatchGame/WordMatchGame/Resources/Assets.xcassets/Asset_3THELASTONE.imageset/Asset_3THELASTONE.png new file mode 100644 index 0000000..c7a0db6 Binary files /dev/null and b/WordMatchGame/WordMatchGame/Resources/Assets.xcassets/Asset_3THELASTONE.imageset/Asset_3THELASTONE.png differ diff --git a/WordMatchGame/WordMatchGame/Resources/Assets.xcassets/Asset_3THELASTONE.imageset/Contents.json b/WordMatchGame/WordMatchGame/Resources/Assets.xcassets/Asset_3THELASTONE.imageset/Contents.json new file mode 100644 index 0000000..3b040dd --- /dev/null +++ b/WordMatchGame/WordMatchGame/Resources/Assets.xcassets/Asset_3THELASTONE.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "Asset_3THELASTONE.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/Contents.json b/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/customDarkPurple.colorset/Contents.json b/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/customDarkPurple.colorset/Contents.json new file mode 100644 index 0000000..c0b1d93 --- /dev/null +++ b/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/customDarkPurple.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0x43", + "green" : "0x2D", + "red" : "0x2A" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/customGreen.colorset/Contents.json b/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/customGreen.colorset/Contents.json new file mode 100644 index 0000000..62ea166 --- /dev/null +++ b/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/customGreen.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0xAD", + "green" : "0xE0", + "red" : "0x7B" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/customPink.colorset/Contents.json b/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/customPink.colorset/Contents.json new file mode 100644 index 0000000..c851281 --- /dev/null +++ b/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/customPink.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0xB5", + "green" : "0x5B", + "red" : "0xF1" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/customPurple.colorset/Contents.json b/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/customPurple.colorset/Contents.json new file mode 100644 index 0000000..27592df --- /dev/null +++ b/WordMatchGame/WordMatchGame/Resources/Colors.xcassets/customPurple.colorset/Contents.json @@ -0,0 +1,20 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0xE5", + "green" : "0x5D", + "red" : "0x9B" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/WordMatchGame/WordMatchGame/Views/Base.lproj/Main.storyboard b/WordMatchGame/WordMatchGame/Views/Base.lproj/Main.storyboard index 659a5dc..b978036 100644 --- a/WordMatchGame/WordMatchGame/Views/Base.lproj/Main.storyboard +++ b/WordMatchGame/WordMatchGame/Views/Base.lproj/Main.storyboard @@ -1,8 +1,306 @@ - - + + + + + - + + + + + + + + + + + + + + + + The Goal of the game is to type in a word that has a matching letter in the same index position as the given word. Example: "WORD" has a letter in the first index position of "W", "WHAT" will meet the requirements. Then do it again for "O", "R", and "D". Do it in 30 seconds and you win! Don't...and you suck. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WordMatchGame/WordMatchGame/Views/ViewControllers/InitialViewController.swift b/WordMatchGame/WordMatchGame/Views/ViewControllers/InitialViewController.swift new file mode 100644 index 0000000..29824ae --- /dev/null +++ b/WordMatchGame/WordMatchGame/Views/ViewControllers/InitialViewController.swift @@ -0,0 +1,42 @@ +// +// InitialViewController.swift +// WordMatchGame +// +// Created by Colton Swapp on 8/26/20. +// Copyright © 2020 Ian Becker. All rights reserved. +// + +import UIKit + +class InitialViewController: UIViewController { + + // MARK: - Properties + let arrayOfWords: [String?] = ["Farm", "Oven", "Tree", "Fish", "Cart", "Port", "Rock", "Jump", "Bear", "Fork", "Bowl", "Wolf", "Lake", "Lava", "Hide", "Dark", "Moon", "Star", "Type", "Milk", "Iron", "Goat", "Blue", "Desk", "Plug", "Sock", "High", "Fort", "Baby", "Fall", "Nest", "Card", "Bush", "Pink", "Fire", "Deer", "Trip", "Sand", "Nail", "Yarn", "Tent", "Pail", "Cure", "Dirt", "Cord", "Wood", "Mesh", "Snow", "Salt", "Boat", "Land", "Ball", "Word", "Bolt", "Case", "Trap", "Claw", "Fang", "Hair", "Tire", "Bold", "Clay", "Gray", "Play", "Heat", "Pond", "Frog", "Moss", "Sage", "Game", "View", "Code", "Bump", "Song", "True", "Silk", "Gold", "Road", "Path", "Gate", "Hike", "Bark", "Bird", "Book", "Line", "Band", "Bass", "Rope", "Pole", "Meat", "Drum", "Calf", "Time", "Vial", "Foot", "Gear", "Date", "West", "Boar", "Pass", "Hand", "Swim", "Mark", "Next", "Done", "Well", "Bolt", "Nail", "Peak", "Name", "Bell", "Nose", "Pull", "Team", "Read", "Head", "Gulp", "Plus", "Gear", "Desk", "Twig", "Mars", "Flip", "Base", "Find", "Orca", "Hawk", "Dime", "Pick", "Sail", "Ring", "Cave", "Fear", "Rose", "Look", "Term", "Mode", "Lift", "Ship", "Talk", "Leaf", "Walk", "Camp", "File", "Hour", "Tube", "Dive", "Fuel", "Food", "Page", "Safe", "Draw", "Roll", "Plug", "Hill", "Wrap", "Cake", "Lamp", "Rain", "Hail", "Wind", "Tent"] + + // MARK: - Lifecycle + override func viewDidLoad() { + super.viewDidLoad() + + self.view.backgroundColor = .customDarkPurple + print(arrayOfWords.count) + } + + // MARK: - Methods + func generateRandomWordFrom(wordsArray: [String?]) -> String? { + guard let randomWord = wordsArray.randomElement() else { return "" } + return randomWord + } + + // MARK: - Actions + @IBAction func generateWordButtonTapped(_ sender: UIButton) { + } + + // MARK: - Navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + if segue.identifier == "toWordGuessVC", + let destinationVC = segue.destination as? WordGuessViewController { + let randomWord = generateRandomWordFrom(wordsArray: arrayOfWords) + destinationVC.baseWord = randomWord ?? "" + } + } +} diff --git a/WordMatchGame/WordMatchGame/Views/ViewControllers/WordGuessViewController.swift b/WordMatchGame/WordMatchGame/Views/ViewControllers/WordGuessViewController.swift new file mode 100644 index 0000000..01ea7f7 --- /dev/null +++ b/WordMatchGame/WordMatchGame/Views/ViewControllers/WordGuessViewController.swift @@ -0,0 +1,192 @@ +// +// WordGuessViewController.swift +// WordMatchGame +// +// Created by Colton Swapp on 8/26/20. +// Copyright © 2020 Ian Becker. All rights reserved. +// + +import UIKit + +class WordGuessViewController: UIViewController { + + // MARK: - Outlets + @IBOutlet weak var timerLabel: UILabel! + + @IBOutlet weak var baseWordTextField: UITextField! + @IBOutlet weak var firstLetterTextField: UITextField! + @IBOutlet weak var secondLetterTextField: UITextField! + @IBOutlet weak var thirdLetterTextField: UITextField! + @IBOutlet weak var fourthLetterTextField: UITextField! + + @IBOutlet weak var firstLetterImageView: UIImageView! + @IBOutlet weak var secondLetterImageView: UIImageView! + @IBOutlet weak var thirdLetterImageView: UIImageView! + @IBOutlet weak var fourthLetterImageView: UIImageView! + + @IBOutlet weak var doneButton: UIButton! + + // MARK: - Properties + var baseWord: String = "" + + var timer = Timer() + + var secondsRemaining = 30 + + // MARK: - LifeCycle Methods + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + updateViews() + startTimer() + } + + override func viewDidLoad() { + super.viewDidLoad() + + self.hideKeyboardWhenTappedAround() + + // Do any additional setup after loading the view. + firstLetterTextField.delegate = self + secondLetterTextField.delegate = self + thirdLetterTextField.delegate = self + fourthLetterTextField.delegate = self + } + + // MARK: - Actions + @IBAction func doneButtonTapped(_ sender: Any) { + + if firstLetterImageView.image == UIImage(systemName: "checkmark.circle.fill")?.withTintColor(UIColor(red: 123/255, green: 224/255, blue: 173/255, alpha: 1), renderingMode: .alwaysOriginal) + && secondLetterImageView.image == UIImage(systemName: "checkmark.circle.fill")?.withTintColor(UIColor(red: 123/255, green: 224/255, blue: 173/255, alpha: 1), renderingMode: .alwaysOriginal) + && thirdLetterImageView.image == UIImage(systemName: "checkmark.circle.fill")?.withTintColor(UIColor(red: 123/255, green: 224/255, blue: 173/255, alpha: 1), renderingMode: .alwaysOriginal) + && fourthLetterImageView.image == UIImage(systemName: "checkmark.circle.fill")?.withTintColor(UIColor(red: 123/255, green: 224/255, blue: 173/255, alpha: 1), renderingMode: .alwaysOriginal) { + + self.alertUserOfSuccess() + } + } + + + // MARK: - Methods + func redDoneButton() { + if firstLetterImageView.image == UIImage(systemName: "checkmark.circle.fill")?.withTintColor(UIColor(red: 123/255, green: 224/255, blue: 173/255, alpha: 1), renderingMode: .alwaysOriginal) + && secondLetterImageView.image == UIImage(systemName: "checkmark.circle.fill")?.withTintColor(UIColor(red: 123/255, green: 224/255, blue: 173/255, alpha: 1), renderingMode: .alwaysOriginal) + && thirdLetterImageView.image == UIImage(systemName: "checkmark.circle.fill")?.withTintColor(UIColor(red: 123/255, green: 224/255, blue: 173/255, alpha: 1), renderingMode: .alwaysOriginal) + && fourthLetterImageView.image == UIImage(systemName: "checkmark.circle.fill")?.withTintColor(UIColor(red: 123/255, green: 224/255, blue: 173/255, alpha: 1), renderingMode: .alwaysOriginal) { + + self.doneButton.backgroundColor = .red + } + } + func alertUserOfSuccess() { + + let alertController = UIAlertController(title: "You Win!", message: "You should feel proud of your vocabulary!", preferredStyle: .alert) + let okAction = UIAlertAction(title: "I do feel proud, thanks!", style: .default) { (_) in + DispatchQueue.main.async { + self.navigationController?.popViewController(animated: true) + } + } + alertController.addAction(okAction) + present(alertController, animated: true) + } + + func alertUserOfLoss() { + let alertController = UIAlertController(title: "You're pitiful...", message: "That really wasn't that hard...what's the matter with you?", preferredStyle: .alert) + let okAction = UIAlertAction(title: "You're right... :(", style: .default) { (_) in + DispatchQueue.main.async { + self.navigationController?.popViewController(animated: true) + } + } + alertController.addAction(okAction) + present(alertController, animated: true) + } + + func startTimer() { + timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { (Timer) in + if self.secondsRemaining >= 0 { + self.timerLabel.text = self.timeFormatted(self.secondsRemaining) + self.redDoneButton() + self.secondsRemaining -= 1 + } + else { + Timer.invalidate() + self.alertUserOfLoss() + } + print("\(self.secondsRemaining)") + } + } + + func timeFormatted(_ secondsRemianing: Int) -> String { + let seconds: Int = secondsRemaining % 60 + return String(format: "0:%02d", seconds) + } + + func updateViews() { + baseWordTextField.text = baseWord.uppercased() + doneButton.backgroundColor = .lightGray + self.view.backgroundColor = .customDarkPurple + + timerLabel.text = timeFormatted(secondsRemaining) + } +} + +extension WordGuessViewController: UITextFieldDelegate { + + func textFieldDidEndEditing(_ textField: UITextField) { + let baseWordArray = Array(self.baseWord.lowercased()) + + if textField == firstLetterTextField { + + guard let firstWordText = self.firstLetterTextField.text, !firstWordText.isEmpty else { return } + let firstWordArray = Array(firstWordText.lowercased()) + + if baseWordArray[0] == firstWordArray[0] { + firstLetterImageView.image = UIImage(systemName: "checkmark.circle.fill")?.withTintColor(UIColor(red: 123/255, green: 224/255, blue: 173/255, alpha: 1), renderingMode: .alwaysOriginal) + } else { + firstLetterImageView.image = UIImage(systemName: "xmark.octagon.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal) + } + } + else if textField == secondLetterTextField { + + guard let secondWordText = self.secondLetterTextField.text, !secondWordText.isEmpty else { return } + let secondWordArray = Array(secondWordText.lowercased()) + + if baseWordArray[1] == secondWordArray[1] { + secondLetterImageView.image = UIImage(systemName: "checkmark.circle.fill")?.withTintColor(UIColor(red: 123/255, green: 224/255, blue: 173/255, alpha: 1), renderingMode: .alwaysOriginal) + } else { + secondLetterImageView.image = UIImage(systemName: "xmark.octagon.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal) + } + } + else if textField == thirdLetterTextField { + + guard let thirdWordText = self.thirdLetterTextField.text, !thirdWordText.isEmpty else { return } + let thirdWordArray = Array(thirdWordText.lowercased()) + + if baseWordArray[2] == thirdWordArray[2] { + thirdLetterImageView.image = UIImage(systemName: "checkmark.circle.fill")?.withTintColor(UIColor(red: 123/255, green: 224/255, blue: 173/255, alpha: 1), renderingMode: .alwaysOriginal) + } else { + thirdLetterImageView.image = UIImage(systemName: "xmark.octagon.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal) + } + } else { + + guard let fourthWordText = self.fourthLetterTextField.text, !fourthWordText.isEmpty else { return } + let fourthWordArray = Array(fourthWordText.lowercased()) + + if baseWordArray[3] == fourthWordArray[3] { + fourthLetterImageView.image = UIImage(systemName: "checkmark.circle.fill")?.withTintColor(UIColor(red: 123/255, green: 224/255, blue: 173/255, alpha: 1), renderingMode: .alwaysOriginal) + } else { + fourthLetterImageView.image = UIImage(systemName: "xmark.octagon.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal) + } + } + } +}//End of Class + +extension UIViewController { + func hideKeyboardWhenTappedAround() { + let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard)) + tap.cancelsTouchesInView = false + view.addGestureRecognizer(tap) + } + + @objc func dismissKeyboard() { + view.endEditing(true) + } +}