Redesigned RPS class.

This commit is contained in:
Aaron
2021-01-22 13:18:00 -05:00
parent bf7e746aff
commit 6d0aa461c3
5 changed files with 24 additions and 15 deletions
@@ -57,7 +57,7 @@ class AlarmActivationViewController: UIViewController
case "Jump": case "Jump":
jumpAction() jumpAction()
case "Factor": case "Factor":
self.puzzleAnswers = puzzleAction(puzzleQuestionLabel: puzzleQuestionLabel) self.puzzleAnswers = factorAction(puzzleQuestionLabel: puzzleQuestionLabel)
puzzleView.isHidden = false puzzleView.isHidden = false
case "Smash": case "Smash":
print("") print("")
@@ -66,8 +66,9 @@ class AlarmActivationViewController: UIViewController
} }
} }
} }
@IBAction func checkPuzzleSolution(_ sender: Any) { //Verfies and ends factoring WVM
@IBAction func checkBinomialSolution(_ sender: Any) {
if let input = puzzleAnswerInput.text { if let input = puzzleAnswerInput.text {
if let numericalInput = Int(input) { if let numericalInput = Int(input) {
if puzzleAnswers.contains(numericalInput) { if puzzleAnswers.contains(numericalInput) {
@@ -77,6 +78,7 @@ class AlarmActivationViewController: UIViewController
} }
} }
//Standard way to turn off and close the alarm
func endAlarm() { func endAlarm() {
timer?.invalidate() timer?.invalidate()
print("Alarm solved") print("Alarm solved")
+1 -1
View File
@@ -656,7 +656,7 @@
<fontDescription key="fontDescription" type="system" pointSize="14"/> <fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" textContentType="cc-number"/> <textInputTraits key="textInputTraits" textContentType="cc-number"/>
<connections> <connections>
<action selector="checkPuzzleSolution:" destination="hDW-11-g9U" eventType="editingChanged" id="nuZ-mN-UR3"/> <action selector="checkBinomialSolution:" destination="hDW-11-g9U" eventType="editingChanged" id="nuZ-mN-UR3"/>
</connections> </connections>
</textField> </textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Input 1 answer:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vHe-pz-8w2"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Input 1 answer:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vHe-pz-8w2">
+9 -8
View File
@@ -181,16 +181,17 @@ class RPS {
} }
*/ */
func playRPS(you: Choice, computer: Choice) -> String { func playRPS(you: Choice, computer: Choice) -> Bool? {
if you == computer { return "It's a tie... GO AGAIN!" } if you == computer { return nil }
else if you == .rock && computer == .scissors { return "You smashed it!" } else if you == .rock && computer == .scissors { return true }
else if you == .paper && computer == .rock { return "We still don't know how you won..." } else if you == .paper && computer == .rock { return false}
else if you == .scissors && computer == .paper { return "You are Dwayne 'The Scissors' Johnson!" } else if you == .scissors && computer == .paper { return true }
else { else {
let randomNum = Int.random(in: 0...2) let randomNum = Int.random(in: 0...2)
if randomNum == 0 { return "Machines win again." } if randomNum == 0 { return false }
else if randomNum == 1 { return "Go back to robotics!" } // DO THESE RETURN THE RIGHT THING?
else { return "Are you even taking this seriously???" } else if randomNum == 1 { return false}
else { return false }
} }
} }
} }
+3 -2
View File
@@ -30,10 +30,11 @@ struct WVM: Codable
} }
let wvms = [ let wvms = [
WVM(name: "Walk", desc: "Walk a few steps"),
WVM(name: "Jump", desc: "Make a few jumps"),
WVM(name: "Factor", desc: "Factor a binomial"), WVM(name: "Factor", desc: "Factor a binomial"),
WVM(name: "RPS", desc: "Win a game of rock paper scissors"),
WVM(name: "Smash", desc: "It'll never truns off"), WVM(name: "Smash", desc: "It'll never truns off"),
WVM(name: "Walk", desc: "Walk a few steps"),
WVM(name: "Jump", desc: "Make a few jumps")
] ]
class Alarm: Codable class Alarm: Codable
+6 -1
View File
@@ -15,10 +15,15 @@ func walkAction() {
} }
func jumpAction() { func jumpAction() {
let rps = RPS()
}
func rpsAction() {
} }
func puzzleAction(puzzleQuestionLabel: UILabel) -> [Int] { // Handles the core logic behind the factoring alarm
func factorAction(puzzleQuestionLabel: UILabel) -> [Int] {
let problem = QuadraticProb() let problem = QuadraticProb()
let answer = problem.getAnswer() let answer = problem.getAnswer()