Commit fa81c572 authored by ivarnm's avatar ivarnm
Browse files

Merge branch 'dev'

parents 7fc78a72 c1000682
......@@ -12,6 +12,9 @@ hs_err_pid*
android/assets/storage.json
android/assets/player_config.json
## Release
android/release
## GWT
/html/war/
/html/gwt-unitCache/
......
......@@ -8,15 +8,15 @@
"games": [
{
"id": "5e90541aeba599f7b1bffceb",
"class": "com.gameware.game.states.FruitSlicerState"
"class": "com.gameware.game.states.games.FruitSlicerState"
},
{
"id": "5e5d0efaa6e2bc5cb4920b7a",
"class": "com.gameware.game.states.ColorRushState"
"class": "com.gameware.game.states.games.ColorRushState"
},
{
"id": "5e5d0f1ea6e2bc5cb4920b7b",
"class": "com.gameware.game.states.BubbleWrapState"
"class": "com.gameware.game.states.games.BubbleWrapState"
}
]
}
package com.gameware.game.states;
package com.gameware.game;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gameware.game.states.State;
import java.util.Stack;
/*
GameStateManager keeps track of which state is the current one. Delegates to the correct state.
Patterns: State, Delegation, Update method
*/
public class GameStateManager {
private Stack<State> states;
......@@ -34,6 +41,7 @@ public class GameStateManager {
states.push(state);
}
// Update method (delegates to current state)
public void update(float dt){
states.peek().update(dt);
}
......
......@@ -13,10 +13,9 @@ import com.badlogic.gdx.utils.JsonValue;
import com.gameware.game.models.Game;
import com.gameware.game.models.LocalStorage;
import com.gameware.game.models.Player;
import com.gameware.game.states.GameStateManager;
import com.gameware.game.states.LoginState;
import com.gameware.game.states.MenuState;
import com.gameware.game.states.PlayStateUnion;
import com.gameware.game.states.menus.LoginState;
import com.gameware.game.states.menus.MenuState;
import com.gameware.game.states.games.PlayStateUnion;
import java.io.IOException;
import java.lang.reflect.Constructor;
......@@ -25,6 +24,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
GameWare is the main class, it is the first class to be created. It is called from the AndroidLauncher.
It extends LibGDX's ApplicationAdapter, and the render method (regarded as the game loop)
delegates to the GameStateManager.
Patterns: Singleton, Delegation, Game Loop
*/
public class GameWare extends ApplicationAdapter {
private SpriteBatch batch;
......@@ -83,12 +90,23 @@ public class GameWare extends ApplicationAdapter {
@Override
public void render () {
// Game loop
// Clearing the screen
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// Delegates to GameStateManager
gsm.update(Gdx.graphics.getDeltaTime());
gsm.render(batch);
}
@Override
public void dispose () {
batch.dispose();
music.dispose();
}
// Option toggles
public void toggleMusic(){
if(musicOn){music.pause();}
else{music.play();}
......@@ -101,6 +119,7 @@ public class GameWare extends ApplicationAdapter {
writeToLocalStorage();
}
// Getters and setters
public void setPlayer(Player player){
this.player = player;
writeToLocalStorage();
......@@ -140,13 +159,6 @@ public class GameWare extends ApplicationAdapter {
writeToLocalStorage();
}
@Override
public void dispose () {
batch.dispose();
music.dispose();
}
/*
The app uses local storage on the device to store the player and player options.
The app writes to local storage when one of the stored variables change and reads from
......
......@@ -31,13 +31,18 @@ import java.util.Map;
import java.util.NoSuchElementException;
import java.util.TimeZone;
public final class QueryIntermediate {
/*
/*
QueryIntermediate works as connector between frontend and backend. It takes care of all
communications and requests with backend.
Static class implemented with private constructor final class and only static methods.
Patterns: Pipe and Filter, Client-Server
*/
public final class QueryIntermediate {
private QueryIntermediate(){}
private static String baseUrl = GameWare.apiBaseUrl;
......@@ -198,7 +203,7 @@ public final class QueryIntermediate {
Map<String, String> params = new HashMap<>();
params.put("playerId", tournament.getPlayers().get(0));
params.put("games", tournament.getGames().toString());
params.put("name", tournament.getName());
params.put("name", tournament.getName().trim());
params.put("timePerRound", Double.toString(tournament.getTimePerRound()));
params.put("maxPlayers", Integer.toString(tournament.getMaxPlayers()));
params.put("roundsPerGame", Integer.toString(tournament.getRoundsPerGame()));
......@@ -326,6 +331,8 @@ public final class QueryIntermediate {
}
public static Player loginPlayer(String username, String password) throws IOException, NoSuchElementException {
username = username.trim();
password = password.trim();
String route = "players/login/" + username + "/" + password;
String[] response = sendGetRequest(route);
checkStatusCode(response);
......@@ -336,6 +343,8 @@ public final class QueryIntermediate {
public static Player createNewPlayer(String username, String password) throws IOException, NoSuchElementException {
String route = "players/";
username = username.trim();
password = password.trim();
Map<String, String> params = new HashMap<>();
params.put("username", username);
params.put("password", password);
......
......@@ -2,6 +2,10 @@ package com.gameware.game.models;
import com.badlogic.gdx.utils.Json;
/*
Model for the alerts about tournaments that finish
*/
public class Alert implements ModelInterface {
private String _id;
private String playerId;
......
......@@ -2,6 +2,10 @@ package com.gameware.game.models;
import com.badlogic.gdx.utils.Json;
/*
Model for games
*/
public class Game implements ModelInterface {
private String _id;
private String name;
......
......@@ -4,6 +4,10 @@ import com.badlogic.gdx.utils.Json;
import java.util.Comparator;
/*
Model for the a high score a player gets on a specific game
*/
public class Highscore implements ModelInterface {
private String _id;
private String gameId;
......
......@@ -2,14 +2,18 @@ package com.gameware.game.models;
import com.badlogic.gdx.utils.Json;
/*
Model for the local storage. Used to remember log in and options.
Loads in the config.json file, placed in the package "assets" under the package "android"
*/
public class LocalStorage implements ModelInterface {
private Player player;
private Boolean musicOn;
private Boolean soundEffects;
private Boolean includeFin;
public LocalStorage() {
}
public LocalStorage() {}
public LocalStorage(Player player, Boolean musicOn, Boolean soundEffects, Boolean includeFin) {
this.player = player;
......
package com.gameware.game.models;
public interface ModelInterface {
public void reset();
public String report();
/*
Data model interface for converting json objects to Java objects
Patterns: Pipe-and-filter
When implemented the class must be a model, in other words a data oriented java object.
Data models used for the filters input/output ports in the QueryIntermediate's pipe-and-filter implementation.
/*
Data models for converting json objects to Java objects
*/
ModelInterface is also implementation of the testability tactic "Specialized interfaces" with
requiring models to have a reset and a report method.
*/
public interface ModelInterface {
void reset();
String report();
}
......@@ -6,6 +6,10 @@ import com.gameware.game.QueryIntermediate;
import java.util.Date;
import java.util.jar.JarEntry;
/*
Model for users. The Player variable in the GameWare is set when logging in and out
*/
public class Player implements ModelInterface {
private String _id;
private String name;
......
......@@ -2,6 +2,10 @@ package com.gameware.game.models;
import com.badlogic.gdx.utils.Json;
/*
Model for the tournament points (TP). TP is the score a player has in a tournament
*/
public class Point implements ModelInterface {
private String id; // playerId
private String name;
......
......@@ -5,6 +5,10 @@ import com.gameware.game.QueryIntermediate;
import java.util.Date;
/*
Model for a player's round in a specific tournament.
*/
public class Round implements ModelInterface {
private String _id;
private String tournamentId;
......
......@@ -2,6 +2,13 @@ package com.gameware.game.models;
import com.badlogic.gdx.utils.Json;
/*
Model for checking and updating tournaments.
If active is true, that means the tournament is not finished,
if nextRound is true, that means the next round of the tournament is ready to be fetched and played.
This is used inside PlayStateUnion to know which menu state is the next one after a game is over.
*/
public class RoundCheck implements ModelInterface {
private boolean active;
private boolean nextRound;
......
......@@ -11,6 +11,10 @@ import java.util.Date;
import java.util.List;
import java.util.TimeZone;
/*
Model for tournaments.
*/
public class Tournament implements ModelInterface {
private String _id;
private List<String> players;
......
......@@ -4,6 +4,8 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
// This is the "Loading..." text that can be seen throughout the application
public class LoadingText extends Sprite {
private boolean isLoading = false;
private boolean firstUpdateFinished = false;
......
......@@ -7,6 +7,8 @@ import com.badlogic.gdx.math.Vector3;
import javax.xml.soap.Text;
// This is the pause button that is accessible in all minigames
public class PauseButton extends Sprite {
private Texture blackButtonTexture;
private Texture whiteButtonTexture;
......
......@@ -3,6 +3,13 @@ package com.gameware.game.sprites;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
/*
Abstract super class/union for game-sprites. Super class instead of interface because of
necessary variables all sprites needs to have
Patterns: Union, Update method
*/
public abstract class Sprite {
protected Vector3 position;
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.bubbleWrapSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
......@@ -7,9 +7,13 @@ import com.gameware.game.GameWare;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
import java.util.ArrayList;
import java.util.Random;
// This is the bubble seen in the Bubble Wrap minigame
public class Bubble extends Sprite {
private boolean textureChanged = false;
private ArrayList<Texture> poppedTextures;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment