Skip to content
Snippets Groups Projects
Commit 6f706629 authored by ivarnm's avatar ivarnm
Browse files

#10 Merge branch 'dev' into 10-query-intermediate

parents c3f82768 ce50b9fd
No related branches found
No related tags found
1 merge request!21Resolve "Query intermediate"
.vscode
\ No newline at end of file
...@@ -91,7 +91,7 @@ router.get("/userscore/:userid", (req, res) => { ...@@ -91,7 +91,7 @@ router.get("/userscore/:userid", (req, res) => {
db.collection(movieCollection) db.collection(movieCollection)
.find({ .find({
userid: req.params.userid userid: mongo.ObjectID(req.params.userid)
}) })
.toArray((err, result) => { .toArray((err, result) => {
if (err) { if (err) {
...@@ -119,9 +119,9 @@ router.get("/gamescores/:gameid", (req, res) => { ...@@ -119,9 +119,9 @@ router.get("/gamescores/:gameid", (req, res) => {
// Using the database gameWare and collection games // Using the database gameWare and collection games
const db = client.db("gameWare"); const db = client.db("gameWare");
const movieCollection = "highscores"; const collection = "highscores";
db.collection(movieCollection) db.collection(collection)
.find( .find(
{ gameid: mongo.ObjectID(req.params.gameid) } { gameid: mongo.ObjectID(req.params.gameid) }
// gives the options to the query. We only want 5 scores and want them sorted by value in descending order // gives the options to the query. We only want 5 scores and want them sorted by value in descending order
......
...@@ -4,7 +4,7 @@ const bodyParser = require("body-parser"); ...@@ -4,7 +4,7 @@ const bodyParser = require("body-parser");
const app = express(); const app = express();
require("dotenv").config(); require("dotenv").config();
const port = process.env.PORT || 3001; // The port for the server const port = process.env.PORT || 3002; // The port for the server
app.use(cors()); app.use(cors());
app.use(bodyParser.json()); app.use(bodyParser.json());
......
...@@ -4,6 +4,7 @@ import com.badlogic.gdx.ApplicationAdapter; ...@@ -4,6 +4,7 @@ import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx; 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.states.BubbleWrapState;
import com.gameware.game.models.Player; import com.gameware.game.models.Player;
import com.gameware.game.states.ColorRushState; import com.gameware.game.states.ColorRushState;
import com.gameware.game.states.CreateJoinTournamentState; import com.gameware.game.states.CreateJoinTournamentState;
...@@ -14,6 +15,7 @@ import com.gameware.game.states.ViewHighScoreState; ...@@ -14,6 +15,7 @@ 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.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -43,9 +45,10 @@ public class GameWare extends ApplicationAdapter { ...@@ -43,9 +45,10 @@ public class GameWare extends ApplicationAdapter {
gsm = GameStateManager.getInstance(); gsm = GameStateManager.getInstance();
gameIdToPlayState.put("5e5d0efaa6e2bc5cb4920b7a", new ColorRushState(gsm)); gameIdToPlayState.put("5e5d0efaa6e2bc5cb4920b7a", new ColorRushState(gsm));
//gameIdToPlayState.put("5e5d0f1ea6e2bc5cb4920b7b", new BubbleWrapState(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);
//music.setVolume(0.1f); //music.setVolume(0.1f);
......
...@@ -24,8 +24,7 @@ import java.util.HashMap; ...@@ -24,8 +24,7 @@ import java.util.HashMap;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
public class QueryIntermediate { public class QueryIntermediate {
private static String baseUrl = "http://192.168.0.169:3001/api/"; // TODO: use your own IP when testing locally private static String baseUrl = "http://192.168.0.195:3002/api/";
//private static String baseUrl = "https://gameware.herokuapp.com/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();
......
...@@ -36,6 +36,21 @@ public class Tournament { ...@@ -36,6 +36,21 @@ public class Tournament {
this.roundsPerGame = roundsPerGame; this.roundsPerGame = roundsPerGame;
} }
// 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
public Tournament(String _id, String name) {
this._id = _id;
this.name = name;
}
public String get_id() { public String get_id() {
return _id; return _id;
} }
......
package com.gameware.game.states;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class BubbleWrapState extends PlayStateTemplate {
public BubbleWrapState(GameStateManager gsm) {
super(gsm);
}
@Override
protected void handleInput() {
}
@Override
public void update(float dt) {
}
@Override
public void render(SpriteBatch sb) {
}
@Override
public void dispose() {
}
@Override
public void reset() {
}
@Override
public Object report() {
return null;
}
}
...@@ -6,6 +6,8 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table; ...@@ -6,6 +6,8 @@ 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 java.io.IOException;
public class MenuState extends State{ public class MenuState extends State{
private Table table; private Table table;
...@@ -40,7 +42,13 @@ public class MenuState extends State{ ...@@ -40,7 +42,13 @@ public class MenuState extends State{
TextButton singlePlayerBtn = new TextButton(singlePlayerBtnText, skin); TextButton singlePlayerBtn = new TextButton(singlePlayerBtnText, skin);
singlePlayerBtn.addListener(new ClickListener() { singlePlayerBtn.addListener(new ClickListener() {
@Override @Override
public void clicked(InputEvent e, float x, float y){ handleSingleBtnClick(); } public void clicked(InputEvent e, float x, float y){
try {
handleSingleBtnClick();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}); });
return singlePlayerBtn; return singlePlayerBtn;
} }
...@@ -67,7 +75,13 @@ public class MenuState extends State{ ...@@ -67,7 +75,13 @@ public class MenuState extends State{
TextButton highScoreBtn = new TextButton(highScoreBtnText, skin); TextButton highScoreBtn = new TextButton(highScoreBtnText, skin);
highScoreBtn.addListener(new ClickListener() { highScoreBtn.addListener(new ClickListener() {
@Override @Override
public void clicked(InputEvent e, float x, float y){ handleHighscoreBtnClick(); } public void clicked(InputEvent e, float x, float y){
try {
handleHighscoreBtnClick();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}); });
return highScoreBtn; return highScoreBtn;
} }
...@@ -119,11 +133,11 @@ public class MenuState extends State{ ...@@ -119,11 +133,11 @@ public class MenuState extends State{
gsm.set(new CreateJoinTournamentState(gsm)); gsm.set(new CreateJoinTournamentState(gsm));
} }
private void handleSingleBtnClick(){ private void handleSingleBtnClick() throws IOException {
gsm.set(new SinglePlayerSelectGameState(gsm));
} }
private void handleHighscoreBtnClick(){ private void handleHighscoreBtnClick() throws IOException {
gsm.set(new ViewHighScoreState(gsm)); gsm.set(new ViewHighScoreState(gsm));
} }
......
package com.gameware.game.states;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
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.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.gameware.game.GameWare;
import com.gameware.game.QueryIntermediate;
import com.gameware.game.models.Game;
import com.gameware.game.models.Tournament;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class SinglePlayerSelectGameState extends State {
private Table table;
private List<Game> games;
private final String backBtnText = "Back";
protected SinglePlayerSelectGameState(GameStateManager gsm) throws IOException {
super(gsm);
games = getGames();
table = new Table();
table.setFillParent(true);
table.row();
for (Game g : games){
TextButton gameBtn = new TextButton(g.getName(), skin);
gameBtn.addListener(new SinglePlayerSelectGameState.MyClickListener(g));
table.add(gameBtn).spaceBottom(spacingOnBottom);
table.row();
}
table.add(makeBackBtn()).spaceBottom(spacingOnBottom);
stage.addActor(table);
}
@Override
protected void handleInput() {
}
@Override
public void update(float dt) {
stage.act();
}
@Override
public void render(SpriteBatch sb) {
stage.draw();
}
@Override
public void dispose() {
stage.dispose();
}
@Override
public void reset() {
}
@Override
public Object report() {
return this;
}
private TextButton makeBackBtn(){
TextButton backBtn = new TextButton(backBtnText, skin);
backBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){ handleBackBtnClick(); }
});
return backBtn;
}
private void handleBackBtnClick(){
gsm.set(new MenuState(gsm));
}
private void handleGameBtnClick(State state){
gsm.set(state);
}
private static List<Game> getGames() throws IOException {
List<Game> games = QueryIntermediate.getGames();
return games;
}
public class MyClickListener extends ClickListener{
private Game game;
public MyClickListener(Game game){
this.game = game;
}
public void clicked(InputEvent event, float x, float y) {
handleGameBtnClick(GameWare.gameIdToPlayState.get(game.getId()));
};
}
}
...@@ -2,57 +2,46 @@ package com.gameware.game.states; ...@@ -2,57 +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 java.util.List;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
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.QueryIntermediate;
import com.gameware.game.GameWare;
import com.gameware.game.models.Game;
import java.io.IOException;
import java.io.IOException;
public class ViewHighScoreState extends State { public class ViewHighScoreState extends State {
private Table table; private Table table;
private List<Game> games;
private String backBtnText = "Back"; private String backBtnText = "Back";
private String colorRushHighScoreBtnText = "Color Rush";
private String bubbleWrapHighScoreBtnText = "Bubble Wrap";
public ViewHighScoreState(GameStateManager gsm) throws IOException {
public ViewHighScoreState(GameStateManager gsm) {
super(gsm); super(gsm);
System.out.println("Du er i view high score state :0");
games = getGames();
table = new Table(); table = new Table();
table.setFillParent(true); table.setFillParent(true);
table.row(); table.row();
table.add(makeBackBtn());
//TODO: autogenerer fra QI get for (Game g : games){
TextButton gameBtn = new TextButton(g.getName(), skin);
gameBtn.addListener(new ViewHighScoreState.MyClickListener(g));
table.add(gameBtn).spaceBottom(spacingOnBottom);
table.row(); table.row();
TextButton colorRushBtn = new TextButton(colorRushHighScoreBtnText, skin);
colorRushBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){ handleColorRushBtnClick(); }
});
table.add(colorRushBtn);
table.row();
TextButton bubbleWrapBtn = new TextButton(bubbleWrapHighScoreBtnText, skin);
bubbleWrapBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){ handleBubbleWrapBtnClick(); }
});
table.add(bubbleWrapBtn);
stage.addActor(table);
} }
private TextButton makeBackBtn(){ table.add(makeBackBtn()).spaceBottom(spacingOnBottom);
TextButton backBtn = new TextButton(backBtnText, skin); stage.addActor(table);
backBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){ handleBackBtnClick(); }
});
return backBtn;
} }
@Override @Override
...@@ -85,9 +74,38 @@ public class ViewHighScoreState extends State { ...@@ -85,9 +74,38 @@ public class ViewHighScoreState extends State {
return this; return this;
} }
private TextButton makeBackBtn(){
TextButton backBtn = new TextButton(backBtnText, skin);
backBtn.addListener(new ClickListener() {
@Override
public void clicked(InputEvent e, float x, float y){ handleBackBtnClick(); }
});
return backBtn;
}
private void handleBackBtnClick(){ private void handleBackBtnClick(){
gsm.set(new MenuState(gsm)); gsm.set(new MenuState(gsm));
} }
private void handleColorRushBtnClick(){}
private void handleBubbleWrapBtnClick(){} private void handleGameBtnClick(){
//TODO: This needs to take in the game object and go to viewHighScoreForGameState. For the next issue.
}
private static List<Game> getGames() throws IOException {
List<Game> games = QueryIntermediate.getGames();
return games;
}
public class MyClickListener extends ClickListener{
private Game game;
public MyClickListener(Game game){
this.game = game;
}
public void clicked(InputEvent event, float x, float y) {
//TODO: Add a new hashmap to GameWare with the gameobjects from the game id from here.
handleGameBtnClick();
};
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment