Redesigned RPS class.
This commit is contained in:
@@ -57,7 +57,7 @@ class AlarmActivationViewController: UIViewController
|
||||
case "Jump":
|
||||
jumpAction()
|
||||
case "Factor":
|
||||
self.puzzleAnswers = puzzleAction(puzzleQuestionLabel: puzzleQuestionLabel)
|
||||
self.puzzleAnswers = factorAction(puzzleQuestionLabel: puzzleQuestionLabel)
|
||||
puzzleView.isHidden = false
|
||||
case "Smash":
|
||||
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 numericalInput = Int(input) {
|
||||
if puzzleAnswers.contains(numericalInput) {
|
||||
@@ -77,6 +78,7 @@ class AlarmActivationViewController: UIViewController
|
||||
}
|
||||
}
|
||||
|
||||
//Standard way to turn off and close the alarm
|
||||
func endAlarm() {
|
||||
timer?.invalidate()
|
||||
print("Alarm solved")
|
||||
|
||||
@@ -656,7 +656,7 @@
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<textInputTraits key="textInputTraits" textContentType="cc-number"/>
|
||||
<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>
|
||||
</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">
|
||||
|
||||
@@ -181,16 +181,17 @@ class RPS {
|
||||
}
|
||||
*/
|
||||
|
||||
func playRPS(you: Choice, computer: Choice) -> String {
|
||||
if you == computer { return "It's a tie... GO AGAIN!" }
|
||||
else if you == .rock && computer == .scissors { return "You smashed it!" }
|
||||
else if you == .paper && computer == .rock { return "We still don't know how you won..." }
|
||||
else if you == .scissors && computer == .paper { return "You are Dwayne 'The Scissors' Johnson!" }
|
||||
func playRPS(you: Choice, computer: Choice) -> Bool? {
|
||||
if you == computer { return nil }
|
||||
else if you == .rock && computer == .scissors { return true }
|
||||
else if you == .paper && computer == .rock { return false}
|
||||
else if you == .scissors && computer == .paper { return true }
|
||||
else {
|
||||
let randomNum = Int.random(in: 0...2)
|
||||
if randomNum == 0 { return "Machines win again." }
|
||||
else if randomNum == 1 { return "Go back to robotics!" }
|
||||
else { return "Are you even taking this seriously???" }
|
||||
if randomNum == 0 { return false }
|
||||
// DO THESE RETURN THE RIGHT THING?
|
||||
else if randomNum == 1 { return false}
|
||||
else { return false }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,11 @@ struct WVM: Codable
|
||||
}
|
||||
|
||||
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: "RPS", desc: "Win a game of rock paper scissors"),
|
||||
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
|
||||
|
||||
@@ -15,10 +15,15 @@ func walkAction() {
|
||||
}
|
||||
|
||||
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 answer = problem.getAnswer()
|
||||
|
||||
Reference in New Issue
Block a user