Skip to content
Snippets Groups Projects
Commit 9ee38d5a authored by Sixten Müller's avatar Sixten Müller
Browse files

bug: fixed startGame listener bug for player. Not tested.

parent d77f4fc5
Branches
No related tags found
2 merge requests!22Resolve "Create game model",!18Draft: Resolve "Create game model"
...@@ -291,6 +291,30 @@ public class AndroidInterfaceClass implements FirebaseInterface { ...@@ -291,6 +291,30 @@ public class AndroidInterfaceClass implements FirebaseInterface {
}); });
} }
public void startRound(String pin) {
DatabaseReference lobbyRef = database.getReference("lobbies").child(pin);
lobbyRef.child("roundStarted").setValue(true)
.addOnSuccessListener(aVoid -> {
System.out.println("Round started for lobby with pin: " + pin);
})
.addOnFailureListener(e -> {
System.err.println("Failed to start round for lobby: " + pin + ", error: " + e.getMessage());
});
}
@Override
public void resetRoundFlag(String pin) {
DatabaseReference lobbyRef = database.getReference("lobbies").child(pin);
lobbyRef.child("roundStarted").setValue(false)
.addOnSuccessListener(aVoid -> {
System.out.println("Round flag reset for lobby with pin: " + pin);
})
.addOnFailureListener(e -> {
System.err.println("Failed to reset round flag for lobby: " + pin + ", error: " + e.getMessage());
});
}
public void listenForGameStart(String pin, GameStartCallback callback) { public void listenForGameStart(String pin, GameStartCallback callback) {
DatabaseReference lobbyRef = database.getReference("lobbies").child(pin); DatabaseReference lobbyRef = database.getReference("lobbies").child(pin);
......
...@@ -37,6 +37,8 @@ public class GamePlayController { ...@@ -37,6 +37,8 @@ public class GamePlayController {
this.nickname = nickname; this.nickname = nickname;
this.gamePlayView = new GamePlayView(state.getCam(), _FBIC, pin); // Assuming you provide a getter for the camera in BaseState this.gamePlayView = new GamePlayView(state.getCam(), _FBIC, pin); // Assuming you provide a getter for the camera in BaseState
resetRoundFLag();
// Fetch the word using the PIN and the category // Fetch the word using the PIN and the category
fetchWord(); fetchWord();
...@@ -117,11 +119,13 @@ public class GamePlayController { ...@@ -117,11 +119,13 @@ public class GamePlayController {
} }
public void fetchRound() {
private void resetRoundFLag() {
_FBIC.resetRoundFlag(pin);
} }
public void fetchWord() { public void fetchWord() {
_FBIC.fetchRound(pin, new FirebaseInterface.RoundCallback() { _FBIC.fetchRound(pin, new FirebaseInterface.RoundCallback() {
@Override @Override
......
...@@ -46,12 +46,9 @@ public class LeaderBoardController { ...@@ -46,12 +46,9 @@ public class LeaderBoardController {
private void listenForRoundStarted() { private void listenForRoundStarted() {
// Assuming _FBIC is your FirebaseInterface instance and pin is your game's pin // Assuming _FBIC is your FirebaseInterface instance and pin is your game's pin
_FBIC.listenForRoundStarted(pin, new Runnable() { _FBIC.listenForRoundStarted(pin, () -> {
@Override
public void run() {
// This code will be executed when the round starts flag is set to true // This code will be executed when the round starts flag is set to true
Gdx.app.postRunnable(() -> startNewRound()); Gdx.app.postRunnable(this::startNewRound);
}
}); });
} }
...@@ -99,6 +96,7 @@ public class LeaderBoardController { ...@@ -99,6 +96,7 @@ public class LeaderBoardController {
state.getCam().unproject(touchPos); // convert from screen coordinates to world coordinates state.getCam().unproject(touchPos); // convert from screen coordinates to world coordinates
if(leaderBoardView.isHost()) { if(leaderBoardView.isHost()) {
if (leaderBoardView.getNextRoundBounds().contains(touchPos.x, touchPos.y)) { if (leaderBoardView.getNextRoundBounds().contains(touchPos.x, touchPos.y)) {
_FBIC.startRound(pin); // Stasrt the round
state.getStateManager().setState(new GamePlayState(state.getStateManager(), _FBIC, pin, nickname)); state.getStateManager().setState(new GamePlayState(state.getStateManager(), _FBIC, pin, nickname));
} }
} }
......
...@@ -22,6 +22,10 @@ public interface FirebaseInterface { ...@@ -22,6 +22,10 @@ public interface FirebaseInterface {
void isHost(String pin, String nickname, HostCheckCallback callback); void isHost(String pin, String nickname, HostCheckCallback callback);
void startRound(String pin);
void resetRoundFlag(String pin);
interface HostCheckCallback { interface HostCheckCallback {
void onHostCheckResult(boolean isHost); void onHostCheckResult(boolean isHost);
void onError(String error); void onError(String error);
......
...@@ -62,6 +62,10 @@ public class FirebaseManager implements FirebaseInterface { ...@@ -62,6 +62,10 @@ public class FirebaseManager implements FirebaseInterface {
} }
@Override
public void startRound(String pin) {
}
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment