[O] Optimize factoring problem initialization
This commit is contained in:
@@ -26,15 +26,3 @@ func shakeAction() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles the core logic behind the factoring alarm
|
|
||||||
func factorAction(puzzleQuestionLabel: UILabel) -> [Int] {
|
|
||||||
let problem = QuadraticProb()
|
|
||||||
|
|
||||||
let answer = problem.getAnswer()
|
|
||||||
let problemString = problem.getProblem()
|
|
||||||
|
|
||||||
puzzleQuestionLabel.text = "Solve: \(problemString)"
|
|
||||||
print("Answer: \(answer)")
|
|
||||||
return answer
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class AlarmActivationViewController: UIViewController
|
|||||||
switch alarm.wakeMethod.name
|
switch alarm.wakeMethod.name
|
||||||
{
|
{
|
||||||
case "Factor":
|
case "Factor":
|
||||||
self.puzzleAnswers = factorAction(puzzleQuestionLabel: puzzleQuestionLabel)
|
initFactorProblem()
|
||||||
puzzleView.show()
|
puzzleView.show()
|
||||||
case "RPS":
|
case "RPS":
|
||||||
rpsView.show()
|
rpsView.show()
|
||||||
@@ -106,16 +106,25 @@ class AlarmActivationViewController: UIViewController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initFactorProblem()
|
||||||
|
{
|
||||||
|
let problem = QuadraticProb()
|
||||||
|
puzzleAnswers = problem.getAnswer()
|
||||||
|
|
||||||
|
puzzleQuestionLabel.text = "Solve: \(problem.getProblem())"
|
||||||
|
print("Answer: \(puzzleAnswers)")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Verfies and ends factoring WVM
|
Verfies and ends factoring WVM
|
||||||
*/
|
*/
|
||||||
@IBAction func checkBinomialSolution(_ sender: Any) {
|
@IBAction func checkBinomialSolution(_ sender: Any)
|
||||||
if let input = puzzleAnswerInput.text {
|
{
|
||||||
if let numericalInput = Int(input) {
|
if let input = puzzleAnswerInput.text,
|
||||||
if puzzleAnswers.contains(numericalInput) {
|
let numericalInput = Int(input),
|
||||||
endAlarm()
|
puzzleAnswers.contains(numericalInput)
|
||||||
}
|
{
|
||||||
}
|
endAlarm()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,8 +133,7 @@ class AlarmActivationViewController: UIViewController
|
|||||||
*/
|
*/
|
||||||
@IBAction func rpsChoice(_ sender: UIButton)
|
@IBAction func rpsChoice(_ sender: UIButton)
|
||||||
{
|
{
|
||||||
let rps = RPS()
|
if RPS.playRPS(you: [.rock, .paper, .scissors][sender.tag], computer: RPS.choices.randomElement()!)
|
||||||
if rps.playRPS(you: [.rock, .paper, .scissors][sender.tag], computer: RPS.choices.randomElement()!)
|
|
||||||
{
|
{
|
||||||
endAlarm()
|
endAlarm()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ class RPS
|
|||||||
case scissors = "Scissors"
|
case scissors = "Scissors"
|
||||||
}
|
}
|
||||||
|
|
||||||
func playRPS(you: Choice, computer: Choice) -> Bool
|
static func playRPS(you: Choice, computer: Choice) -> Bool
|
||||||
{
|
{
|
||||||
return you == .rock && computer == .scissors ||
|
return you == .rock && computer == .scissors ||
|
||||||
you == .paper && computer == .rock ||
|
you == .paper && computer == .rock ||
|
||||||
|
|||||||
Reference in New Issue
Block a user