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

#38 added ViewTournamentState and hashmap in GameWare

parent 8f40c311
No related branches found
No related tags found
1 merge request!37Resolve "ViewTournamentState"
...@@ -5,13 +5,18 @@ import com.badlogic.gdx.Gdx; ...@@ -5,13 +5,18 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gameware.game.models.Player; import com.gameware.game.models.Player;
import com.gameware.game.states.ColorRushState;
import com.gameware.game.states.CreateJoinTournamentState; import com.gameware.game.states.CreateJoinTournamentState;
import com.gameware.game.states.GameStateManager; import com.gameware.game.states.GameStateManager;
import com.gameware.game.states.MenuState; import com.gameware.game.states.MenuState;
import com.gameware.game.states.State;
import com.gameware.game.states.ViewHighScoreState; import com.gameware.game.states.ViewHighScoreState;
import com.gameware.game.states.ViewTournamentState; import com.gameware.game.states.ViewTournamentState;
import com.gameware.game.states.LoginState; import com.gameware.game.states.LoginState;
import java.util.HashMap;
import java.util.Map;
public class GameWare extends ApplicationAdapter { public class GameWare extends ApplicationAdapter {
private SpriteBatch batch; private SpriteBatch batch;
private GameStateManager gsm; private GameStateManager gsm;
...@@ -21,6 +26,7 @@ public class GameWare extends ApplicationAdapter { ...@@ -21,6 +26,7 @@ public class GameWare extends ApplicationAdapter {
public static final String TITLE = "WackyWare!"; public static final String TITLE = "WackyWare!";
public static final String skinFilePath = "glassy/skin/glassy-ui.json"; public static final String skinFilePath = "glassy/skin/glassy-ui.json";
private Player player; private Player player;
public static Map<String, State> gameIdToPlayState = new HashMap<>();
// TODO: Add music // TODO: Add music
private static GameWare instance = null; private static GameWare instance = null;
...@@ -35,6 +41,10 @@ public class GameWare extends ApplicationAdapter { ...@@ -35,6 +41,10 @@ public class GameWare extends ApplicationAdapter {
@Override @Override
public void create () { public void create () {
gsm = GameStateManager.getInstance(); gsm = GameStateManager.getInstance();
gameIdToPlayState.put("5e5d0efaa6e2bc5cb4920b7a", new ColorRushState(gsm));
//gameIdToPlayState.put("5e5d0f1ea6e2bc5cb4920b7b", new BubbleWrapState(gsm));
batch = new SpriteBatch(); batch = new SpriteBatch();
//music = Gdx.audio.newMusic(Gdx.files.internal(("music.mp3"))); //music = Gdx.audio.newMusic(Gdx.files.internal(("music.mp3")));
//music.setLooping(true); //music.setLooping(true);
......
...@@ -24,6 +24,15 @@ public class Tournament { ...@@ -24,6 +24,15 @@ public class Tournament {
public Tournament() { public Tournament() {
} }
//Just testing delete afterwards
public Tournament(String _id, String name, List<String> players, int roundsPerGame, int currentRound) {
this._id = _id;
this.name = name;
this.players = players;
this.roundsPerGame = roundsPerGame;
this.currentRound = currentRound;
}
//Just testing delete afterwards //Just testing delete afterwards
public Tournament(String _id, String name) { public Tournament(String _id, String name) {
this._id = _id; this._id = _id;
......
...@@ -8,6 +8,8 @@ import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; ...@@ -8,6 +8,8 @@ import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.gameware.game.GameWare;
import com.gameware.game.models.Player;
import com.gameware.game.models.Tournament; import com.gameware.game.models.Tournament;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -54,15 +56,19 @@ public class CreateJoinTournamentState extends State { ...@@ -54,15 +56,19 @@ public class CreateJoinTournamentState extends State {
public CreateJoinTournamentState(GameStateManager gsm) { public CreateJoinTournamentState(GameStateManager gsm) {
super(gsm); super(gsm);
System.out.println("Du er i create join tournament state :0"); System.out.println("Du er i create join tournament state :0");
tournaments.add(new Tournament("id1", "Tournament 1")); List<String> players = new ArrayList<>();
tournaments.add(new Tournament("id2", "Beste tournament!!")); players.add("Kari");
tournaments.add(new Tournament("id3", "La oss spille >:D")); players.add("Bob");
tournaments.add(new Tournament("id4", "Tournament 4")); players.add("Blåruss");
tournaments.add(new Tournament("id5", "Tournament 5")); tournaments.add(new Tournament("id1", "Tournament 1", players, 5, 3));
tournaments.add(new Tournament("id6", "Tournament 6")); tournaments.add(new Tournament("id2", "Beste tournament!!", players, 5, 3));
tournaments.add(new Tournament("id7", "Tournament 7")); tournaments.add(new Tournament("id3", "La oss spille >:D", players, 5, 3));
tournaments.add(new Tournament("id8", "Tournament 8")); tournaments.add(new Tournament("id4", "Tournament 4", players, 5, 3));
tournaments.add(new Tournament("id9", "Tournament 9")); tournaments.add(new Tournament("id5", "Tournament 5", players, 5, 3));
tournaments.add(new Tournament("id6", "Tournament 6", players, 5, 3));
tournaments.add(new Tournament("id7", "Tournament 7", players, 5, 3));
tournaments.add(new Tournament("id8", "Tournament 8", players, 5, 3));
tournaments.add(new Tournament("id9", "Tournament 9", players, 5, 3));
try{ try{
// tournaments = QueryIntermediate.getTournamentsForPlayer(GameWare.getPlayer().getId()); // tournaments = QueryIntermediate.getTournamentsForPlayer(GameWare.getPlayer().getId());
}catch(Exception e){ }catch(Exception e){
...@@ -175,7 +181,7 @@ public class CreateJoinTournamentState extends State { ...@@ -175,7 +181,7 @@ public class CreateJoinTournamentState extends State {
private void handleEnterBtnClick(Tournament t){ private void handleEnterBtnClick(Tournament t){
System.out.println("Entered tournament with id = "+ t.get_id()); System.out.println("Entered tournament with id = "+ t.get_id());
gsm.set(new ViewTournamentState(gsm)); gsm.set(new ViewTournamentState(gsm, t));
} }
private void handleLeaveBtnClick(Tournament t){ private void handleLeaveBtnClick(Tournament t){
......
...@@ -2,25 +2,46 @@ package com.gameware.game.states; ...@@ -2,25 +2,46 @@ package com.gameware.game.states;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.gameware.game.GameWare;
import com.gameware.game.models.Round;
import com.gameware.game.models.Tournament;
public class ViewTournamentState extends State { public class ViewTournamentState extends State {
private Table table; private Table table;
private Tournament tournament;
private String backBtnText = "Back"; private String backBtnText = "Back";
private String playBtnText = "Play Round";
private String viewPointsBtnText = "View Points";
private String nrPlayersText = "Players in tournament";
private String roundsLeftText = "Rounds left";
public ViewTournamentState(GameStateManager gsm) { public ViewTournamentState(GameStateManager gsm, Tournament tournament) {
super(gsm); super(gsm);
System.out.println("Du er i view tournament state :0"); System.out.println("Du er i view tournament state :0");
this.tournament = tournament;
table = new Table(); table = new Table();
table.setFillParent(true); table.setFillParent(true);
table.row(); table.row();
table.add(makeBackBtn()); table.add(new Label(tournament.getName(), skin)).spaceBottom(spacingOnBottomInputFIeld);
table.row();
table.add(makePlayBtn()).spaceBottom(spacingOnBottomInputFIeld);
table.row();
table.add(new Label(nrPlayersText+" "+tournament.getPlayers().size(), skin));
table.row();
table.add(new Label(roundsLeftText+" "+(tournament.getRoundsPerGame()-tournament.getCurrentRound()), skin)).spaceBottom(spacingOnBottomInputFIeld);
table.row();
Table innerTable = new Table();
innerTable.add(makeBackBtn());
innerTable.add(makeViewPointsBtn());
table.add(innerTable);
stage.addActor(table); stage.addActor(table);
} }
...@@ -36,10 +57,30 @@ public class ViewTournamentState extends State { ...@@ -36,10 +57,30 @@ public class ViewTournamentState extends State {
return backBtn; return backBtn;
} }
private TextButton makePlayBtn(){
TextButton playBtn = new TextButton(playBtnText, skin);
playBtn.addListener(new ClickListener() {
@Override @Override
protected void handleInput() { public void clicked(InputEvent e, float x, float y){
handlePlayBtnClick();
}
});
return playBtn;
}
private TextButton makeViewPointsBtn(){
TextButton viewPoints = new TextButton(viewPointsBtnText, skin);
viewPoints.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){
handleViewPointsBtnClick();
} }
});
return viewPoints;
}
@Override
protected void handleInput() { }
@Override @Override
public void update(float dt) { public void update(float dt) {
...@@ -57,9 +98,7 @@ public class ViewTournamentState extends State { ...@@ -57,9 +98,7 @@ public class ViewTournamentState extends State {
} }
@Override @Override
public void reset() { public void reset() { }
}
@Override @Override
public Object report() { public Object report() {
...@@ -69,4 +108,18 @@ public class ViewTournamentState extends State { ...@@ -69,4 +108,18 @@ public class ViewTournamentState extends State {
private void handleBackBtnClick(){ private void handleBackBtnClick(){
gsm.set(new CreateJoinTournamentState(gsm)); gsm.set(new CreateJoinTournamentState(gsm));
} }
private void handlePlayBtnClick(){
try{
// Round round = QueryIntermediate.getRoundFromTournament(tournament.get_id(), GameWare.getInstance().getPlayer(), tournament.getCurrentRound());
// gsm.set(GameWare.gameIdToPlayState.get(round.getGameId()));
gsm.set(GameWare.gameIdToPlayState.get("5e5d0efaa6e2bc5cb4920b7a"));
}catch(Exception e){
System.out.println(e);
}
}
private void handleViewPointsBtnClick(){
// gsm.set(TournamentHighScoreState(gsm, tournament));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment