Skip to content
This repository has been archived by the owner on Oct 1, 2022. It is now read-only.

Add a statistics screen at the end of every game #779

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*******************************************************************************/
package jsettlers.common.menu;

import java8.util.function.Consumer;
import jsettlers.common.map.IGraphicsGrid;
import jsettlers.common.player.IInGamePlayer;
import jsettlers.common.statistics.IGameTimeProvider;
Expand Down Expand Up @@ -53,7 +54,12 @@ public IInGamePlayer getInGamePlayer() {
}

@Override
public void setGameExitListener(IGameExitListener exitListener) {
public IInGamePlayer[] getAllInGamePlayers() {
return null;
}

@Override
public void setGameExitListener(Consumer<IStartedGame> exitListener) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
*******************************************************************************/
package jsettlers.common.menu;

import java8.util.function.Consumer;
import jsettlers.common.map.IGraphicsGrid;
import jsettlers.common.player.IEndgameStatistic;
import jsettlers.common.player.IInGamePlayer;
import jsettlers.common.statistics.IGameTimeProvider;

Expand All @@ -27,21 +29,27 @@
public interface IStartedGame {
/**
* Gets the grid that should be displayed to the user.
*
*
* @return
*/
IGraphicsGrid getMap();

/**
* Gets an {@link IGameTimeProvider} implementation used to supply the UI with game time information.
*
*
* @return
*/
IGameTimeProvider getGameTimeProvider();

/**
*
* @return null or all {@link IInGamePlayer}s
*/
IInGamePlayer[] getAllInGamePlayers();

IInGamePlayer getInGamePlayer();

void setGameExitListener(IGameExitListener exitListener);
void setGameExitListener(Consumer<IStartedGame> exitListener);

boolean isShutdownFinished();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public interface IEndgameStatistic {
short getAmountOfProducedSoldiers();
short getAmountOfProducedMana();
short getAmountOfProducedGold();

String getName();

byte getTeam();
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,13 @@ join-game-panel-map-slot = Position
join-game-panel-team = Team
join-game-panel-send-chat-messageLabel = Senden

stats-panel-exit = Weiter
stats-panel-name = Name
stats-panel-team = Team
stats-panel-manna = Manna
stats-panel-gold = Gold
stats-panel-soldiers = rekrutierte Soldaten

peace-time-WITHOUT = keine
player-type-HUMAN = Mensch
player-type-AI_VERY_EASY = Computer (sehr einfach)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ join-game-panel-map-slot = Position
join-game-panel-team = Team
join-game-panel-send-chat-messageLabel = Send

stats-panel-exit = Next
stats-panel-name = Name
stats-panel-team = Team
stats-panel-manna = Manna
stats-panel-gold = Gold
stats-panel-soldiers = recruted soldiers

peace-time-WITHOUT = without
player-type-HUMAN = Human
player-type-AI_VERY_EASY = Computer (very easy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*******************************************************************************/
package jsettlers.logic.player;

import jsettlers.common.ai.EPlayerType;
import jsettlers.common.player.IEndgameStatistic;

import java.io.Serializable;
Expand All @@ -22,14 +23,14 @@
* @author codingberlin
*/
public class EndgameStatistic implements IEndgameStatistic, Serializable {
private static final long serialVersionUID = -1352905249487671842L;
private static final long serialVersionUID = -1352905249487671843L;

private MannaInformation mannaInformation;
private Player player;
private short amountOfProducedSoldiers = 0;
private short amountOfProducedGold = 0;

public EndgameStatistic(MannaInformation mannaInformation) {
this.mannaInformation = mannaInformation;
public EndgameStatistic(Player player) {
this.player = player;
}

@Override
Expand All @@ -39,14 +40,24 @@ public short getAmountOfProducedSoldiers() {

@Override
public short getAmountOfProducedMana() {
return mannaInformation.getAmountOfManna();
return player.getMannaInformation().getAmountOfManna();
}

@Override
public short getAmountOfProducedGold() {
return amountOfProducedGold;
}

@Override
public String getName() {
return player.getPlayerType().toString();
}

@Override
public byte getTeam() {
return player.getTeamId();
}

public void incrementAmountOfProducedSoldiers() {
amountOfProducedSoldiers++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ public class Player implements Serializable, IMessenger, IInGamePlayer, IOffersC
private final Team team;
private final byte numberOfPlayers;
private final MannaInformation mannaInformation = new MannaInformation();
private final MaterialCounts materialCounts = new MaterialCounts();
private final EndgameStatistic endgameStatistic = new EndgameStatistic(mannaInformation);

private final MaterialCounts materialCounts = new MaterialCounts();
private final EndgameStatistic endgameStatistic = new EndgameStatistic(this);

private EWinState winState;

Expand Down
27 changes: 10 additions & 17 deletions jsettlers.logic/src/main/java/jsettlers/main/JSettlersGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
import java.util.Date;
import java.util.Locale;

import java8.util.function.Consumer;

import jsettlers.ai.highlevel.AiExecutor;
import jsettlers.common.CommonConstants;
import jsettlers.common.map.IGraphicsGrid;
import jsettlers.common.menu.EGameError;
import jsettlers.common.menu.EProgressState;
import jsettlers.common.menu.IGameExitListener;
import jsettlers.common.menu.IMapInterfaceConnector;
import jsettlers.common.menu.IStartedGame;
import jsettlers.common.menu.IStartingGame;
Expand Down Expand Up @@ -165,24 +166,11 @@ public synchronized IStartingGame start() {

public void stop() {
synchronized (stopMutex) {
printEndgameStatistic();
stopped = true;
stopMutex.notifyAll();
}
}

// TODO remove me when an EndgameStatistic screen exists.
private void printEndgameStatistic() {
PartitionsGrid partitionsGrid = gameRunner.getMainGrid().getPartitionsGrid();
System.out.println("Endgame statistic:");
for (byte playerId = 0; playerId < partitionsGrid.getNumberOfPlayers(); playerId++) {
Player player = partitionsGrid.getPlayer(playerId);
if (player != null) {
System.out.println("Player " + playerId + ": " + player.getEndgameStatistic());
}
}
}

protected OutputStream createReplayWriteStream() throws IOException {
final String replayFilename = getLogFile(mapCreator, "_replay.log");
return ResourceManager.writeUserFile(replayFilename);
Expand All @@ -194,7 +182,7 @@ public class GameRunner implements Runnable, IStartingGame, IStartedGame, IGameS
private GameTimeProvider gameTimeProvider;
private EProgressState progressState;
private float progress;
private IGameExitListener exitListener;
private Consumer<IStartedGame> exitListener;
private boolean gameRunning;
private AiExecutor aiExecutor;
private WinLoseTracker winLoseTracker;
Expand Down Expand Up @@ -287,7 +275,7 @@ public void run() {
} finally {
shutdownFinished = true;
if (exitListener != null) {
exitListener.gameExited(this);
exitListener.accept(this);
}
}
}
Expand Down Expand Up @@ -368,6 +356,11 @@ public IInGamePlayer getInGamePlayer() {
return mainGrid.getPartitionsGrid().getPlayer(playerId);
}

@Override
public IInGamePlayer[] getAllInGamePlayers() {
return mainGrid.getPartitionsGrid().getPlayers();
}

@Override
public boolean isShutdownFinished() {
return shutdownFinished;
Expand All @@ -384,7 +377,7 @@ public void stopGame() {
}

@Override
public void setGameExitListener(IGameExitListener exitListener) {
public void setGameExitListener(Consumer<IStartedGame> exitListener) {
this.exitListener = exitListener;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
import android.widget.Toast;

import go.graphics.android.AndroidSoundPlayer;
import java8.util.function.Consumer;
import jsettlers.common.action.Action;
import jsettlers.common.action.EActionType;
import jsettlers.common.action.SetSpeedAction;
import jsettlers.common.menu.IGameExitListener;
import jsettlers.common.menu.IStartedGame;
import jsettlers.main.android.R;
import jsettlers.main.android.gameplay.gamemenu.GameSpeedLiveData;

/**
* GameMenu is a singleton within the scope of a started game
*/
public class GameMenu implements IGameExitListener {
public class GameMenu implements Consumer<IStartedGame> {
public enum GameState {
PLAYING,
CONFIRM_QUIT,
Expand Down Expand Up @@ -148,7 +148,7 @@ public boolean isMultiplayer() {
* IGameExitedListener implementation
*/
@Override
public void gameExited(IStartedGame game) {
public void accept(IStartedGame game) {
gameState.postValue(GameState.QUITTED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import jsettlers.main.swing.menu.joinpanel.JoinGamePanel;
import jsettlers.main.swing.menu.mainmenu.MainMenuPanel;
import jsettlers.main.swing.menu.startinggamemenu.StartingGamePanel;
import jsettlers.main.swing.menu.statspanel.EndgameStatsPanel;
import jsettlers.main.swing.settings.SettingsManager;
import jsettlers.main.swing.settings.UiPlayer;

Expand All @@ -58,6 +59,7 @@ public class JSettlersFrame extends JFrame {

private final IMultiplayerConnector multiPlayerConnector;
private final MainMenuPanel mainPanel;
private final EndgameStatsPanel endgameStatsPanel = new EndgameStatsPanel(this);
private final StartingGamePanel startingGamePanel = new StartingGamePanel(this);
private final JoinGamePanel joinGamePanel = new JoinGamePanel(this);
private final SoundPlayer soundPlayer = new SwingSoundPlayer(SettingsManager.getInstance());
Expand Down Expand Up @@ -194,10 +196,15 @@ public void showJoinMultiplayerMenu(IJoinPhaseMultiplayerGameConnector joinPhase
setNewContentPane(joinGamePanel);
}

public void showEndgameStatistics(IStartedGame game) {
endgameStatsPanel.setGame(game);
setNewContentPane(endgameStatsPanel);
}

public IMapInterfaceConnector showStartedGame(IStartedGame startedGame) {
MapContent content = new MapContent(startedGame, soundPlayer, SettingsManager.getInstance().getFpsLimit(), ETextDrawPosition.TOP_RIGHT);
SwingUtilities.invokeLater(() -> setContent(content));
startedGame.setGameExitListener(exitGame -> SwingUtilities.invokeLater(this::showMainMenu));
startedGame.setGameExitListener(exitGame -> SwingUtilities.invokeLater(() -> showEndgameStatistics(exitGame)));
return content.getInterfaceConnector();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ public enum ELFStyle {
/**
* Combobox in settler style
*/
COMBOBOX;
COMBOBOX,

/**
* Tables in settlers label style
*/
TABLE;

/**
* Key used for putClientProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import jsettlers.main.swing.lookandfeel.factory.ProgressBarUiFactory;
import jsettlers.main.swing.lookandfeel.factory.ScrollPaneUiFactory;
import jsettlers.main.swing.lookandfeel.factory.ScrollbarUiFactory;
import jsettlers.main.swing.lookandfeel.factory.TableUiFactory;
import jsettlers.main.swing.lookandfeel.factory.TextAreaUiFactory;
import jsettlers.main.swing.lookandfeel.factory.TextFieldUiFactory;
import jsettlers.main.swing.lookandfeel.factory.ToggleButtonUiFactory;
Expand Down Expand Up @@ -67,6 +68,7 @@ public static void install() throws JSettlersLookAndFeelExecption {
TextFieldUiFactory.FORWARD.loadFromType("TextFieldUI");
ButtonUiFactory.FORWARD.loadFromType("ButtonUI");
LabelUiFactory.FORWARD.loadFromType("LabelUI");
TableUiFactory.FORWARD.loadFromType("TableUI");
// Panel handles all UI types
// PanelUiFactory.FORWARD.loadFromType("PanelUI");
// ScrollPane handles all UI types
Expand Down Expand Up @@ -102,6 +104,7 @@ public static void install() throws JSettlersLookAndFeelExecption {
"ProgressBarUI", ProgressBarUiFactory.class.getName(),
"TextAreaUI", TextAreaUiFactory.class.getName(),
"ComboBoxUI", ComboboxUiFactory.class.getName(),
"TableUI", TableUiFactory.class.getName(),
};
UIManager.getDefaults().putDefaults(uiFactories);

Expand Down
Loading