Commit 24eb33e3 authored by Turid Cecilie Dahl's avatar Turid Cecilie Dahl
Browse files

Refactored to PlayStateUnion and MenuStateUnion

parent e96d9917
......@@ -16,7 +16,7 @@ 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.PlayStateTemplate;
import com.gameware.game.states.PlayStateUnion;
import java.io.IOException;
import java.lang.reflect.Constructor;
......@@ -44,7 +44,7 @@ public class GameWare extends ApplicationAdapter {
private Player player;
private List<Game> games = new ArrayList<>();
private Map<String, PlayStateTemplate> gameIdToPlayState = new HashMap<>();
private Map<String, PlayStateUnion> gameIdToPlayState = new HashMap<>();
//Singleton (lazy initialization)
private GameWare(){ }
......@@ -117,11 +117,11 @@ public class GameWare extends ApplicationAdapter {
return games;
}
public Map<String, PlayStateTemplate> getGameIdToPlayState(){
public Map<String, PlayStateUnion> getGameIdToPlayState(){
return gameIdToPlayState;
}
public void updateGameMap(String id, PlayStateTemplate state){
public void updateGameMap(String id, PlayStateUnion state){
gameIdToPlayState.put(id, state);
}
......@@ -197,7 +197,7 @@ public class GameWare extends ApplicationAdapter {
try {
Class cl = Class.forName(className);
Constructor con = cl.getConstructor(GameStateManager.class);
PlayStateTemplate state = (PlayStateTemplate) con.newInstance(gsm);
PlayStateUnion state = (PlayStateUnion) con.newInstance(gsm);
gameIdToPlayState.put(id, state);
} catch (Exception e) {
e.printStackTrace();
......
......@@ -7,7 +7,7 @@ import com.gameware.game.sprites.Bubble;
import java.util.ArrayList;
public class BubbleWrapState extends PlayStateTemplate {
public class BubbleWrapState extends PlayStateUnion {
private Texture background;
private Texture unpopped;
private Texture popped1;
......
......@@ -9,7 +9,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ColorRushState extends PlayStateTemplate {
public class ColorRushState extends PlayStateUnion {
private List<ColorRushTarget> activeTargets;
private List<ColorRushTarget> previousTargets;
......
......@@ -26,7 +26,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class CreateJoinTournamentState extends MenuStateTemplate {
public class CreateJoinTournamentState extends MenuStateUnion {
// Data
private List<Tournament> tournaments = new ArrayList<>();
......
......@@ -27,7 +27,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class CreateNewTournamentState extends MenuStateTemplate {
public class CreateNewTournamentState extends MenuStateUnion {
// Data
private List<Game> games;
......
......@@ -18,7 +18,7 @@ import com.gameware.game.models.Tournament;
import java.util.ArrayList;
import java.util.List;
public class FinishedTournamentState extends MenuStateTemplate {
public class FinishedTournamentState extends MenuStateUnion {
// Data
private Tournament tournament;
......
......@@ -12,7 +12,7 @@ import com.gameware.game.sprites.SlicingCircle;
import java.util.ArrayList;
import java.util.List;
public class FruitSlicerState extends PlayStateTemplate {
public class FruitSlicerState extends PlayStateUnion {
private int totalFruitsCut = 0;
private float startingEmitFrequency = 1f;
private float endingEmitFrequency = 0.2f;
......
......@@ -2,7 +2,6 @@ package com.gameware.game.states;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
......@@ -19,7 +18,7 @@ import com.gameware.game.sprites.LoadingText;
import java.io.IOException;
import java.util.NoSuchElementException;
public class LoginState extends MenuStateTemplate {
public class LoginState extends MenuStateUnion {
// Labels
private final Label titleLabel = new Label("GameWare", skin, "big");
......
......@@ -2,7 +2,6 @@ package com.gameware.game.states;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
......@@ -16,7 +15,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.gameware.game.GameWare;
import com.gameware.game.sprites.LoadingText;
public class MenuState extends MenuStateTemplate{
public class MenuState extends MenuStateUnion {
// Labels
private final Label titleLabel = new Label("GameWare", skin, "big");
......
......@@ -18,7 +18,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Align;
import com.gameware.game.GameWare;
public abstract class MenuStateTemplate extends State{
public abstract class MenuStateUnion extends State{
// Font
protected final float fontScale = 3f;
......@@ -55,7 +55,7 @@ public abstract class MenuStateTemplate extends State{
protected Sound checkBoxSound;
public MenuStateTemplate(GameStateManager gsm){
public MenuStateUnion(GameStateManager gsm){
super(gsm);
skin.getFont("font").getData().setScale(fontScale);
......
......@@ -12,7 +12,7 @@ import com.badlogic.gdx.utils.Scaling;
import com.gameware.game.GameWare;
public class OptionsState extends MenuStateTemplate {
public class OptionsState extends MenuStateUnion {
// Labels
private final Label titleLabel = new Label("Options", skin, "big");
......
......@@ -16,7 +16,7 @@ import java.util.List;
public class PauseState extends State {
// Data
private PlayStateTemplate pausedGame;
private PlayStateUnion pausedGame;
// Textures
private Texture background;
......@@ -40,7 +40,7 @@ public class PauseState extends State {
private LoadingText loadingText;
public PauseState(GameStateManager gsm, PlayStateTemplate pausedGame) {
public PauseState(GameStateManager gsm, PlayStateUnion pausedGame) {
super(gsm);
this.background = new Texture(Gdx.files.internal("pause/PauseBackground.jpg"));
......
......@@ -26,7 +26,7 @@ import java.io.IOException;
import java.util.List;
public abstract class PlayStateTemplate extends State {
public abstract class PlayStateUnion extends State {
// Data
private Round round = null;
......@@ -51,7 +51,7 @@ public abstract class PlayStateTemplate extends State {
private boolean currentScoreVisible = true;
public PlayStateTemplate(GameStateManager gsm){
public PlayStateUnion(GameStateManager gsm){
super(gsm);
// Default pause button (black color)
......
......@@ -11,7 +11,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.Align;
import com.gameware.game.GameWare;
public class ScoreState extends MenuStateTemplate {
public class ScoreState extends MenuStateUnion {
// Data
private State nextState;
......
......@@ -17,7 +17,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class SinglePlayerSelectGameState extends MenuStateTemplate {
public class SinglePlayerSelectGameState extends MenuStateUnion {
// Data
private List<Game> games = new ArrayList<>();
......@@ -124,7 +124,7 @@ public class SinglePlayerSelectGameState extends MenuStateTemplate {
@Override
public void clicked(InputEvent event, float x, float y) {
Map<String, PlayStateTemplate> map = GameWare.getInstance().getGameIdToPlayState();
Map<String, PlayStateUnion> map = GameWare.getInstance().getGameIdToPlayState();
State s = map.get(game.getId());
handleGameBtnClick(s);
};
......
......@@ -10,7 +10,7 @@ import com.gameware.game.GameWare;
public abstract class State {
// Common variables between MenuStateTemplate and PlayStateTemplate
// Common variables between MenuStateUnion and PlayStateUnion
// Data
protected GameStateManager gsm;
......
......@@ -17,7 +17,7 @@ import com.gameware.game.models.Tournament;
import java.util.ArrayList;
import java.util.List;
public class TournamentHighScoreState extends MenuStateTemplate{
public class TournamentHighScoreState extends MenuStateUnion {
// Data
private Tournament tournament;
......
......@@ -18,7 +18,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
public class ViewHighScoreForGameState extends MenuStateTemplate {
public class ViewHighScoreForGameState extends MenuStateUnion {
// Data
private String playerId = GameWare.getInstance().getPlayer().getId();
......
......@@ -20,7 +20,7 @@ import com.gameware.game.sprites.LoadingText;
import java.io.IOException;
public class ViewHighScoreState extends MenuStateTemplate {
public class ViewHighScoreState extends MenuStateUnion {
// Data
private List<Game> games = new ArrayList<>();
......
......@@ -24,7 +24,7 @@ import com.gameware.game.sprites.LoadingText;
import java.io.IOException;
import java.util.List;
public class ViewTournamentState extends MenuStateTemplate {
public class ViewTournamentState extends MenuStateUnion {
// Data
private Tournament tournament;
......@@ -108,7 +108,7 @@ public class ViewTournamentState extends MenuStateTemplate {
currentRoundTable.pad(padding);
currentRoundTable.setBackground(backgroundTableBlueRounded);
currentRoundTable.add(new Label("This round:\n\n"+gameName,skin)).space(spacingLittle);
PlayStateTemplate state = GameWare.getInstance().getGameIdToPlayState().get(round.getGameId());
PlayStateUnion state = GameWare.getInstance().getGameIdToPlayState().get(round.getGameId());
currentRoundTable.add(new Image(state.getScreenshot())).width(imageWidthAndHeigh).height(imageWidthAndHeigh).spaceBottom(spacingMedium).colspan(2);
rootTable.add(currentRoundTable).maxHeight(Gdx.graphics.getHeight()/5).colspan(2);
rootTable.row();
......@@ -273,7 +273,7 @@ public class ViewTournamentState extends MenuStateTemplate {
private void handlePlayBtnClick(){
if(GameWare.getInstance().isSoundEffectsOn()){ buttonPressSound.play(); }
PlayStateTemplate state = GameWare.getInstance().getGameIdToPlayState().get(round.getGameId());
PlayStateUnion state = GameWare.getInstance().getGameIdToPlayState().get(round.getGameId());
state.setTournament(tournament);
state.setRound(round);
gsm.set(state);
......
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