Commit f4ea40c7 authored by Turid Cecilie Dahl's avatar Turid Cecilie Dahl
Browse files

#100 Adds comments about patterns, + some cleaning

parent 1fac56ac
......@@ -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"
}
]
}
......@@ -4,7 +4,6 @@ import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonReader;
......@@ -14,9 +13,9 @@ 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,13 @@ 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 delegates to the GameStateManager.
Patterns: Singleton, Delegation
*/
public class GameWare extends ApplicationAdapter {
private SpriteBatch batch;
......@@ -83,12 +89,18 @@ public class GameWare extends ApplicationAdapter {
@Override
public void render () {
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 +113,7 @@ public class GameWare extends ApplicationAdapter {
writeToLocalStorage();
}
// Getters and setters
public void setPlayer(Player player){
this.player = player;
writeToLocalStorage();
......@@ -140,13 +153,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,12 +31,17 @@ 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.
/*
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(){}
......
......@@ -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: Interface pattern, pipe-and-filter pattern
Implementation of the interface from the Interface pattern.
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;
......
......@@ -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
*/
public abstract class Sprite {
protected Vector3 position;
......
......@@ -4,6 +4,12 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import java.util.Stack;
/*
GameStateManager keeps track of which state is the current one. Delegates to the correct state.
Patterns: State, Delegation
*/
public class GameStateManager {
private Stack<State> states;
......
......@@ -9,10 +9,19 @@ import com.gameware.game.sprites.ConfirmationBox;
import com.gameware.game.sprites.LoadingText;
import com.gameware.game.sprites.PauseCircle;
import com.gameware.game.sprites.PauseMenuButton;
import com.gameware.game.states.games.PlayStateUnion;
import java.util.ArrayList;
import java.util.List;
/*
State shown when players pause a game.
Since it is still inside a game, the group wanted it to have a different look than the other menu states.
However it was not a game, so it doesn't extend either the MenuStateUnion or the PlayStateUnion.
It is therefore a bit of a special state, kind of in between the menu states and the game states.
*/
public class PauseState extends State {
// Data
......
......@@ -2,20 +2,26 @@ package com.gameware.game.states;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.gameware.game.GameWare;
/*
State is the super class/union of all the states in the application.
A state has their own logic and rendering. State contains common variables between
MenuStateUnion and PlayStateUnion.
Patterns: State, Union Design
*/
public abstract class State {
// Common variables between MenuStateUnion and PlayStateUnion
// Data
protected GameStateManager gsm;
protected Stage stage = new Stage();
protected final OrthographicCamera cam = new OrthographicCamera();
protected final Skin skin = new Skin(Gdx.files.internal(GameWare.skinFilePath));
// Sound effects
......@@ -23,13 +29,9 @@ public abstract class State {
protected Sound pauseResumeBtnSound;
protected Sound pauseStateBtnSound;
// Variables
protected boolean firstTimeRunningUpdate = true;
protected State(GameStateManager gsm){
this.gsm = gsm;
cam.setToOrtho(false, Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
// Add sound effects
this.buttonPressSound = Gdx.audio.newSound(Gdx.files.internal("sfx/button_press.ogg"));
......
package com.gameware.game.states;
package com.gameware.game.states.games;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gameware.game.sprites.Bubble;
import com.gameware.game.states.GameStateManager;
import java.util.ArrayList;
......
package com.gameware.game.states;
package com.gameware.game.states.games;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gameware.game.sprites.ColorRushButton;
import com.gameware.game.sprites.ColorRushTarget;
import com.gameware.game.states.GameStateManager;
import java.util.ArrayList;
import java.util.Collections;
......
package com.gameware.game.states;
package com.gameware.game.states.games;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
......@@ -8,6 +8,7 @@ import com.badlogic.gdx.math.Vector3;
import com.gameware.game.GameWare;
import com.gameware.game.sprites.Fruit;
import com.gameware.game.sprites.SlicingCircle;
import com.gameware.game.states.GameStateManager;
import java.util.ArrayList;
import java.util.List;
......
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