Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessamae23 committed Apr 8, 2024
1 parent 66343c3 commit 85345cf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<!--GameViewController-->
<scene sceneID="tXr-a1-R10">
<objects>
<viewController storyboardIdentifier="GameViewController" title="GameViewController" wantsFullScreenLayout="YES" modalPresentationStyle="fullScreen" id="BV1-FR-VrT" customClass="GameViewController" customModule="TowerForge" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="GameViewController" title="GameViewController" wantsFullScreenLayout="YES" modalPresentationStyle="fullScreen" useStoryboardIdentifierAsRestorationIdentifier="YES" id="BV1-FR-VrT" customClass="GameViewController" customModule="TowerForge" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" multipleTouchEnabled="YES" contentMode="scaleToFill" id="3se-qz-xqx" customClass="SKView">
<rect key="frame" x="0.0" y="0.0" width="1366" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -400,8 +400,7 @@ Match</string>
<navigationItem key="navigationItem" id="RIh-Gm-msf"/>
<connections>
<outlet property="ListStackView" destination="FSQ-sC-jDO" id="21H-Es-ph1"/>
<outlet property="startButton" destination="95L-Ms-1Jv" id="Hsc-Qq-ETX"/>
<segue destination="BV1-FR-VrT" kind="show" identifier="segueToGame" id="22u-0c-ugI"/>
<outlet property="startButton" destination="95L-Ms-1Jv" id="1ak-OX-1gU"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="srP-KJ-HWs" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
Expand Down Expand Up @@ -429,9 +428,6 @@ Match</string>
<point key="canvasLocation" x="-684" y="-814"/>
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="22u-0c-ugI"/>
</inferredMetricsTieBreakers>
<resources>
<image name="Flag" width="500" height="500"/>
<image name="Sword" width="500" height="500"/>
Expand Down
11 changes: 11 additions & 0 deletions TowerForge/TowerForge/Networking/RoomNetwork/GameRoom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ class GameRoom {
completion(.waitingForFinalConfirmation)
}
}
func deleteRoom() {
if roomState == .gameOnGoing {
roomRef.child(roomName).removeValue { error, _ in
if let error = error {
print("Error deleting room: \(error.localizedDescription)")
} else {
print("Room deleted successfully.")
}
}
}
}

// Updates the current room state in the class and database
private func updateRoomState(roomState: RoomState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class GameRoomViewController: UIViewController {
}

let playerOne = GamePlayer(userName: playerName)
print("Attempting to make a room")
gameRoom = GameRoom(roomName: roomName) { success in
if success {
print("Now joining the room \(success)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class GameWaitingRoomViewController: UIViewController {

@IBOutlet private var startButton: UIButton!
deinit {
gameRoom?.deleteRoom()
gameRoom = nil
currentPlayer = nil
print("deinit")
Expand All @@ -37,7 +38,7 @@ class GameWaitingRoomViewController: UIViewController {

@IBAction private func onStartButtonPressed(_ sender: Any) {
gameRoom?.updatePlayerReady { _ in
self.startButton.isEnabled = false
self.startButton.isHidden = true
}
}

Expand Down Expand Up @@ -69,7 +70,12 @@ class GameWaitingRoomViewController: UIViewController {
ListStackView.addArrangedSubview(playerTwoView)
}
if gameRoom?.roomState == .gameOnGoing {
self.performSegue(withIdentifier: "segueToGame", sender: self)
guard let gameViewController = self.storyboard?.instantiateViewController(withIdentifier: "GameViewController")
as? GameViewController else {
return
}
self.present(gameViewController, animated: true)
gameRoom?.deleteRoom()
}
}

Expand Down

0 comments on commit 85345cf

Please sign in to comment.