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

Colored playernames and turnindicator

parent f328d873
......@@ -19,6 +19,9 @@ public class GameController {
private Vector3 previousCoordinateClicked; // Previously clicked coordinate
private final PlayerController playerController;
private List<Integer> usedBoardSlots;
private List<List<Float>> playerNameTextFieldCoordinates;
public GameController(Game model, PlayView view, PlayerController playerController) {
this.model = model;
this.view = view;
......@@ -28,12 +31,13 @@ public class GameController {
this.previousCoordinateClicked = null;
// Get used boardslots and coordinates to place name of players
List<Integer> playerIndexes = this.model.getUsedBoardSlots(playerController.getLobby().getPlayers().size());
List<List<Float>> playerNameTextFieldCoordinates = this.model.getPlayerNameCoordinates(this.view.hex_side_length);
usedBoardSlots = this.model.getUsedBoardSlots(playerController.getLobby().getPlayers().size());
playerNameTextFieldCoordinates = this.model.getPlayerNameCoordinates(this.view.hex_side_length);
// Initialize pieces and place playernames
this.view.initializePieces(this.model.getStartFieldCoordinates());
this.view.placePlayerNames(playerIndexes, playerNameTextFieldCoordinates);
this.view.placePlayerNames(usedBoardSlots, playerNameTextFieldCoordinates);
this.view.placeRocket(playerNameTextFieldCoordinates.get(0));
}
public void handleClick(float x, float y) {
......@@ -64,6 +68,8 @@ public class GameController {
playerController.getNetWorkController().sendToServer(new cPlayerPieceMove(previousCoordinateClicked, cubeCoordinates, playerController.getLobby().getID(), playerController.getPlayer().getID()));
previousCoordinateClicked = null;
// TODO: Check if all pieces of the player are in goal? (model.isPlayerFinished)
System.out.println(model.isPlayerFinished(playerController.getPlayer().getID()));
this.view.placeRocket(playerNameTextFieldCoordinates.get(this.model.getPlayerTurnSlot()));
} else {
System.out.println("Move was not allowed");
// TODO: Give feedback (move was not valid/not executed)
......@@ -76,6 +82,7 @@ public class GameController {
public void playerMovedPiece(Vector3 fromCoordinates, Vector3 toCoordinates, int playerId) {
if (this.model.movePiece(fromCoordinates, toCoordinates, playerId)) {
this.view.moveOtherPlayerPiece(fromCoordinates, toCoordinates);
this.view.placeRocket(playerNameTextFieldCoordinates.get(this.model.getPlayerTurnSlot()));
} else {
System.out.println("ERROR: Could not execute moving of other players piece");
}
......
......@@ -9,6 +9,7 @@ class Game(gameState: GameState, playerIds: HashSet<Int>) {
private var playerIds: HashSet<Int>
private var playerTurnId: Int
private var playerTurnIndex: Int = 0 // TODO: Random initial value
private var playerTurnSlot: Int = 0; // TODO: Random initial value
init {
this.gameState = gameState
......@@ -50,6 +51,10 @@ class Game(gameState: GameState, playerIds: HashSet<Int>) {
return playerTurnId
}
fun getPlayerTurnSlot(): Int {
return gameState.getRules().getUsedBoardSlots(playerIds.size).get(playerTurnIndex)
}
fun nextPlayer() {
playerTurnIndex++
if (playerTurnIndex == playerIds.size) {
......@@ -64,7 +69,9 @@ class Game(gameState: GameState, playerIds: HashSet<Int>) {
}
fun isPlayerFinished(playerId: Int): Boolean {
val targetFields = this.gameState.getRules().getPlayerTargetFields(playerId)
val boardSlot = gameState.getRules().getUsedBoardSlots(playerIds.size).get(playerIds.indexOf(playerId));
val targetFields = this.gameState.getRules().getPlayerTargetFields(boardSlot)
for (targetField: Vector3 in targetFields) {
if (this.gameState.getBoardState().fields[targetField]?.getPiece()?.getOwnerId() != playerId) {
......
......@@ -8,8 +8,8 @@ abstract class AbstractRules {
abstract var moveRange: Int // How far a piece can be moved
abstract var jumpRange: Int // How many pieces a piece can jump over
abstract fun getPlayerStartfields(playerIndex: Int) : List<Vector3> // Returns a list of startfields for a given player
abstract fun getPlayerTargetFields(playerIndex: Int) : List<Vector3> // Returns a list of targetfields for a given player
abstract fun getPlayerStartfields(boardSlot: Int) : List<Vector3> // Returns a list of startfields for a given player
abstract fun getPlayerTargetFields(boardSlot: Int) : List<Vector3> // Returns a list of targetfields for a given player
abstract fun generateStartFields(playerCount: Int = 6): List<List<Vector3>> // Returns a list with lists of startfields
abstract fun getUsedBoardSlots(playerCount: Int): List<Int> // Returns a list with used boardslots
abstract fun getPlayerNameCoordinates(hex_side_length: Float): List<List<Float>> // Returns a list with lists of coordinates for playernames
......
......@@ -10,21 +10,21 @@ class DefaultRules: AbstractRules() {
override var moveRange = 1
override var jumpRange = 2
override fun getPlayerStartfields(playerIndex: Int): List<Vector3> {
return startFields[playerIndex]
override fun getPlayerStartfields(boardSlot: Int): List<Vector3> {
return startFields[boardSlot]
}
override fun getPlayerTargetFields(playerIndex: Int): List<Vector3> {
var index = playerIndex
override fun getPlayerTargetFields(boardSlot: Int): List<Vector3> {
var slot = boardSlot
for (i in 0..2) {
index++
slot++
// Wrap around to first player
if(index == 6) {
index = 0
if(slot == 6) {
slot = 0
}
}
return startFields[index]
return startFields[slot]
}
// Sequence: top, upperright, lowerright, bottom, lowerleft, upperleft
......
......@@ -722,7 +722,6 @@ public class LobbyView extends View{
if(Gdx.input.justTouched()){
lastTouch[0] = Gdx.input.getX();
lastTouch[1] = stage.getViewport().getScreenHeight()-Gdx.input.getY();
System.out.println("Only once");
}
if(Gdx.input.isTouched()){
float camXPos = camera.position.x + (lastTouch[0]-Gdx.input.getX())* touchSensitivity; //camera.position.x + (Gdx.input.getX()-lastTouch[0])*sensitivity;
......@@ -732,7 +731,6 @@ public class LobbyView extends View{
float b = MathUtils.clamp(camYPos, camera.viewportHeight/2, backgroundImage.getImageHeight()-camera.viewportHeight/2);
camera.position.set(a, b, 0);
System.out.println("Multiple times");
}
}
......
......@@ -25,8 +25,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import javax.xml.soap.Text;
public class PlayView extends View{
......@@ -43,6 +41,9 @@ public class PlayView extends View{
Texture starPieceHead;
Texture starPieceHeadBorder;
Image rocketImage;
Image rocketExhaustImage;
ConcurrentHashMap<Vector3, StarPiece> pieces; // Concurrent to avoid ConcurrentModificationException due to render-function
GameController gameController;
List<TextField> playerNameFields;
......@@ -78,7 +79,6 @@ public class PlayView extends View{
boardImage.setPosition(Gdx.graphics.getWidth() / 2F - boardImage.getWidth() * boardImage.getScaleX() / 2F, Gdx.graphics.getHeight() / 2F - board.getHeight() * boardImage.getScaleY() / 2F);
stage.addActor(boardImage);
for (PlayAssets asset : PlayAssets.values()) {
assetManager.load(asset.path, asset.classType);
}
......@@ -86,6 +86,18 @@ public class PlayView extends View{
setFadeColor(Color.BLACK);
Texture rocket = (Texture) assetManager.get(PlayAssets.ROCKET.path, PlayAssets.ROCKET.classType);
rocketImage = new Image(rocket);
rocketImage.setScale(0.5F, 0.5F);
rocketImage.rotateBy(-30);
stage.addActor(rocketImage);
Texture rocketExhaust = (Texture) assetManager.get(PlayAssets.ROCKET_EXHAUST.path, PlayAssets.ROCKET_EXHAUST.classType);
rocketExhaustImage = new Image(rocketExhaust);
rocketExhaustImage.setScale(0.5F, 0.5F);
rocketExhaustImage.rotateBy(-30);
stage.addActor(rocketExhaustImage);
starPieceBase = (Texture) assetManager.get(PlayAssets.STAR_PIECE_BASE.path, PlayAssets.STAR_PIECE_BASE.classType);
starPieceBaseBorder = (Texture) assetManager.get(PlayAssets.STAR_PIECE_BASE_BORDER.path, PlayAssets.STAR_PIECE_BASE_BORDER.classType);
starPieceMast = (Texture) assetManager.get(PlayAssets.STAR_PIECE_MAST.path, PlayAssets.STAR_PIECE_MAST.classType);
......@@ -94,19 +106,6 @@ public class PlayView extends View{
starPieceHeadBorder = (Texture) assetManager.get(PlayAssets.STAR_PIECE_HEAD_BORDER.path, PlayAssets.STAR_PIECE_HEAD_BORDER.classType);
this.pieces = new ConcurrentHashMap<>();
/*for (Player player : playerController.getLobby().getPlayers()) {
String playerName = player.getPlayerName();
TextField textField = getPlayerNameTextField(player.getPlayerName(), index);
TextField textField = new TextField(player.getPlayerName(), skin);
textField.setSize(300, 80);
textField.setPosition(Gdx.graphics.getWidth() / 2F - textField.getWidth() - (2 * hex_side_length), Gdx.graphics.getHeight() - (3 * hex_side_length));
stage.addActor(textField);
playerNameFields.add(textField);
}*/
}
public void setGameController(GameController gameController) {
......@@ -173,6 +172,27 @@ public class PlayView extends View{
}
}
public void placePlayerNames(List<Integer> usedBoardSlots, List<List<Float>> coordinateList) {
List<Player> players = playerController.getLobby().getPlayers();
playerNameFields = new ArrayList<>();
for (int i = 0; i < players.size(); i++) {
TextField textField = new TextField(players.get(i).getPlayerName(), skin);
textField.setColor(PIECE_COLORS.get(i));
textField.setSize(Constants.PLAYER_NAME_TEXT_FIELD_WIDTH, Constants.PLAYER_NAME_TEXT_FIELD_HEIGHT);
textField.setPosition(coordinateList.get(usedBoardSlots.get(i)).get(0), coordinateList.get(usedBoardSlots.get(i)).get(1));
stage.addActor(textField);
playerNameFields.add(textField);
}
}
public void placeRocket(List<Float> coordinates) {
rocketImage.setPosition(coordinates.get(0) - 60F, coordinates.get(1) + 50F);
rocketExhaustImage.setPosition(rocketImage.getX() - 62F, rocketImage.getY() + 20F - (rocketImage.getHeight()) * rocketImage.getScaleY());
}
@Override
public void fadeIn(float dt) {
stage.getBatch().begin();
......@@ -223,21 +243,6 @@ public class PlayView extends View{
return startFieldCoordinatesPixel;
}
public void placePlayerNames(List<Integer> playerIndexes, List<List<Float>> coordinateList) {
List<Player> players = playerController.getLobby().getPlayers();
playerNameFields = new ArrayList<>();
for (int i = 0; i < players.size(); i++) {
TextField textField = new TextField(players.get(i).getPlayerName(), skin);
textField.setSize(Constants.PLAYER_NAME_TEXT_FIELD_WIDTH, Constants.PLAYER_NAME_TEXT_FIELD_HEIGHT);
textField.setPosition(coordinateList.get(playerIndexes.get(i)).get(0), coordinateList.get(playerIndexes.get(i)).get(1));
stage.addActor(textField);
playerNameFields.add(textField);
}
}
public void movePiece(StarPiece piece, Vector3 toCoordinates) {
Float[] pixelCoordinates = UtilsKt.cubeToPixel(toCoordinates, hex_side_length);
......
......@@ -11,7 +11,9 @@ public enum PlayAssets {
STAR_PIECE_HEAD("Game/1x/StarPiece_Head.png", Texture.class),
STAR_PIECE_HEAD_BORDER("Game/1x/StarPiece_HeadBrd.png", Texture.class),
STAR_PIECE_MAST("Game/1x/StarPiece_Mast.png", Texture.class),
STAR_PIECE_MAST_BORDER("Game/1x/StarPiece_MastBrd.png", Texture.class);
STAR_PIECE_MAST_BORDER("Game/1x/StarPiece_MastBrd.png", Texture.class),
ROCKET("Menu/0.25x/Rocket_Main@0.25x.png", Texture.class),
ROCKET_EXHAUST("Menu/0.25x/Rocket_Exhaust@0.25x.png", Texture.class);
public final String path;
public final Class classType;
......
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