Commit 5e4090d7 authored by Anders H. Rebner's avatar Anders H. Rebner
Browse files

Finalized flow, added exit button

parent 41165917
package com.mygdx.game;
import java.util.HashMap;
public class Constants {
public static final int PLAYER_NAME_TEXT_FIELD_WIDTH = 340;
public static final int PLAYER_NAME_TEXT_FIELD_HEIGHT = 80;
public static final HashMap<Integer, String> AVAILABLEAVATARSHASHMAP = new HashMap<Integer, String>() {{
put(0, "RegularGuy");
put(1, "HipsterGirl");
put(2, "HighSchoolGuy");
put(3, "RocketGuy");
put(4, "AsianGirl");
put(5, "Grandma");
}};
}
......@@ -96,8 +96,8 @@ public class GameController {
}
}
public void setGameFinished(List<Integer> placementIds) {
// TODO: New view, pass results
// Remove turnindicator, add home button
public void setGameFinished() {
this.view.removeTurnIndicator();
this.view.placeHomeButton();
}
}
......@@ -46,12 +46,14 @@ class Game(gameState: GameState, playerIds: LinkedHashSet<Int>) {
playerFinishedIds = playerFinishedIds + playerId
gameController.setPlayerFinished(playerId, playerFinishedIds.size)
// First player finished, he/she wins
if (playerFinishedIds.size == 1) {
this.gameState.setWinner(playerId)
}
// All players are finished
if (playerFinishedIds.size == playerIds.size) {
gameController.setGameFinished(playerFinishedIds)
// TODO: End game
gameController.setGameFinished()
this.gameState.setFinished()
}
}
nextPlayer()
......
......@@ -11,6 +11,7 @@ class GameState(gameMode: GameMode) {
private var rules: AbstractRules
private var isStarted: Boolean
private var winner: Int?
private var isFinished: Boolean = false
init {
this.rules = gameMode.getRules()
......@@ -37,10 +38,7 @@ class GameState(gameMode: GameMode) {
}
fun isFinished(): Boolean {
if (this.winner != null) {
return true
}
return false
return isFinished
}
fun getWinner(): Int? {
......@@ -50,4 +48,8 @@ class GameState(gameMode: GameMode) {
fun setWinner(winner: Int) {
this.winner = winner
}
fun setFinished() {
isFinished = true
}
}
\ No newline at end of file
......@@ -25,15 +25,9 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.utils.Align;
import com.mygdx.game.controllers.GameController;
import com.mygdx.game.controllers.PlayerController;
import com.mygdx.game.model.DefaultBoard;
import com.mygdx.game.model.Game;
import com.mygdx.game.model.GameMode;
import com.mygdx.game.model.GameState;
import com.mygdx.game.model.Lobby;
import com.mygdx.game.model.Player;
import com.mygdx.game.model.gamemodes.rules.DefaultRules;
import com.mygdx.game.views.enums.CharacterAssets;
import com.mygdx.game.views.enums.CinematicAssets;
import com.mygdx.game.views.enums.LobbyAssets;
......@@ -103,8 +97,15 @@ public class LobbyView extends View{
this.portraitAtlas = (TextureAtlas) assetManager.get(CharacterAssets.PortraitsAtlas.path, CharacterAssets.PortraitsAtlas.classType);
this.currentSong = currentSong;
fadeOutVolume = currentSong.getVolume();
if (currentSong == null) {
this.currentSong = Gdx.audio.newMusic(Gdx.files.internal(MenuAssets.LOOP_AUDIO.path));
this.currentSong.setVolume(1);
this.currentSong.setLooping(true);
this.currentSong.play();
} else {
this.currentSong = currentSong;
}
fadeOutVolume = this.currentSong.getVolume();
buttonClickAudio = (Sound) assetManager.get(MenuAssets.BUTTON_CLICK_AUDIO.path, MenuAssets.BUTTON_CLICK_AUDIO.classType);
this.camera = stage.getCamera();
......
......@@ -23,6 +23,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.mygdx.game.Constants;
import com.mygdx.game.controllers.PlayerController;
import com.mygdx.game.views.enums.CharacterAssets;
import com.mygdx.game.views.enums.LobbyAssets;
......@@ -76,14 +77,8 @@ public class MenuView extends View{
assetManager.load(asset.path, asset.classType);
}
shapeRenderer = new ShapeRenderer(); // Used for draw debugging
availableAvatarsHashMap = new HashMap<>();
availableAvatarsHashMap.put(0, "RegularGuy");
availableAvatarsHashMap.put(1, "HipsterGirl");
availableAvatarsHashMap.put(2, "HighSchoolGuy");
availableAvatarsHashMap.put(3, "RocketGuy");
availableAvatarsHashMap.put(4, "AsianGirl");
availableAvatarsHashMap.put(5, "Grandma");
availableAvatarsHashMap = Constants.AVAILABLEAVATARSHASHMAP;
this.backgroundImage = new Image ((Texture) assetManager.get(MenuAssets.BACKGROUND.path, MenuAssets.BACKGROUND.classType));
backgroundImage.setPosition(Gdx.graphics.getWidth()/2-backgroundImage.getWidth()/2, 0);
......
......@@ -6,15 +6,19 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.utils.Scaling;
import com.mygdx.game.Constants;
import com.mygdx.game.controllers.GameController;
import com.mygdx.game.controllers.PlayerController;
import com.mygdx.game.controllers.UtilsKt;
import com.mygdx.game.model.Lobby;
import com.mygdx.game.model.Player;
import com.mygdx.game.views.enums.PlayAssets;
import com.mygdx.game.views.tokens.AnimatedSprite;
......@@ -25,6 +29,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import static com.badlogic.gdx.scenes.scene2d.InputEvent.Type.touchDown;
public class PlayView extends View{
......@@ -42,6 +48,8 @@ public class PlayView extends View{
Texture starPieceHead;
Texture starPieceHeadBorder;
Image boardImage;
Image backgroundImage;
Image rocketImage;
Image rocketExhaustImage;
......@@ -59,7 +67,7 @@ public class PlayView extends View{
// Create background image
Texture background = new Texture("Game/1x/StarBackground1x.png");
Image backgroundImage = new Image(background);
backgroundImage = new Image(background);
backgroundImage.setScaling(Scaling.fill);
backgroundImage.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
......@@ -67,7 +75,7 @@ public class PlayView extends View{
// Create board image
Texture board = new Texture("Game/1x/GameBoard@1x.png");
Image boardImage = new Image(board);
boardImage = new Image(board);
// Calculate scale factors for board and pieces, and corresponding hex side length
float scale_factor_board = Gdx.graphics.getHeight() / boardImage.getHeight();
......@@ -194,6 +202,11 @@ public class PlayView extends View{
rocketExhaustImage.setPosition(rocketImage.getX() - 62F, rocketImage.getY() + 20F - (rocketImage.getHeight()) * rocketImage.getScaleY());
}
public void removeTurnIndicator() {
rocketImage.remove();
rocketExhaustImage.remove();
}
public void setPlayerFinished(int playerIndex, int place) {
// Weaken playername-field
TextField playerNameField = playerNameFields.get(playerIndex);
......@@ -218,6 +231,23 @@ public class PlayView extends View{
stage.addActor(placeField);
}
public void placeHomeButton() {
TextButton homeButton = new TextButton("Exit", skin, "small");
homeButton.setPosition(Gdx.graphics.getWidth() / 2F - homeButton.getWidth() / 2F, Gdx.graphics.getHeight() / 2F - homeButton.getHeight() / 2F);
homeButton.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
startFadeout = true;
playerController.setLobbyPlayerReady(false);
playerController.leaveLobby(playerController.getLobby().getID());
return true;
}
});
stage.addActor(homeButton);
}
@Override
public void fadeIn(float dt) {
stage.getBatch().begin();
......@@ -245,8 +275,8 @@ public class PlayView extends View{
if(fadeOutAlpha >= 1){
stage.clear();
startFadeout = false;
//gvm.set(new CinematicView(gvm, playerController, assetManager, stage, skin, lobbyAvatars));
//gvm.set(new MenuView(gvm, playerController, assetManager, stage, skin));
gvm.set(new LobbyView(gvm, playerController, assetManager, stage, skin, Constants.AVAILABLEAVATARSHASHMAP, null));
}
}
......@@ -296,6 +326,6 @@ public class PlayView extends View{
@Override
public void dispose() {
stage.dispose();
}
}
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