diff --git a/ProjectClock/AlarmActivationLogic.swift b/ProjectClock/AlarmActivationLogic.swift index 1fbd7ae..cae9d45 100644 --- a/ProjectClock/AlarmActivationLogic.swift +++ b/ProjectClock/AlarmActivationLogic.swift @@ -27,11 +27,6 @@ func shakeAction() { } } -func rpsAction(choice: RPS.Choice) -> Bool? { - let rps = RPS() - return rps.playRPS(you: choice, computer: RPS.randomComputerChoice()) -} - // Handles the core logic behind the factoring alarm func factorAction(puzzleQuestionLabel: UILabel) -> [Int] { let problem = QuadraticProb() @@ -43,8 +38,3 @@ func factorAction(puzzleQuestionLabel: UILabel) -> [Int] { print("Answer: \(answer)") return answer } - -func smashAction() { - -} - diff --git a/ProjectClock/AlarmActivationViewController.swift b/ProjectClock/AlarmActivationViewController.swift index 16c5301..81b1c11 100644 --- a/ProjectClock/AlarmActivationViewController.swift +++ b/ProjectClock/AlarmActivationViewController.swift @@ -85,8 +85,6 @@ class AlarmActivationViewController: UIViewController */ func runAlarm() { - - if let alarm = currentAlarm { switch alarm.wakeMethod.name @@ -94,12 +92,8 @@ class AlarmActivationViewController: UIViewController case "Factor": self.puzzleAnswers = factorAction(puzzleQuestionLabel: puzzleQuestionLabel) puzzleView.isHidden = false - case "Smash": - print("") case "RPS": rpsView.isHidden = false - //Get Choice here - //rpsAction(choice: choice) case "Shake": shakeView.isHidden = false shakeAction() @@ -130,8 +124,15 @@ class AlarmActivationViewController: UIViewController */ @IBAction func rpsChoice(_ sender: UIButton) { - if rpsAction(choice: [.rock, .paper, .scissors][sender.tag])! { endAlarm() } - else { rpsResult.text = "\(["Paper", "Scissors", "Rock"][sender.tag]): You lost, try again" } + let rps = RPS() + if rps.playRPS(you: [.rock, .paper, .scissors][sender.tag], computer: RPS.choices.randomElement()!) + { + endAlarm() + } + else + { + rpsResult.text = "\(["Paper", "Scissors", "Rock"][sender.tag]): You lost, try again" + } } /** diff --git a/ProjectClock/MathExpressions.swift b/ProjectClock/MathExpressions.swift index a264d6a..765a70e 100644 --- a/ProjectClock/MathExpressions.swift +++ b/ProjectClock/MathExpressions.swift @@ -157,45 +157,26 @@ class QuadraticProb { } } -class RPS { - //@IBOutlet weak var resultsLabel: UILabel! +/** + Rock paper scissors + */ +class RPS +{ + static let choices: [Choice] = [.rock, .paper, .scissors] - enum Choice: String { - case rock = "ROCK" - case paper = "PAPER" - case scissors = "SCISSORS" + enum Choice: String + { + case rock = "Rock" + case paper = "Paper" + case scissors = "Scissors" } - static func randomComputerChoice() -> Choice { - let choices: [Choice] = [.rock, .paper, .scissors] - return choices[Int.random(in: 0...2)] + func playRPS(you: Choice, computer: Choice) -> Bool + { + return you == .rock && computer == .scissors || + you == .paper && computer == .rock || + you == .scissors && computer == .paper } - - func playRPS(you: Choice, computer: Choice) -> Bool? { - if you == .rock && computer == .scissors { return true } - else if you == .paper && computer == .rock { return true} - else if you == .scissors && computer == .paper { return true } - else { - return false - } - } - - /* - @IBAction func rock(_ sender: UIButton) { - let computerChoice = Choice.randomComputerChoice() - resultsLabel.text = playRPS(you: .rock, computer: computerChoice) - } - - @IBAction func paper(_ sender: UIButton) { - let computerChoice = Choice.randomComputerChoice() - resultsLabel.text = playRPS(you: .paper, computer: computerChoice) - } - - @IBAction func scissors(_ sender: UIButton) { - let computerChoice = Choice.randomComputerChoice() - resultsLabel.text = playRPS(you: .scissors, computer: computerChoice) - } - */ } /**