diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 600d2d33badf45cc068e01d2e3c837e11c417bc4..0000000000000000000000000000000000000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.vscode \ No newline at end of file diff --git a/backend/api/highscores.js b/backend/api/highscores.js index e3616e473dfaafe4af879e0e1ff3c6d87a6ca608..69476d9dd29d1ad82988b3b13e5f111559325b4b 100644 --- a/backend/api/highscores.js +++ b/backend/api/highscores.js @@ -91,7 +91,7 @@ router.get("/userscore/:userid", (req, res) => { db.collection(movieCollection) .find({ - userid: req.params.userid + userid: mongo.ObjectID(req.params.userid) }) .toArray((err, result) => { if (err) { @@ -119,9 +119,9 @@ router.get("/gamescores/:gameid", (req, res) => { // Using the database gameWare and collection games const db = client.db("gameWare"); - const movieCollection = "highscores"; + const collection = "highscores"; - db.collection(movieCollection) + db.collection(collection) .find( { 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 diff --git a/backend/index.js b/backend/index.js index 04718cc037ad7b4a75415688e1de31243902a191..1cbb1d3bfa2bfdb0e113602bac81b45d9273bd56 100644 --- a/backend/index.js +++ b/backend/index.js @@ -4,7 +4,7 @@ const bodyParser = require("body-parser"); const app = express(); 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(bodyParser.json()); diff --git a/frontend/core/src/com/gameware/game/GameWare.java b/frontend/core/src/com/gameware/game/GameWare.java index 47d9cfb000f388dc7a275ccd4bb20bb6e5f6e242..23f4a8dbac74f8f914dc511f25a7bac49967e680 100644 --- a/frontend/core/src/com/gameware/game/GameWare.java +++ b/frontend/core/src/com/gameware/game/GameWare.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.gameware.game.states.BubbleWrapState; import com.gameware.game.models.Player; import com.gameware.game.states.ColorRushState; import com.gameware.game.states.CreateJoinTournamentState; @@ -14,6 +15,7 @@ import com.gameware.game.states.ViewHighScoreState; import com.gameware.game.states.ViewTournamentState; import com.gameware.game.states.LoginState; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -43,9 +45,10 @@ public class GameWare extends ApplicationAdapter { gsm = GameStateManager.getInstance(); gameIdToPlayState.put("5e5d0efaa6e2bc5cb4920b7a", new ColorRushState(gsm)); - //gameIdToPlayState.put("5e5d0f1ea6e2bc5cb4920b7b", new BubbleWrapState(gsm)); + gameIdToPlayState.put("5e5d0f1ea6e2bc5cb4920b7b", new BubbleWrapState(gsm)); batch = new SpriteBatch(); + //music = Gdx.audio.newMusic(Gdx.files.internal(("music.mp3"))); //music.setLooping(true); //music.setVolume(0.1f); diff --git a/frontend/core/src/com/gameware/game/QueryIntermediate.java b/frontend/core/src/com/gameware/game/QueryIntermediate.java index 2182e04c79ec67973b6bbdcf6a1067aa1c309d6d..c8135cd7253b09c0b08d1ee23c266cb941e8fea3 100644 --- a/frontend/core/src/com/gameware/game/QueryIntermediate.java +++ b/frontend/core/src/com/gameware/game/QueryIntermediate.java @@ -24,8 +24,7 @@ import java.util.HashMap; import java.util.NoSuchElementException; 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 = "https://gameware.herokuapp.com/api/"; + private static String baseUrl = "http://192.168.0.195:3002/api/"; private static Json json = new Json(); private static JsonReader jsonReader = new JsonReader(); diff --git a/frontend/core/src/com/gameware/game/models/Tournament.java b/frontend/core/src/com/gameware/game/models/Tournament.java index 2632946e4bb21a1f06da7d623e19e800805e008f..bfd4a91c33bf0713ba43ebaf6231c1cf72b1719c 100644 --- a/frontend/core/src/com/gameware/game/models/Tournament.java +++ b/frontend/core/src/com/gameware/game/models/Tournament.java @@ -36,6 +36,21 @@ public class Tournament { 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() { return _id; } diff --git a/frontend/core/src/com/gameware/game/states/BubbleWrapState.java b/frontend/core/src/com/gameware/game/states/BubbleWrapState.java new file mode 100644 index 0000000000000000000000000000000000000000..25c9c7e0a5517bc99125ead06ae3e140d17b58be --- /dev/null +++ b/frontend/core/src/com/gameware/game/states/BubbleWrapState.java @@ -0,0 +1,39 @@ +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; + } +} diff --git a/frontend/core/src/com/gameware/game/states/MenuState.java b/frontend/core/src/com/gameware/game/states/MenuState.java index acc3beae1effb1bb69117ce073070d39bf9bfd98..b188d4a7acc1c43758b4879db7f83f23b9a60a4d 100644 --- a/frontend/core/src/com/gameware/game/states/MenuState.java +++ b/frontend/core/src/com/gameware/game/states/MenuState.java @@ -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.utils.ClickListener; +import java.io.IOException; + public class MenuState extends State{ private Table table; @@ -40,7 +42,13 @@ public class MenuState extends State{ TextButton singlePlayerBtn = new TextButton(singlePlayerBtnText, skin); singlePlayerBtn.addListener(new ClickListener() { @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; } @@ -67,7 +75,13 @@ public class MenuState extends State{ TextButton highScoreBtn = new TextButton(highScoreBtnText, skin); highScoreBtn.addListener(new ClickListener() { @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; } @@ -119,11 +133,11 @@ public class MenuState extends State{ 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)); } diff --git a/frontend/core/src/com/gameware/game/states/SinglePlayerSelectGameState.java b/frontend/core/src/com/gameware/game/states/SinglePlayerSelectGameState.java new file mode 100644 index 0000000000000000000000000000000000000000..15e1600aa20ad5afee4d43c01944320d4f3083a1 --- /dev/null +++ b/frontend/core/src/com/gameware/game/states/SinglePlayerSelectGameState.java @@ -0,0 +1,109 @@ +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())); + }; + } +} diff --git a/frontend/core/src/com/gameware/game/states/ViewHighScoreState.java b/frontend/core/src/com/gameware/game/states/ViewHighScoreState.java index 7d17cf6c4075d3937c71eac9ff32947e28154baa..7ce02c06753b6c407bec74b9c2cefce9f17b9e00 100644 --- a/frontend/core/src/com/gameware/game/states/ViewHighScoreState.java +++ b/frontend/core/src/com/gameware/game/states/ViewHighScoreState.java @@ -2,59 +2,48 @@ package com.gameware.game.states; import com.badlogic.gdx.graphics.g2d.SpriteBatch; 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.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; 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 { private Table table; + private List<Game> games; private String backBtnText = "Back"; - private String colorRushHighScoreBtnText = "Color Rush"; - private String bubbleWrapHighScoreBtnText = "Bubble Wrap"; - - public ViewHighScoreState(GameStateManager gsm) { + public ViewHighScoreState(GameStateManager gsm) throws IOException { super(gsm); - System.out.println("Du er i view high score state :0"); + + games = getGames(); table = new Table(); table.setFillParent(true); table.row(); - table.add(makeBackBtn()); - //TODO: autogenerer fra QI get - 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); + 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.add(makeBackBtn()).spaceBottom(spacingOnBottom); stage.addActor(table); } - 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; - } - @Override protected void handleInput() { @@ -85,9 +74,38 @@ public class ViewHighScoreState extends State { 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 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