Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 101-make-font-scale-based-on-device-width
  • 77-static-loading-screen
  • dev
  • master
4 results

Target

Select target project
  • haakogun/tdt-4240-v-20-haakon
  • tobiasio/progark-gruppe-3
2 results
Select Git revision
  • 101-make-font-scale-based-on-device-width
  • 77-static-loading-screen
  • dev
  • master
4 results
Show changes
Commits on Source (14)
Showing
with 84 additions and 37 deletions
......@@ -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/
......
frontend/android/assets/gameTextures/placeholderThumbnail.png

262 KiB

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
Patterns: State, Delegation, Update method
*/
public class GameStateManager {
......@@ -40,6 +41,7 @@ public class GameStateManager {
states.push(state);
}
// Update method (delegates to current state)
public void update(float dt){
states.peek().update(dt);
}
......
......@@ -4,6 +4,7 @@ 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;
......@@ -12,7 +13,6 @@ 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.menus.LoginState;
import com.gameware.game.states.menus.MenuState;
import com.gameware.game.states.games.PlayStateUnion;
......@@ -27,9 +27,10 @@ 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.
It extends LibGDX's ApplicationAdapter, and the render method (regarded as the game loop)
delegates to the GameStateManager.
Patterns: Singleton, Delegation
Patterns: Singleton, Delegation, Game Loop
*/
public class GameWare extends ApplicationAdapter {
......@@ -89,6 +90,8 @@ 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);
......
......@@ -203,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()));
......@@ -331,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);
......@@ -341,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);
......
......@@ -3,9 +3,8 @@ package com.gameware.game.models;
/*
Data model interface for converting json objects to Java objects
Patterns: Interface pattern, pipe-and-filter pattern
Patterns: Pipe-and-filter
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.
......
......@@ -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;
......
......@@ -7,7 +7,7 @@ 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
Patterns: Union, Update method
*/
public abstract class Sprite {
......
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;
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.colorRushSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
......@@ -6,6 +6,9 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.GameWare;
import com.gameware.game.sprites.Sprite;
// These are the buttons that needs to be pressed according to the matching color of the target in the Color Rush minigame
public class ColorRushButton extends Sprite {
private Texture mainTexture;
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.colorRushSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
// This is the block that you need to press the matching color to remove in the Color Rush minigame
public class ColorRushTarget extends Sprite {
private int nextHeight;
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.fruitSlicerSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
// This is the fruit that can be chopped in the Fruit Slicer minigame
public class Fruit extends Sprite {
private Vector3 cutPosition1;
......@@ -131,6 +133,7 @@ public class Fruit extends Sprite {
@Override
public void dispose() {
// Nothing to dispose
}
public boolean isDisposable() {
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.fruitSlicerSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
// This is the circle trail that are left when slicing in the Fruit Slicer minigame
public class SlicingCircle extends Sprite {
private Texture slicingVFX;
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.pauseStateSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
// This is the confirmation box when trying to exit a minigame when in the pause state
public class ConfirmationBox extends Sprite {
private Texture boxTexture;
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.pauseStateSprites;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
// These are the animated circles that can be seen in the background of the pause state
public class PauseCircle extends Sprite {
private int radius;
......
package com.gameware.game.sprites;
package com.gameware.game.sprites.pauseStateSprites;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.gameware.game.sprites.Sprite;
// This is the button used for "Resume" and "Exit" in the pause state
public class PauseMenuButton extends Sprite {
private Texture buttonTexture;
......
......@@ -4,11 +4,12 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.gameware.game.GameStateManager;
import com.gameware.game.GameWare;
import com.gameware.game.sprites.ConfirmationBox;
import com.gameware.game.sprites.pauseStateSprites.ConfirmationBox;
import com.gameware.game.sprites.LoadingText;
import com.gameware.game.sprites.PauseCircle;
import com.gameware.game.sprites.PauseMenuButton;
import com.gameware.game.sprites.pauseStateSprites.PauseCircle;
import com.gameware.game.sprites.pauseStateSprites.PauseMenuButton;
import com.gameware.game.states.games.PlayStateUnion;
import java.util.ArrayList;
......@@ -42,7 +43,7 @@ public class PauseState extends State {
private boolean needsConfirmation;
// Widgets
private List<PauseCircle> pauseCircles;
private List<PauseCircle> pauseBackgroundCircles;
private ConfirmationBox confirmationBox;
private PauseMenuButton resumeButton;
private PauseMenuButton exitButton;
......@@ -63,7 +64,7 @@ public class PauseState extends State {
this.countdownDurationLeft = 3f;
this.countdownStarted = false;
this.pauseCircles = new ArrayList<PauseCircle>();
this.pauseBackgroundCircles = new ArrayList<PauseCircle>();
this.pausedGame = pausedGame;
this.originalFontColor = new Color(this.pausedGame.getFontColor());
......@@ -85,7 +86,7 @@ public class PauseState extends State {
for(int i = 0; i<25; i++){
this.pauseCircles.add(new PauseCircle());
this.pauseBackgroundCircles.add(new PauseCircle());
}
}
......@@ -146,7 +147,7 @@ public class PauseState extends State {
// If the user has pressed the resume button the countdown has started
if(this.countdownStarted){
this.countdownDurationLeft -= dt;
this.countdownNumberTexture = this.countdownNumbers.get(Math.min(Math.max((int) (this.countdownDurationLeft),0), 3));
this.countdownNumberTexture = this.countdownNumbers.get(Math.min(Math.max((int) (this.countdownDurationLeft),0), 2));
// If the countdown has finished we resume the game
if(this.countdownDurationLeft <= 0){
......@@ -157,7 +158,7 @@ public class PauseState extends State {
}
}
for(PauseCircle pc : this.pauseCircles){
for(PauseCircle pc : this.pauseBackgroundCircles){
pc.update(dt);
}
}
......@@ -173,7 +174,7 @@ public class PauseState extends State {
// Animated circles
for(PauseCircle pc : pauseCircles){
for(PauseCircle pc : pauseBackgroundCircles){
pc.draw(sb);
}
......@@ -213,7 +214,7 @@ public class PauseState extends State {
@Override
public void dispose() {
for(PauseCircle pc : pauseCircles){
for(PauseCircle pc : pauseBackgroundCircles){
pc.dispose();
}
......@@ -231,5 +232,9 @@ public class PauseState extends State {
}
@Override
public void reset() { }
public void reset() {
this.needsConfirmation = false;
this.countdownStarted = false;
this.countdownDurationLeft = 3f;
}
}
......@@ -5,15 +5,16 @@ import com.badlogic.gdx.audio.Sound;
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.GameStateManager;
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.
MenuStateUnion and PlayStateUnion. All states must have their own update method.
Patterns: State, Union Design
Patterns: State, Union Design, Update method
*/
public abstract class State {
......@@ -45,6 +46,7 @@ public abstract class State {
// Abstract state methods
protected abstract void handleInput();
// Requires all states to have the update method
public abstract void update(float dt);
public abstract void render(SpriteBatch sb);
......
......@@ -3,8 +3,8 @@ 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 com.gameware.game.sprites.bubbleWrapSprites.Bubble;
import com.gameware.game.GameStateManager;
import java.util.ArrayList;
......@@ -28,9 +28,9 @@ public class BubbleWrapState extends PlayStateUnion {
public BubbleWrapState(GameStateManager gsm) {
super(gsm);
super.setPauseButtonWhite();
super.setTotalGameTime(20f);
super.setTotalTimeLimit(20f);
super.setFontColorWhite();
super.screenshot = new Texture(Gdx.files.internal("gameTextures/BubbleWrap/bubbleWrapPhotoEdit.png"));
super.setThumbnail(new Texture(Gdx.files.internal("gameTextures/BubbleWrap/bubbleWrapPhotoEdit.png")));
background = new Texture(Gdx.files.internal("gameTextures/BubbleWrap/bubblewrap_background.jpg"));
unpopped = new Texture(Gdx.files.internal("gameTextures/BubbleWrap/bubble_unpopped_1.png"));
......@@ -62,7 +62,7 @@ public class BubbleWrapState extends PlayStateUnion {
// Keeps score consistent
// One point per bubble popped, plus three points for each second of remaining time. Time bonus is only given if the player pops all the bubbles.
if(this.poppedBubbles == this.bubbles.size()){
score = this.poppedBubbles + Math.max(Math.round((super.getTotalGameTime() - super.getCurrentDuration())*3), 0);
score = this.poppedBubbles + Math.max(Math.round((super.getTotalTimeLimit() - super.getCurrentDuration())*3), 0);
}
else{
score = this.poppedBubbles;
......