Commit 25eba0ec authored by morkolai's avatar morkolai
Browse files

Merge branch 'default-game' into possible-moves

parents 14d67b8b d38bb6cb
......@@ -7,6 +7,7 @@ import com.mygdx.game.model.Player;
import com.mygdx.game.views.PlayView;
import com.mygdx.game.views.tokens.StarPiece;
import java.util.ArrayList;
import java.util.List;
public class GameController {
......@@ -103,17 +104,9 @@ public class GameController {
}
public void setPlayerFinished(int playerId, int place) {
int playerIndex;
List<Player> players = playerController.getLobby().getPlayers();
for (Player player: players) {
if (player.getID() == playerId) {
playerIndex = players.indexOf(player);
this.view.setPlayerFinished(playerIndex, place);
break;
}
}
List<Integer> playerIds = new ArrayList(model.getPlayerIds());
int playerIndex = playerIds.indexOf(playerId);
this.view.setPlayerFinished(playerIndex, place);
}
public void setGameFinished() {
......
......@@ -38,6 +38,7 @@ public class cLobbyLeave extends Command{
if (playerId == playerController.getPlayer().getID()) {
System.out.println("Request to leave lobby successful");
playerController.setLobby(new Lobby(-1));
playerController.getPlayer().setIsPlayerReady(false);
} else {
System.out.println("Player with id " + playerId + " left");
......
......@@ -136,4 +136,8 @@ class Game(gameState: GameState, playerIds: LinkedHashSet<Int>) {
private fun thereArePlayersLeft(): Boolean {
return playerFinishedIds.size < playerIds.size - playerLeftIds.size
}
fun getPlayerIds(): LinkedHashSet<Int> {
return playerIds
}
}
package com.mygdx.game.views;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.mygdx.game.controllers.PlayerController;
public class PauseView extends AbstractView {
private Texture background;
private Texture playBtn;
public PauseView(GameViewManager gvm, PlayerController playerController, AssetManager assetManager, Stage stage, Skin skin) {
super(gvm, playerController, assetManager, stage, skin);
background = new Texture ("Pause/PauseBackground.png");
playBtn = new Texture ("Pause/PauseButton.png");
Gdx.input.setCursorCatched(true);
}
@Override
public void handleInput(float dt) {
}
@Override
public void update(float dt) {
if(Gdx.input.isKeyPressed(Input.Keys.ANY_KEY)){
gvm.pop();
}
}
@Override
public void render(float dt) {
stage.draw();
}
@Override
public void fadeIn(float dt) {
}
@Override
public void fadeOut(float dt) {
}
@Override
public void dispose() {
background.dispose();
playBtn.dispose();
stage.dispose();
}
}
......@@ -191,7 +191,14 @@ public class PlayView extends AbstractView {
playerNameFields = new ArrayList<>();
for (int i = 0; i < players.size(); i++) {
TextField textField = new TextField(players.get(i).getPlayerName(), skin);
TextField textField;
// Place asterisk in front of client's playername
if (players.get(i).getID() == playerController.getPlayer().getID()) {
textField = new TextField("*" + playerController.getPlayer().getPlayerName(), skin);
} else {
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));
......@@ -274,7 +281,7 @@ public class PlayView extends AbstractView {
homeButton.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
playerController.setLobbyPlayerReady(false);
playerController.getPlayer().setIsPlayerReady(false);
playerController.leaveLobby(playerController.getLobby().getID());
startFadeout = true;
return true;
......@@ -286,12 +293,13 @@ public class PlayView extends AbstractView {
public void placeLeaveButton() {
TextButton leaveButton = new TextButton("Leave", skin, "small");
leaveButton.setPosition(Gdx.graphics.getWidth() / 2F + (boardImage.getWidth() * boardImage.getScaleX()) / 2F, Gdx.graphics.getHeight() - 3F * hex_side_length - leaveButton.getHeight() / 2F);
leaveButton.setSize(col_width, (float)(row_height*0.75));
leaveButton.setPosition(Gdx.graphics.getWidth() / 2 + (boardImage.getWidth() * boardImage.getScaleX()) / 3 - leaveButton.getWidth() / 2, Gdx.graphics.getHeight() - 3F * hex_side_length - leaveButton.getHeight() / 2F);
leaveButton.addListener(new InputListener(){
@Override
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
playerController.setLobbyPlayerReady(false);
playerController.getPlayer().setIsPlayerReady(false);
playerController.leaveLobby(playerController.getLobby().getID());
startFadeout = true;
return true;
......
<component name="libraryTable">
<library name="Gradle: CheckersServer.core.core-1.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/core/build/libs/core-1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
......@@ -26,8 +26,7 @@ public class cLobbyLeave extends Command{
Lobby lobby = net.getLobby(lobbyId);
System.out.printf("Request from Player w. ID: %d to leave Lobby w. ID: %d. Returning Lobby w. ID: %d \n",
playerId, lobbyId, lobbyId);
System.out.printf("Request from Player w. ID: %d to leave Lobby w. ID: %d \n", playerId, lobbyId);
for (Connection c : net.getConnections(lobby)) {
c.sendTCP(this);
......
Markdown is supported
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