From d200984eaf70ff9743dbf6409ff65f9399d89f2e Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 21 Jan 2021 14:26:56 -0500 Subject: [PATCH 1/4] Simpler Quadratic Problems with a-value of 1 --- ProjectClock/MathExpressions.swift | 41 ++++++++++-------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/ProjectClock/MathExpressions.swift b/ProjectClock/MathExpressions.swift index d908330..6c11aed 100644 --- a/ProjectClock/MathExpressions.swift +++ b/ProjectClock/MathExpressions.swift @@ -2,7 +2,7 @@ // MathExpressions.swift // ProjectClock // -// Class that will generate a simple math expression +// MathElement import Foundation @@ -118,38 +118,23 @@ let c = MathExpression.random() } } +class quadraticProb{ + //generates the roots + let root1 = Int.random(in: 1...10)//ax^2 + let root2 = Int.random(in: 1...10)//bx -class QuadraticProb{ - - let a = Int.random(in: 1...10)//ax^2 - let b = Int.random(in: 1...10)//bx - let c = Int.random(in: 1...10)//c - var roots = [Int]() - - func getProblem() -> String{ - return "\(a)x^2 + \(b)x + \(c)" + //a value is 1 + let b = root1 + root2 // b value + let c = root1 * root2 // c value + + return "x^2 + \(b)x + \(c)" } - + //finds the roots of the quadratic **NOTE**: the return type is [Int], not a String func getAnswer() -> [Int]{ - let d = Int(pow(Double(b), 2) - 4 * Double(a) * Double(c)) // discriminant - - // if d>0 , equation has two distinct real roots exist. - if d > 0 { - let x1 = Int((-Double(b) + sqrt(Double(d)))/(2*Double(a))) - let x2 = Int((-Double(b) - sqrt(Double(d)))/(2*Double(a))) - roots = [x1, x2] - } - //if d=0, equation has two repeated real roots. - else if d == 0 { - let x = Int(-Double(b)/(2*Double(a))) - roots = [x] - } - // if d<0 equation has two complex roots, but idk how to calculate that by hand, so we'll return nothing - else if d < 0 { - roots = [] - } + let roots = [root1, root2] return roots } + } From acfcdbed2452b1e9b57ac88677af166435677681 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 21 Jan 2021 14:27:27 -0500 Subject: [PATCH 2/4] Integrating PuzzleWakeMethod (1/2) --- .../AlarmActivationViewController.swift | 18 ++++++++- ProjectClock/Base.lproj/Main.storyboard | 40 ++++++++++++++++++- ProjectClock/NotificationLogic.swift | 6 ++- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/ProjectClock/AlarmActivationViewController.swift b/ProjectClock/AlarmActivationViewController.swift index 3e24a79..bad2d6f 100644 --- a/ProjectClock/AlarmActivationViewController.swift +++ b/ProjectClock/AlarmActivationViewController.swift @@ -13,6 +13,12 @@ class AlarmActivationViewController: UIViewController var timer: Timer? var currentAlarm: Alarm? + //Outlets + @IBOutlet weak var puzzleView: UIView! + @IBOutlet weak var puzzleQuestionLabel: UILabel! + @IBOutlet weak var puzzleAnswerInput: UITextField! + var puzzleAnswers: [Int] = [] + init?(coder: NSCoder, currentAlarm: Alarm) { self.currentAlarm = currentAlarm @@ -27,6 +33,9 @@ class AlarmActivationViewController: UIViewController override func viewDidLoad() { super.viewDidLoad() + //Hide all inactive wakemethods + puzzleView.isHidden = true + timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(AlarmActivationViewController.playSound), userInfo: nil, repeats: true) setAlarmType() print(MathExpression.random()) @@ -48,7 +57,8 @@ class AlarmActivationViewController: UIViewController case "Jump": jumpAction() case "Puzzle": - puzzleAction() + self.puzzleAnswers = puzzleAction(puzzleQuestionLabel: puzzleQuestionLabel) + puzzleView.isHidden = false case "Smash": print("") default: @@ -56,4 +66,10 @@ class AlarmActivationViewController: UIViewController } } } + + @IBAction func checkPuzzleSolution(_ sender: Any) { + if puzzleAnswers.contains(Int(puzzleAnswerInput.text!)!) { + print("alarm solved") + } + } } diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index b7099d7..98e9ab2 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -639,6 +639,36 @@ + + + + + + + + + + + + + + + + + + @@ -653,10 +683,15 @@ + + + + + - + @@ -692,6 +727,9 @@ + + + diff --git a/ProjectClock/NotificationLogic.swift b/ProjectClock/NotificationLogic.swift index 2f06fe5..8738f7d 100644 --- a/ProjectClock/NotificationLogic.swift +++ b/ProjectClock/NotificationLogic.swift @@ -8,6 +8,7 @@ import Foundation import CoreMotion import UserNotifications +import UIKit let motionManager = CMMotionManager() @@ -27,14 +28,15 @@ func jumpAction() { } -func puzzleAction() { +func puzzleAction(puzzleQuestionLabel: UILabel) -> [Int] { var problem = QuadraticProb() let answer = problem.getAnswer() let problemString = problem.getProblem() - print("Problem: \(problemString)") + puzzleQuestionLabel.text = "Solve: \(problemString)" print("Answer: \(answer)") + return answer } func smashAction() { From 431650c366099fdd805bf1c07dac2201b40226be Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 21 Jan 2021 14:27:31 -0500 Subject: [PATCH 3/4] Sorry! Again --- ProjectClock/MathExpressions.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectClock/MathExpressions.swift b/ProjectClock/MathExpressions.swift index 6c11aed..f3aa61b 100644 --- a/ProjectClock/MathExpressions.swift +++ b/ProjectClock/MathExpressions.swift @@ -118,7 +118,7 @@ let c = MathExpression.random() } } -class quadraticProb{ +class QuadraticProb{ //generates the roots let root1 = Int.random(in: 1...10)//ax^2 let root2 = Int.random(in: 1...10)//bx From e41c0ea0679a76d4734c25712d2104f855fb7ffd Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 21 Jan 2021 14:29:56 -0500 Subject: [PATCH 4/4] Revert "Merge branch 'main' of github.com:hykilpikonna/ProjectClock into main" This reverts commit ecd15bb30a1deabbce0d2808d166d6038d948179, reversing changes made to acfcdbed2452b1e9b57ac88677af166435677681. --- ProjectClock.xcodeproj/project.pbxproj | 8 ++-- .../AlarmActivationViewController.swift | 19 ++++---- ProjectClock/Base.lproj/Main.storyboard | 13 +----- ProjectClock/MathExpressions.swift | 43 +++++++++++++------ 4 files changed, 43 insertions(+), 40 deletions(-) diff --git a/ProjectClock.xcodeproj/project.pbxproj b/ProjectClock.xcodeproj/project.pbxproj index c348582..b96bbb0 100644 --- a/ProjectClock.xcodeproj/project.pbxproj +++ b/ProjectClock.xcodeproj/project.pbxproj @@ -10,10 +10,10 @@ 4F509BD225AE22D100726227 /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F509BD125AE22D100726227 /* Models.swift */; }; 4F8A607125A9160400D88DC3 /* AddAlarmViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F8A607025A9160400D88DC3 /* AddAlarmViewController.swift */; }; 4F98955225A9260400F51321 /* Net.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F98955125A9260400F51321 /* Net.swift */; }; - 4F9E458F25BA0558003F715D /* AlarmActivationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F9E458E25BA0558003F715D /* AlarmActivationViewController.swift */; }; 4FA419AF25AF93EC004CE0FC /* AlarmViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FA419AE25AF93EC004CE0FC /* AlarmViewController.swift */; }; 4FD642D325B48C380069171E /* AlarmActivator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD642D225B48C380069171E /* AlarmActivator.swift */; }; 4FD642DB25B4B7F60069171E /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD642DA25B4B7F60069171E /* Utils.swift */; }; + 4FD642E025B4D5F30069171E /* AlarmActivationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD642DF25B4D5F30069171E /* AlarmActivationViewController.swift */; }; 4FF0683F25A5F18700304E6B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF0683E25A5F18700304E6B /* AppDelegate.swift */; }; 4FF0684325A5F18700304E6B /* AccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF0684225A5F18700304E6B /* AccountViewController.swift */; }; 4FF0684625A5F18700304E6B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4FF0684425A5F18700304E6B /* Main.storyboard */; }; @@ -29,10 +29,10 @@ 4F509BD125AE22D100726227 /* Models.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Models.swift; sourceTree = ""; }; 4F8A607025A9160400D88DC3 /* AddAlarmViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddAlarmViewController.swift; sourceTree = ""; }; 4F98955125A9260400F51321 /* Net.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Net.swift; sourceTree = ""; }; - 4F9E458E25BA0558003F715D /* AlarmActivationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlarmActivationViewController.swift; sourceTree = ""; }; 4FA419AE25AF93EC004CE0FC /* AlarmViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlarmViewController.swift; sourceTree = ""; }; 4FD642D225B48C380069171E /* AlarmActivator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlarmActivator.swift; sourceTree = ""; }; 4FD642DA25B4B7F60069171E /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; + 4FD642DF25B4D5F30069171E /* AlarmActivationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlarmActivationViewController.swift; sourceTree = ""; }; 4FF0683B25A5F18700304E6B /* ProjectClock.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ProjectClock.app; sourceTree = BUILT_PRODUCTS_DIR; }; 4FF0683E25A5F18700304E6B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 4FF0684225A5F18700304E6B /* AccountViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountViewController.swift; sourceTree = ""; }; @@ -88,7 +88,7 @@ 4FF0684225A5F18700304E6B /* AccountViewController.swift */, 4FA419AE25AF93EC004CE0FC /* AlarmViewController.swift */, 4F8A607025A9160400D88DC3 /* AddAlarmViewController.swift */, - 4F9E458E25BA0558003F715D /* AlarmActivationViewController.swift */, + 4FD642DF25B4D5F30069171E /* AlarmActivationViewController.swift */, 4FF0684425A5F18700304E6B /* Main.storyboard */, 7C83963525AF375B0027A94C /* NotificationLogic.swift */, 4F98955125A9260400F51321 /* Net.swift */, @@ -183,7 +183,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4F9E458F25BA0558003F715D /* AlarmActivationViewController.swift in Sources */, 4F8A607125A9160400D88DC3 /* AddAlarmViewController.swift in Sources */, 4F98955225A9260400F51321 /* Net.swift in Sources */, 7C83963925AF68980027A94C /* TestingViewController.swift in Sources */, @@ -195,6 +194,7 @@ 4F509BD225AE22D100726227 /* Models.swift in Sources */, C7E638E825B88F8B00799512 /* MathExpressions.swift in Sources */, 7C83963625AF375B0027A94C /* NotificationLogic.swift in Sources */, + 4FD642E025B4D5F30069171E /* AlarmActivationViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ProjectClock/AlarmActivationViewController.swift b/ProjectClock/AlarmActivationViewController.swift index 3736f08..bad2d6f 100644 --- a/ProjectClock/AlarmActivationViewController.swift +++ b/ProjectClock/AlarmActivationViewController.swift @@ -12,41 +12,41 @@ class AlarmActivationViewController: UIViewController { var timer: Timer? var currentAlarm: Alarm? - + //Outlets @IBOutlet weak var puzzleView: UIView! @IBOutlet weak var puzzleQuestionLabel: UILabel! @IBOutlet weak var puzzleAnswerInput: UITextField! var puzzleAnswers: [Int] = [] - + init?(coder: NSCoder, currentAlarm: Alarm) { self.currentAlarm = currentAlarm //print(currentAlarm.wakeMethod) super.init(coder: coder) } - + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + override func viewDidLoad() { super.viewDidLoad() //Hide all inactive wakemethods puzzleView.isHidden = true - + timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(AlarmActivationViewController.playSound), userInfo: nil, repeats: true) setAlarmType() print(MathExpression.random()) } - + @objc func playSound() { AudioServicesPlayAlertSound(SystemSoundID(1005)) AudioServicesPlayAlertSound(kSystemSoundID_Vibrate) } - + func setAlarmType() { if let alarm = currentAlarm @@ -66,13 +66,10 @@ class AlarmActivationViewController: UIViewController } } } - + @IBAction func checkPuzzleSolution(_ sender: Any) { if puzzleAnswers.contains(Int(puzzleAnswerInput.text!)!) { print("alarm solved") } - @IBAction func debugForceStop(_ sender: Any) - { - timer?.invalidate() } } diff --git a/ProjectClock/Base.lproj/Main.storyboard b/ProjectClock/Base.lproj/Main.storyboard index ddedd48..98e9ab2 100644 --- a/ProjectClock/Base.lproj/Main.storyboard +++ b/ProjectClock/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -669,22 +669,13 @@ - - - diff --git a/ProjectClock/MathExpressions.swift b/ProjectClock/MathExpressions.swift index 6c11aed..d908330 100644 --- a/ProjectClock/MathExpressions.swift +++ b/ProjectClock/MathExpressions.swift @@ -2,7 +2,7 @@ // MathExpressions.swift // ProjectClock // -// MathElement +// Class that will generate a simple math expression import Foundation @@ -118,23 +118,38 @@ let c = MathExpression.random() } } -class quadraticProb{ - //generates the roots - let root1 = Int.random(in: 1...10)//ax^2 - let root2 = Int.random(in: 1...10)//bx - func getProblem() -> String{ - //a value is 1 - let b = root1 + root2 // b value - let c = root1 * root2 // c value - - return "x^2 + \(b)x + \(c)" - } +class QuadraticProb{ + let a = Int.random(in: 1...10)//ax^2 + let b = Int.random(in: 1...10)//bx + let c = Int.random(in: 1...10)//c + var roots = [Int]() + + + func getProblem() -> String{ + return "\(a)x^2 + \(b)x + \(c)" + } + //finds the roots of the quadratic **NOTE**: the return type is [Int], not a String func getAnswer() -> [Int]{ - let roots = [root1, root2] + let d = Int(pow(Double(b), 2) - 4 * Double(a) * Double(c)) // discriminant + + // if d>0 , equation has two distinct real roots exist. + if d > 0 { + let x1 = Int((-Double(b) + sqrt(Double(d)))/(2*Double(a))) + let x2 = Int((-Double(b) - sqrt(Double(d)))/(2*Double(a))) + roots = [x1, x2] + } + //if d=0, equation has two repeated real roots. + else if d == 0 { + let x = Int(-Double(b)/(2*Double(a))) + roots = [x] + } + // if d<0 equation has two complex roots, but idk how to calculate that by hand, so we'll return nothing + else if d < 0 { + roots = [] + } return roots } - }