Skip to content
Snippets Groups Projects
Commit d9af7890 authored by Turid Cecilie Dahl's avatar Turid Cecilie Dahl
Browse files

#81 added roundCheck

parent 04ebcfc5
No related branches found
No related tags found
1 merge request!78Resolve "Add checkound into frontend"
...@@ -31,7 +31,7 @@ import java.util.TimeZone; ...@@ -31,7 +31,7 @@ import java.util.TimeZone;
public class QueryIntermediate { public class QueryIntermediate {
private static String baseUrl = "https://gameware.herokuapp.com/api/"; private static String baseUrl = "http://192.168.1.142:3002/api/";
private static Json json = new Json(); private static Json json = new Json();
private static JsonReader jsonReader = new JsonReader(); private static JsonReader jsonReader = new JsonReader();
......
...@@ -18,6 +18,7 @@ import com.badlogic.gdx.utils.Scaling; ...@@ -18,6 +18,7 @@ import com.badlogic.gdx.utils.Scaling;
import com.gameware.game.GameWare; import com.gameware.game.GameWare;
import com.gameware.game.QueryIntermediate; import com.gameware.game.QueryIntermediate;
import com.gameware.game.models.Round; import com.gameware.game.models.Round;
import com.gameware.game.models.RoundCheck;
import com.gameware.game.models.Tournament; import com.gameware.game.models.Tournament;
import com.gameware.game.sprites.LoadingText; import com.gameware.game.sprites.LoadingText;
...@@ -139,7 +140,7 @@ public class CreateJoinTournamentState extends State { ...@@ -139,7 +140,7 @@ public class CreateJoinTournamentState extends State {
private Table createTournamentList(){ private Table createTournamentList(){
Table innerTable = new Table(); Table innerTable = new Table();
innerTable.setBackground(makeColorBackground(scrollPaneBGColor)); innerTable.setBackground(makeColorBackground(scrollPaneBGColor));
innerTable.defaults().space(spacingLittle); innerTable.defaults().space(spacingLittle).expandY();
innerTable.pad(spacingLittle).padRight(spacingLittle); innerTable.pad(spacingLittle).padRight(spacingLittle);
if(!tournaments.isEmpty()) { if(!tournaments.isEmpty()) {
...@@ -260,6 +261,7 @@ public class CreateJoinTournamentState extends State { ...@@ -260,6 +261,7 @@ public class CreateJoinTournamentState extends State {
this.joinButtonClicked = false; this.joinButtonClicked = false;
} }
this.loadingText.update(dt); this.loadingText.update(dt);
} }
...@@ -314,12 +316,29 @@ public class CreateJoinTournamentState extends State { ...@@ -314,12 +316,29 @@ public class CreateJoinTournamentState extends State {
private void handleEnterBtnClick(Tournament t, Round r){ private void handleEnterBtnClick(Tournament t, Round r){
if(GameWare.getInstance().getSoundEffects()){ buttonPressSound.play(); } if(GameWare.getInstance().getSoundEffects()){ buttonPressSound.play(); }
if(!t.isActive()){ if(!t.isActive()){
gsm.set(new FinishedTournamentState(gsm,t)); gsm.set(new FinishedTournamentState(gsm,t));
} }
else{ else{
RoundCheck rc = null;
try {
rc = QueryIntermediate.doRoundCheck(t.get_id());
}catch(IOException e){
e.printStackTrace();
}
if(rc != null){
if(!rc.isActive()) {
FinishedTournamentState s = new FinishedTournamentState(gsm, t);
s.makeDialogTimeOut();
gsm.set(s);
}else{
gsm.set(new ViewTournamentState(gsm, t, r)); gsm.set(new ViewTournamentState(gsm, t, r));
} }
} else {
gsm.set(new ViewTournamentState(gsm, t, r));
}
}
} }
private void handleLeaveBtnClick(Tournament t){ private void handleLeaveBtnClick(Tournament t){
......
...@@ -34,12 +34,13 @@ public class FinishedTournamentState extends State { ...@@ -34,12 +34,13 @@ public class FinishedTournamentState extends State {
private final String leaveBtnText = "Leave"; private final String leaveBtnText = "Leave";
private final String winnerText = "Winner: "; private final String winnerText = "Winner: ";
private final String leaveDialogText = "Are you sure want to\nleave "; private final String leaveDialogText = "Are you sure want to\nleave ";
private final String dialogTimeOutText = "Tournament finished because\nplayers timed out";
// Variables // Variables
private final int padding = 50;
private final Color scrollPaneBGColor = Color.GOLD; private final Color scrollPaneBGColor = Color.GOLD;
private Dialog dialog; private Dialog dialog;
private Dialog dialogTimeOut;
public FinishedTournamentState(GameStateManager gsm, Tournament tournament) { public FinishedTournamentState(GameStateManager gsm, Tournament tournament) {
...@@ -127,6 +128,13 @@ public class FinishedTournamentState extends State { ...@@ -127,6 +128,13 @@ public class FinishedTournamentState extends State {
dialog.button("No", false).pad(padding); //sends "false" as the result dialog.button("No", false).pad(padding); //sends "false" as the result
} }
public void makeDialogTimeOut(){
dialogTimeOut = new Dialog("", skin, "dialog");
dialogTimeOut.text(dialogTimeOutText).pad(padding);
dialogTimeOut.button("Okay", false).pad(padding); //sends "false" as the result
dialogTimeOut.show(stage);
}
private TextButton makeBackBtn(){ private TextButton makeBackBtn(){
TextButton backBtn = new TextButton(backBtnText, skin); TextButton backBtn = new TextButton(backBtnText, skin);
backBtn.addListener(new ClickListener() { backBtn.addListener(new ClickListener() {
......
...@@ -22,7 +22,7 @@ public abstract class PlayStateTemplate extends State { ...@@ -22,7 +22,7 @@ public abstract class PlayStateTemplate extends State {
private Round updatedRound = null; private Round updatedRound = null;
private PauseButton pauseButton; private PauseButton pauseButton;
private LoadingText loadingText = new LoadingText(); private LoadingText loadingText = new LoadingText();
protected float totalGameTime = 30f; protected float totalGameTime = 5f;
protected Texture screenshot = null; protected Texture screenshot = null;
public PlayStateTemplate(GameStateManager gsm){ public PlayStateTemplate(GameStateManager gsm){
......
...@@ -16,9 +16,12 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; ...@@ -16,9 +16,12 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.gameware.game.GameWare; import com.gameware.game.GameWare;
import com.gameware.game.QueryIntermediate; import com.gameware.game.QueryIntermediate;
import com.gameware.game.models.Round; import com.gameware.game.models.Round;
import com.gameware.game.models.RoundCheck;
import com.gameware.game.models.Tournament; import com.gameware.game.models.Tournament;
import com.gameware.game.sprites.LoadingText; import com.gameware.game.sprites.LoadingText;
import java.io.IOException;
public class ViewTournamentState extends State { public class ViewTournamentState extends State {
// Data // Data
...@@ -236,11 +239,31 @@ public class ViewTournamentState extends State { ...@@ -236,11 +239,31 @@ public class ViewTournamentState extends State {
private void handlePlayBtnClick(){ private void handlePlayBtnClick(){
if(GameWare.getInstance().getSoundEffects()){ buttonPressSound.play(); } if(GameWare.getInstance().getSoundEffects()){ buttonPressSound.play(); }
RoundCheck rc = null;
try {
rc = QueryIntermediate.doRoundCheck(tournament.get_id());
}catch(IOException e){
e.printStackTrace();
}
if(rc != null){
if(!rc.isActive()) {
FinishedTournamentState s = new FinishedTournamentState(gsm, tournament);
s.makeDialogTimeOut();
gsm.set(s);
}else{
PlayStateTemplate state = GameWare.getInstance().getGameIdToPlayState().get(round.getGameId()); PlayStateTemplate state = GameWare.getInstance().getGameIdToPlayState().get(round.getGameId());
state.setTournament(tournament); state.setTournament(tournament);
state.setRound(round); state.setRound(round);
gsm.set(state); gsm.set(state);
} }
} else {
PlayStateTemplate state = GameWare.getInstance().getGameIdToPlayState().get(round.getGameId());
state.setTournament(tournament);
state.setRound(round);
gsm.set(state);
}
}
private void handleViewPointsBtnClick(){ private void handleViewPointsBtnClick(){
if(GameWare.getInstance().getSoundEffects()){ buttonPressSound.play(); } if(GameWare.getInstance().getSoundEffects()){ buttonPressSound.play(); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment