Theoretical RPS WVM completed

This commit is contained in:
Aaron
2021-01-23 17:09:31 -05:00
parent 5b576a7912
commit 2a9cb8e677
3 changed files with 60 additions and 4 deletions
@@ -13,12 +13,17 @@ class AlarmActivationViewController: UIViewController
var timer: Timer?
var currentAlarm: Alarm?
//Outlets
//Puzzle outlets
@IBOutlet weak var puzzleView: UIView!
@IBOutlet weak var puzzleQuestionLabel: UILabel!
@IBOutlet weak var puzzleAnswerInput: UITextField!
var puzzleAnswers: [Int] = []
//RPS Outlets
@IBOutlet weak var rpsView: UIView!
@IBOutlet weak var rpsResult: UILabel!
init?(coder: NSCoder, currentAlarm: Alarm)
{
self.currentAlarm = currentAlarm
@@ -35,6 +40,7 @@ class AlarmActivationViewController: UIViewController
super.viewDidLoad()
//Hide all inactive wakemethods
puzzleView.isHidden = true
rpsView.isHidden = true
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(AlarmActivationViewController.playSound), userInfo: nil, repeats: true)
setAlarmType()
@@ -61,6 +67,10 @@ class AlarmActivationViewController: UIViewController
puzzleView.isHidden = false
case "Smash":
print("")
case "RPS":
rpsView.isHidden = false
//Get Choice here
//rpsAction(choice: choice)
default:
print("Invalid alarm type")
}
@@ -78,6 +88,31 @@ class AlarmActivationViewController: UIViewController
}
}
//Gets RPS choice
@IBAction func rockChoice(_ sender: Any) {
if rpsAction(choice: .rock)! {
endAlarm()
} else {
rpsResult.text = "Paper: You lost, try again"
}
}
@IBAction func paperChoice(_ sender: Any) {
if rpsAction(choice: .paper)! {
endAlarm()
} else {
rpsResult.text = "Scissors: You lost, try again"
}
}
@IBAction func scissorChoice(_ sender: Any) {
if rpsAction(choice: .scissors)! {
endAlarm()
} else {
rpsResult.text = "Rock: You lost, try again"
}
}
//Standard way to turn off and close the alarm
func endAlarm() {
timer?.invalidate()
+23 -2
View File
@@ -553,27 +553,43 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" fixedFrame="YES" spacing="64" translatesAutoresizingMaskIntoConstraints="NO" id="213-rS-oYj">
<rect key="frame" x="19" y="19" width="336" height="42"/>
<rect key="frame" x="19" y="134" width="336" height="42"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ndj-R4-AKk">
<rect key="frame" x="0.0" y="0.0" width="55" height="42"/>
<fontDescription key="fontDescription" type="system" pointSize="25"/>
<state key="normal" title="Rock"/>
<connections>
<action selector="rockChoice:" destination="hDW-11-g9U" eventType="touchUpInside" id="w4O-MC-ohr"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Iiv-Co-j8G">
<rect key="frame" x="119" y="0.0" width="62" height="42"/>
<fontDescription key="fontDescription" type="system" pointSize="25"/>
<state key="normal" title="Paper"/>
<connections>
<action selector="paperChoice:" destination="hDW-11-g9U" eventType="touchUpInside" id="giR-wy-jqv"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="U4y-ls-yuK">
<rect key="frame" x="245" y="0.0" width="91" height="42"/>
<fontDescription key="fontDescription" type="system" pointSize="25"/>
<state key="normal" title="Scissors"/>
<connections>
<action selector="scissorChoice:" destination="hDW-11-g9U" eventType="touchUpInside" id="BVu-ST-Hfr"/>
</connections>
</button>
</subviews>
</stackView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="RPS: What do you choose?" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="HEP-oh-VSY">
<rect key="frame" x="31" y="8" width="313" height="33"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="27"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" systemColor="systemGray6Color"/>
<color key="backgroundColor" systemColor="systemGray4Color"/>
</view>
</subviews>
<viewLayoutGuide key="safeArea" id="hS6-fS-yWp"/>
@@ -593,6 +609,8 @@
<outlet property="puzzleAnswerInput" destination="eTb-g7-8x3" id="xIh-TJ-vhq"/>
<outlet property="puzzleQuestionLabel" destination="CZ0-R6-FDq" id="gon-N6-XTD"/>
<outlet property="puzzleView" destination="OMQ-qK-fej" id="KLT-oe-RJX"/>
<outlet property="rpsResult" destination="HEP-oh-VSY" id="W2G-eZ-mzI"/>
<outlet property="rpsView" destination="NmX-iJ-1D0" id="Rhg-Hm-2Xx"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="78q-sr-CNz" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
@@ -807,6 +825,9 @@
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemGray4Color">
<color red="0.81960784313725488" green="0.81960784313725488" blue="0.83921568627450982" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemGray6Color">
<color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
+1 -1
View File
@@ -58,7 +58,7 @@ class TestingViewController: UIViewController
@IBAction func addAlarm(_ sender: Any)
{
let (h, m, _) = Date().getHMS()
Alarms.fromLocal().apply { $0.list.append(Alarm(hour: h, minute: m, text: "Test alarm - \(h * m)", wakeMethod: wvms[0], lastActivate: Date().added(.minute, -1))) }.localSave()
Alarms.fromLocal().apply { $0.list.append(Alarm(hour: h, minute: m, text: "Test alarm - \(h * m)", wakeMethod: wvms[1], lastActivate: Date().added(.minute, -1))) }.localSave()
}
@IBAction func deleteAlarm(_ sender: Any)