Commit e61a050c authored by Matyáš Latner's avatar Matyáš Latner

Merge branch 'feature_reports' into 'V3.4'

Feature reports

See merge request !501
parents 3507ce4f 0a4266cb
Subproject commit fdee988573fde42cd99fbc55e4414f9b7cfcb560 Subproject commit d789f13b16efb7f951a9787e5a5701530bbe158b
...@@ -60,11 +60,6 @@ public class TablexiaSettings { ...@@ -60,11 +60,6 @@ public class TablexiaSettings {
public static final String LOCALE_KEY = "locale"; public static final String LOCALE_KEY = "locale";
private static final String SELECTED_USER = "selected_user"; private static final String SELECTED_USER = "selected_user";
public static final int EXPERIENCE_POINTS_TUTORIAL = 0;
public static final int EXPERIENCE_POINTS_EASY = 1;
public static final int EXPERIENCE_POINTS_MEDIUM = 2;
public static final int EXPERIENCE_POINTS_HARD = 3;
//Interval <start month; end month> //Interval <start month; end month>
private static final int WINTER_MODE_START_MONTH = 10; private static final int WINTER_MODE_START_MONTH = 10;
private static final int WINTER_MODE_END_MONTH = 2; private static final int WINTER_MODE_END_MONTH = 2;
...@@ -429,28 +424,28 @@ public class TablexiaSettings { ...@@ -429,28 +424,28 @@ public class TablexiaSettings {
} }
public enum LocaleDefinition { public enum LocaleDefinition {
SYSTEM (null, "system", 0, ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_SYSTEM, true), SYSTEM (null, null, "system", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_SYSTEM, true),
cs_CZ (new Locale("cs", "CZ"), "cs_CZ", 1, ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_CZECH, true), cs_CZ (cz.nic.tablexia.shared.model.definitions.LocaleDefinition.cs_CZ, new Locale("cs", "CZ"), "cs_CZ", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_CZECH, true),
sk_SK (new Locale("sk", "SK"), "sk_SK", 2, ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_SLOVAK, true), sk_SK (cz.nic.tablexia.shared.model.definitions.LocaleDefinition.sk_SK, new Locale("sk", "SK"), "sk_SK", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_SLOVAK, true),
de_DE (new Locale("de", "DE"), "de_DE", 3, ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_GERMAN, true); de_DE (cz.nic.tablexia.shared.model.definitions.LocaleDefinition.de_DE, new Locale("de", "DE"), "de_DE", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_GERMAN, true);
public final static LocaleDefinition DEFAULT_LOCALE = LocaleDefinition.cs_CZ; public final static LocaleDefinition DEFAULT_LOCALE = LocaleDefinition.cs_CZ;
private final static LocaleDefinition FALLBACK_VARIANT = LocaleDefinition.SYSTEM; private final static LocaleDefinition FALLBACK_VARIANT = LocaleDefinition.SYSTEM;
private final Locale locale; private final cz.nic.tablexia.shared.model.definitions.LocaleDefinition modelLocaleDefinition;
private final String localeKey; private final Locale locale;
private final int localeNumber; private final String localeKey;
private final String descriptionKey; private final String descriptionKey;
private boolean enabled; private final boolean enabled;
private static List<LocaleDefinition> enabledLocaleDefinitions; private static List<LocaleDefinition> enabledLocaleDefinitions;
LocaleDefinition(Locale locale, String localeKey, int localeNumber, String descriptionKey, boolean enabled) { LocaleDefinition(cz.nic.tablexia.shared.model.definitions.LocaleDefinition modelLocaleDefinition, Locale locale, String localeKey, String descriptionKey, boolean enabled) {
this.locale = locale; this.modelLocaleDefinition = modelLocaleDefinition;
this.localeKey = localeKey; this.locale = locale;
this.localeNumber = localeNumber; this.localeKey = localeKey;
this.descriptionKey = descriptionKey; this.descriptionKey = descriptionKey;
this.enabled = enabled; this.enabled = enabled;
} }
public String getLocaleKey() { public String getLocaleKey() {
...@@ -458,7 +453,7 @@ public class TablexiaSettings { ...@@ -458,7 +453,7 @@ public class TablexiaSettings {
} }
public int getLocaleNumber() { public int getLocaleNumber() {
return localeNumber; return getLocaleDefinitionForLocale(getLocale()).modelLocaleDefinition.number();
} }
public String getDescriptionKey() { public String getDescriptionKey() {
......
...@@ -79,6 +79,8 @@ import cz.nic.tablexia.screen.halloffame.trophy.TrophyHelper; ...@@ -79,6 +79,8 @@ import cz.nic.tablexia.screen.halloffame.trophy.TrophyHelper;
import cz.nic.tablexia.screen.profile.ProfileScreen; import cz.nic.tablexia.screen.profile.ProfileScreen;
import cz.nic.tablexia.shared.model.Game; import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.shared.model.GameScore; import cz.nic.tablexia.shared.model.GameScore;
import cz.nic.tablexia.shared.model.definitions.DifficultyDefinition;
import cz.nic.tablexia.shared.model.definitions.GameResultDefinition;
import cz.nic.tablexia.util.Log; import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.MusicUtil; import cz.nic.tablexia.util.MusicUtil;
import cz.nic.tablexia.util.actions.MoveAlongAction; import cz.nic.tablexia.util.actions.MoveAlongAction;
...@@ -127,30 +129,43 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T> ...@@ -127,30 +129,43 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
public enum GameResult { public enum GameResult {
NO_STAR(0, null), NO_STAR (GameResultDefinition.NO_STAR, null),
ONE_STAR(1, RATINGSTAR1_SOUND), ONE_STAR (GameResultDefinition.ONE_STAR, RATINGSTAR1_SOUND),
TWO_STAR(2, RATINGSTAR2_SOUND), TWO_STAR (GameResultDefinition.TWO_STAR, RATINGSTAR2_SOUND),
THREE_STAR(3, RATINGSTAR3_SOUND); THREE_STAR (GameResultDefinition.THREE_STAR, RATINGSTAR3_SOUND);
private int starCount; private GameResultDefinition gameResultDefinition;
private String startSoundName; private String startSoundName;
GameResult(int starCount, String startSoundName) { GameResult(GameResultDefinition gameResultDefinition, String startSoundName) {
this.starCount = starCount; this.gameResultDefinition = gameResultDefinition;
this.startSoundName = startSoundName; this.startSoundName = startSoundName;
} }
public int getStarCount() { public int getStarCount() {
return starCount; return gameResultDefinition.number();
} }
public String getStartSoundName() { public String getStartSoundName() {
return startSoundName; return startSoundName;
} }
public GameResultDefinition getGameResultDefinition() {
return gameResultDefinition;
}
public static GameResult getGameResultForStartCount(int starCount) { public static GameResult getGameResultForStartCount(int starCount) {
for (GameResult gameResult : GameResult.values()) { for (GameResult gameResult : GameResult.values()) {
if (gameResult.starCount == starCount) { if (gameResult.getStarCount() == starCount) {
return gameResult;
}
}
return null;
}
public static GameResult getGameResultForGameResultDefinition(GameResultDefinition gameCupsResult) {
for(GameResult gameResult : values()) {
if(gameResult.gameResultDefinition == gameCupsResult) {
return gameResult; return gameResult;
} }
} }
...@@ -514,7 +529,7 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T> ...@@ -514,7 +529,7 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
@Override @Override
public void clicked(InputEvent event, float x, float y) { public void clicked(InputEvent event, float x, float y) {
if(getGamePhase() == GamePhase.STARTED) { if(getGamePhase() == GamePhase.STARTED) {
forceGameEnd(GameResult.THREE_STAR); forceGameEnd(GameResultDefinition.THREE_STAR);
debugEndGameButton.setDisabled(); debugEndGameButton.setDisabled();
} }
} }
...@@ -1369,15 +1384,15 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T> ...@@ -1369,15 +1384,15 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
ApplicationBus.getInstance().publishAsync(new StartIncrementalSynchronizationEvent(getSelectedUser().getId())); ApplicationBus.getInstance().publishAsync(new StartIncrementalSynchronizationEvent(getSelectedUser().getId()));
} }
private void forceGameEnd(GameResult gameResult) { private void forceGameEnd(GameResultDefinition gameResult) {
List<GameScore> gameScores = GameDefinition.getGameDefinitionForClass(getClass()).getGameResultResolver().getGameScoreList(getGameDifficulty(), gameResult); List<GameScore> gameScores = GameDefinition.getGameDefinitionForClass(getClass()).getGameResultResolver().getExampleScoreForGameResult(getGameDifficulty().getDifficultyDefinition(), gameResult);
setGameScores(gameScores); setGameScores(gameScores);
waitForActualGameScore(); waitForActualGameScore();
onForceGameEnd(gameResult); onForceGameEnd(gameResult);
} }
protected void onForceGameEnd(GameResult gameResult) { protected void onForceGameEnd(GameResultDefinition gameResult) {
endGame(); endGame();
showGameResultDialog(); showGameResultDialog();
} }
......
...@@ -23,6 +23,7 @@ import java.util.List; ...@@ -23,6 +23,7 @@ import java.util.List;
import cz.nic.tablexia.TablexiaSettings; import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.loader.application.ApplicationTextManager; import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.shared.model.Game; import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.shared.model.definitions.DifficultyDefinition;
/** /**
* Game difficulty types * Game difficulty types
...@@ -31,29 +32,31 @@ import cz.nic.tablexia.shared.model.Game; ...@@ -31,29 +32,31 @@ import cz.nic.tablexia.shared.model.Game;
*/ */
public enum GameDifficulty { public enum GameDifficulty {
TUTORIAL(0, TablexiaSettings.EXPERIENCE_POINTS_TUTORIAL, "gamedifficulty_tutorial", false, false), TUTORIAL(DifficultyDefinition.TUTORIAL, "gamedifficulty_tutorial", false, false),
EASY (1, TablexiaSettings.EXPERIENCE_POINTS_EASY, "gamedifficulty_easy", true, true), EASY (DifficultyDefinition.EASY, "gamedifficulty_easy", true, true),
MEDIUM (2, TablexiaSettings.EXPERIENCE_POINTS_MEDIUM, "gamedifficulty_medium", true, true), MEDIUM (DifficultyDefinition.MEDIUM, "gamedifficulty_medium", true, true),
HARD (3, TablexiaSettings.EXPERIENCE_POINTS_HARD, "gamedifficulty_hard", true, true); HARD (DifficultyDefinition.HARD, "gamedifficulty_hard", true, true);
public static final GameDifficulty DEFAULT_DIFFICULTY = EASY; public static final GameDifficulty DEFAULT_DIFFICULTY = EASY;
private int difficultyNumber; private final DifficultyDefinition difficultyDefinition;
private int experiencePointsMultiplier; private final String descriptionResourceKey;
private String descriptionResourceKey; private final boolean visible;
private boolean visible; private final boolean hasScore;
private boolean hasScore;
GameDifficulty(int difficultyNumber, int experiencePointsMultiplier, String descriptionResourceKey, boolean visible, boolean hasScore) { GameDifficulty(DifficultyDefinition difficultyDefinition, String descriptionResourceKey, boolean visible, boolean hasScore) {
this.difficultyNumber = difficultyNumber; this.difficultyDefinition = difficultyDefinition;
this.experiencePointsMultiplier = experiencePointsMultiplier;
this.descriptionResourceKey = descriptionResourceKey; this.descriptionResourceKey = descriptionResourceKey;
this.visible = visible; this.visible = visible;
this.hasScore = hasScore; this.hasScore = hasScore;
} }
public DifficultyDefinition getDifficultyDefinition() {
return difficultyDefinition;
}
public int getDifficultyNumber() { public int getDifficultyNumber() {
return difficultyNumber; return difficultyDefinition.number();
} }
public String getTextDescription() { public String getTextDescription() {
...@@ -85,7 +88,7 @@ public enum GameDifficulty { ...@@ -85,7 +88,7 @@ public enum GameDifficulty {
public static GameDifficulty getGameDifficultyForDifficultyNumber(int difficultyNumber) { public static GameDifficulty getGameDifficultyForDifficultyNumber(int difficultyNumber) {
for (GameDifficulty gameDifficulty: GameDifficulty.values()) { for (GameDifficulty gameDifficulty: GameDifficulty.values()) {
if (gameDifficulty.difficultyNumber == difficultyNumber) { if (gameDifficulty.difficultyDefinition.number() == difficultyNumber) {
return gameDifficulty; return gameDifficulty;
} }
} }
...@@ -97,7 +100,7 @@ public enum GameDifficulty { ...@@ -97,7 +100,7 @@ public enum GameDifficulty {
} }
public int getExperiencePointsMultiplier() { public int getExperiencePointsMultiplier() {
return experiencePointsMultiplier; return difficultyDefinition.getExperiencePointsMultiplier();
} }
public boolean hasScore() { public boolean hasScore() {
......
...@@ -40,7 +40,6 @@ import java.util.TimerTask; ...@@ -40,7 +40,6 @@ import java.util.TimerTask;
import cz.nic.tablexia.TablexiaApplication; import cz.nic.tablexia.TablexiaApplication;
import cz.nic.tablexia.game.AbstractTablexiaGame; import cz.nic.tablexia.game.AbstractTablexiaGame;
import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.difficulty.GameDifficulty; import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.crime_scene.actors.PlaySoundScreen; import cz.nic.tablexia.game.games.crime_scene.actors.PlaySoundScreen;
import cz.nic.tablexia.game.games.crime_scene.assets.CrimeSceneAssets; import cz.nic.tablexia.game.games.crime_scene.assets.CrimeSceneAssets;
...@@ -50,7 +49,7 @@ import cz.nic.tablexia.game.games.crime_scene.gameobject.GameObjectType; ...@@ -50,7 +49,7 @@ import cz.nic.tablexia.game.games.crime_scene.gameobject.GameObjectType;
import cz.nic.tablexia.game.games.crime_scene.model.*; import cz.nic.tablexia.game.games.crime_scene.model.*;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager; import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
import cz.nic.tablexia.loader.application.ApplicationInternalTextureManager; import cz.nic.tablexia.loader.application.ApplicationInternalTextureManager;
import cz.nic.tablexia.shared.model.GameScore; import cz.nic.tablexia.shared.model.resolvers.CrimeSceneScoreResolver;
import cz.nic.tablexia.util.ScaleUtil; import cz.nic.tablexia.util.ScaleUtil;
import cz.nic.tablexia.util.ui.AnimatedImage; import cz.nic.tablexia.util.ui.AnimatedImage;
import cz.nic.tablexia.util.ui.actionwidget.Action; import cz.nic.tablexia.util.ui.actionwidget.Action;
...@@ -82,8 +81,9 @@ public class CrimeSceneGame extends AbstractTablexiaGame<CrimeSceneGameState> { ...@@ -82,8 +81,9 @@ public class CrimeSceneGame extends AbstractTablexiaGame<CrimeSceneGameState> {
private static final int GAME_MAP_PADDING = 25; private static final int GAME_MAP_PADDING = 25;
private static final int GAME_MAP_SIZE = 625; private static final int GAME_MAP_SIZE = 625;
private static final int ACTION_CARD_EXTRA_LARGE = 2 * ACTION_CARD_DRAG_SIZE; private static final int ACTION_CARD_EXTRA_LARGE = 2 * ACTION_CARD_DRAG_SIZE;
private static final String SCORE_KEY_COUNT = "score_count";
private static final String RESULT_SCORE_COUNT = "result_score_count"; private static final String SCORE_KEY_COUNT = CrimeSceneScoreResolver.SCORE_KEY_COUNT;
private static final String RESULT_SCORE_COUNT = CrimeSceneScoreResolver.RESULT_SCORE_COUNT;
private static final float ANIMATION_DURATION = 0.3f; private static final float ANIMATION_DURATION = 0.3f;
private static final float FADE_DURATION = 1f; private static final float FADE_DURATION = 1f;
...@@ -123,39 +123,6 @@ public class CrimeSceneGame extends AbstractTablexiaGame<CrimeSceneGameState> { ...@@ -123,39 +123,6 @@ public class CrimeSceneGame extends AbstractTablexiaGame<CrimeSceneGameState> {
private int level = 1; private int level = 1;
private int wrongRounds = 0; private int wrongRounds = 0;
public static class GameResultResolver extends GameDefinition.GameResultResolver {
private static final String FORMATTED_TEXT_FOR_STATISTICS_FORMAT = "%d / %d";
@Override
public AbstractTablexiaGame.GameResult getGameCupsResult(Game game) {
return ResultStars.getStarCountForDifficultyAndErrors(GameDifficulty.getGameDifficultyForDifficultyNumber(game.getGameDifficulty()),
Integer.parseInt(game.getGameScore(SCORE_KEY_COUNT, String.valueOf(correctSounds))));
}
@Override
public float getGameScoreResult(Game game) {
return Float.parseFloat(game.getGameScore(SCORE_KEY_COUNT, String.valueOf(correctSounds)));
}
@Override
public float getStatisticsScore(Game game) {
//Score to sort graph values in statistics is calculated as "actualScore / maxScore". So 2 cups on hard difficulty wont show up higher than 3 cups on medium difficulty.
return getGameScoreResult(game) / (float)(getMaxScoreForDifficulty(GameDifficulty.getGameDifficultyForDifficultyNumber(game.getGameDifficulty())));
}
@Override
public String getFormattedScoreForStatistics(Game game) {
return String.format(FORMATTED_TEXT_FOR_STATISTICS_FORMAT, Math.round(getGameScoreResult(game)), getMaxScoreForDifficulty(GameDifficulty.getGameDifficultyForDifficultyNumber(game.getGameDifficulty())));
}
@Override
public List<GameScore> getGameScoreList(GameDifficulty difficulty, GameResult result) {
ArrayList gameScoreList = new ArrayList<GameScore>(1);
gameScoreList.add(new GameScore(SCORE_KEY_COUNT, String.valueOf(ResultStars.getScoreForGameResultAndDifficulty(result, difficulty))));
return gameScoreList;
}
}
@Override @Override
protected void gameLoaded(java.util.Map gameState) { protected void gameLoaded(java.util.Map gameState) {
setUpActionsStripWidget(); setUpActionsStripWidget();
......
...@@ -38,9 +38,8 @@ import java.util.Map; ...@@ -38,9 +38,8 @@ import java.util.Map;
import cz.nic.tablexia.TablexiaApplication; import cz.nic.tablexia.TablexiaApplication;
import cz.nic.tablexia.TablexiaSettings; import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.game.AbstractTablexiaGame; import cz.nic.tablexia.game.AbstractTablexiaGame;
import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.in_the_darkness.action.InTheDarknessActionType; import cz.nic.tablexia.game.games.in_the_darkness.action.InTheDarknessActionType;
import cz.nic.tablexia.shared.model.resolvers.InTheDarknessScoreResolver;
import cz.nic.tablexia.util.ui.actionwidget.Action; import cz.nic.tablexia.util.ui.actionwidget.Action;
import cz.nic.tablexia.util.ui.actionwidget.ActionContainer; import cz.nic.tablexia.util.ui.actionwidget.ActionContainer;
import cz.nic.tablexia.util.ui.actionwidget.ActionsStripWidget; import cz.nic.tablexia.util.ui.actionwidget.ActionsStripWidget;
...@@ -56,7 +55,6 @@ import cz.nic.tablexia.loader.application.ApplicationInternalTextureManager; ...@@ -56,7 +55,6 @@ import cz.nic.tablexia.loader.application.ApplicationInternalTextureManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager; import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.model.game.GameDAO; import cz.nic.tablexia.model.game.GameDAO;
import cz.nic.tablexia.shared.model.Game; import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.shared.model.GameScore;
import cz.nic.tablexia.util.Log; import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.ScaleUtil; import cz.nic.tablexia.util.ScaleUtil;
import cz.nic.tablexia.util.ui.AnimatedImage; import cz.nic.tablexia.util.ui.AnimatedImage;
...@@ -82,48 +80,6 @@ import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence; ...@@ -82,48 +80,6 @@ import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence;
* Created by Matyáš Latner on 7.9.15. * Created by Matyáš Latner on 7.9.15.
*/ */
public class InTheDarknessGame extends AbstractTablexiaGame<List<MapWidget>> implements MapWidget.TileMapClickListener { public class InTheDarknessGame extends AbstractTablexiaGame<List<MapWidget>> implements MapWidget.TileMapClickListener {
public static class GameResultResolver extends GameDefinition.GameResultResolver {
public static final int ERROR_COUNT_THREE_STARS = 2;
public static final int ERROR_COUNT_TWO_STARS = 4;
public static final int ERROR_COUNT_ONE_STAR = 8;
@Override
public AbstractTablexiaGame.GameResult getGameCupsResult(Game game) {
Integer errorsCount = Integer.valueOf(game.getGameScoreValue(InTheDarknessGame.SCORE_KEY_ERRORS_COUNT));
if (errorsCount < ERROR_COUNT_THREE_STARS) {
return AbstractTablexiaGame.GameResult.THREE_STAR;
} else if (errorsCount < ERROR_COUNT_TWO_STARS) {
return AbstractTablexiaGame.GameResult.TWO_STAR;
} else if (errorsCount < ERROR_COUNT_ONE_STAR) {
return AbstractTablexiaGame.GameResult.ONE_STAR;
} else {
return AbstractTablexiaGame.GameResult.NO_STAR;
}
}
@Override
public float getGameScoreResult(Game game) {
return Float.parseFloat(game.getGameScore(InTheDarknessGame.SCORE_KEY_ERRORS_COUNT, "0"));
}
@Override
public List<GameScore> getGameScoreList(GameDifficulty difficulty, GameResult result) {
int errors;
switch (result) {
case NO_STAR: errors = GameResultResolver.ERROR_COUNT_ONE_STAR + 1; break;
case ONE_STAR: errors = GameResultResolver.ERROR_COUNT_ONE_STAR - 1; break;
case TWO_STAR: errors = GameResultResolver.ERROR_COUNT_TWO_STARS - 1; break;
default: errors = GameResultResolver.ERROR_COUNT_THREE_STARS - 1; break;
}
List<GameScore> gameScores = new ArrayList<GameScore>(1);
gameScores.add(new GameScore(SCORE_KEY_ERRORS_COUNT, Integer.toString(errors)));
return gameScores;
}
}
public enum GameLayer { public enum GameLayer {
BACKGROUND_TEXTURE_LAYER (0, Touchable.disabled), BACKGROUND_TEXTURE_LAYER (0, Touchable.disabled),
...@@ -183,8 +139,8 @@ public class InTheDarknessGame extends AbstractTablexiaGame<List<MapWidget>> imp ...@@ -183,8 +139,8 @@ public class InTheDarknessGame extends AbstractTablexiaGame<List<MapWidget>> imp
} }
} }
private static final String SCORE_KEY_PLANNING_DURATION = "planning_duration"; private static final String SCORE_KEY_PLANNING_DURATION = InTheDarknessScoreResolver.SCORE_KEY_PLANNING_DURATION;
public static final String SCORE_KEY_ERRORS_COUNT = "errors_count"; public static final String SCORE_KEY_ERRORS_COUNT = InTheDarknessScoreResolver.SCORE_KEY_ERRORS_COUNT;
private static final Interpolation.Pow FADE_IN_INTERPOLATION = Interpolation.pow2; private static final Interpolation.Pow FADE_IN_INTERPOLATION = Interpolation.pow2;
private static final float FADE_DURATION = 0.4f; private static final float FADE_DURATION = 0.4f;
......
...@@ -27,6 +27,7 @@ import java.util.Random; ...@@ -27,6 +27,7 @@ import java.util.Random;
import cz.nic.tablexia.game.difficulty.GameDifficulty; import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.kidnapping.generator.PathGenerator; import cz.nic.tablexia.game.games.kidnapping.generator.PathGenerator;
import cz.nic.tablexia.game.games.kidnapping.generator.SoundPathGenerator; import cz.nic.tablexia.game.games.kidnapping.generator.SoundPathGenerator;
import cz.nic.tablexia.shared.model.resolvers.KidnappingScoreResolver;
import cz.nic.tablexia.util.ui.tilemapgenerator.Position; import cz.nic.tablexia.util.ui.tilemapgenerator.Position;
import cz.nic.tablexia.game.games.kidnapping.generator.TileMapGenerator; import cz.nic.tablexia.game.games.kidnapping.generator.TileMapGenerator;
import cz.nic.tablexia.game.games.kidnapping.media.DirectionSounds; import cz.nic.tablexia.game.games.kidnapping.media.DirectionSounds;
...@@ -39,9 +40,9 @@ import cz.nic.tablexia.shared.model.Game; ...@@ -39,9 +40,9 @@ import cz.nic.tablexia.shared.model.Game;
* Created by lhoracek on 5/15/15. * Created by lhoracek on 5/15/15.
*/ */
public class GameState { public class GameState {
public static final String GAME_MISSES = "GAME_MISSES"; public static final String GAME_MISSES = KidnappingScoreResolver.GAME_MISSES;
public static final String GAME_REPLAYS = "GAME_REPLAYS"; public static final String GAME_REPLAYS = KidnappingScoreResolver.GAME_REPLAYS;
public static final String GAME_STEP = "GAME_STEP"; public static final String GAME_STEP = KidnappingScoreResolver.GAME_STEP;
private final Map<Position, TileType> map; private final Map<Position, TileType> map;
......
/*
* Copyright (C) 2016 CZ.NIC, z.s.p.o. <info@tablexia.cz>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cz.nic.tablexia.game.games.kidnapping.util;
import java.util.ArrayList;
import java.util.List;
import cz.nic.tablexia.game.AbstractTablexiaGame;
import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.kidnapping.Properties;
import cz.nic.tablexia.game.games.kidnapping.model.GameState;
import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.shared.model.GameScore;
/**
* Created by lhoracek on 10/6/15.
*/
public class KidnappingResultResolver extends GameDefinition.GameResultResolver {
@Override
public AbstractTablexiaGame.GameResult getGameCupsResult(Game game) {
int[] levels = Properties.GAMERULE_CUPS[game.getGameDifficulty() - 1];
if (game.getGameScoreValue(GameState.GAME_MISSES) != null) {
int misses = Integer.valueOf(game.getGameScoreValue(GameState.GAME_MISSES));
if (misses <= levels[0]) {
return AbstractTablexiaGame.GameResult.THREE_STAR;
} else if (misses <= levels[1]) {
return AbstractTablexiaGame.GameResult.TWO_STAR;
} else if (misses <= levels[2]) {
return AbstractTablexiaGame.GameResult.ONE_STAR;
}
}
return AbstractTablexiaGame.GameResult.NO_STAR;
}
@Override
public float getGameScoreResult(Game game) {
return Float.parseFloat(game.getGameScore(GameState.GAME_MISSES, "0"));
}
@Override
public List<GameScore> getGameScoreList(GameDifficulty difficulty, AbstractTablexiaGame.GameResult result) {
int[] levels = Properties.GAMERULE_CUPS[difficulty.getDifficultyNumber() - 1];
int misses;
switch (result) {
case NO_STAR:
misses = levels[2] + 1;
break;
case ONE_STAR:
misses = levels[2];
break;
case TWO_STAR:
misses = levels[1];
break;
default:
misses = 0;
break;
}
List<GameScore> gameScores = new ArrayList<GameScore>(1);
gameScores.add(new GameScore(GameState.GAME_MISSES, Integer.toString(misses)));
return gameScores;
}
}
...@@ -55,6 +55,7 @@ import cz.nic.tablexia.loader.application.ApplicationInternalTextureManager; ...@@ -55,6 +55,7 @@ import cz.nic.tablexia.loader.application.ApplicationInternalTextureManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager; import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.shared.model.Game; import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.shared.model.GameScore; import cz.nic.tablexia.shared.model.GameScore;
import cz.nic.tablexia.shared.model.resolvers.NightWatchScoreResolver;
import cz.nic.tablexia.util.Log; import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.Utility; import cz.nic.tablexia.util.Utility;
import cz.nic.tablexia.util.ui.AnimatedImage; import cz.nic.tablexia.util.ui.AnimatedImage;
...@@ -68,77 +69,6 @@ import cz.nic.tablexia.util.ui.dialog.components.TwoColumnContentDialogComponent ...@@ -68,77 +69,6 @@ import cz.nic.tablexia.util.ui.dialog.components.TwoColumnContentDialogComponent
* Created by Václav Tarantík on 6.3.15. * Created by Václav Tarantík on 6.3.15.
*/ */
public class NightWatchGame extends AbstractTablexiaGame<int[][]> { public class NightWatchGame extends AbstractTablexiaGame<int[][]> {
public static class GameResultResolver extends GameDefinition.GameResultResolver {
private final int MAX_OLD_SCORE = 16;
private final int MAX_NEW_SCORE = 12;
private final int MIN_NEW_SCORE = 2;
@Override
public GameResult getGameCupsResult(Game game) {
if(game.getApplicationVersionCode() > Game.DEFAULT_APPLICATION_VERSION_CODE) {
return GameRulesHelper.getNumberOfStarsForResult(Integer.parseInt(game.getGameScore(SCORE_ROUND_COUNT, "0")), false);
} else {
int correctWindows = LEVELS_COUNT - Integer.valueOf(game.getGameScoreValue(SCORE_WRONG_WINDOWS));
int correctTimeCount = LEVELS_COUNT - Integer.valueOf(game.getGameScoreValue(SCORE_WRONG_TIME));
return GameRulesHelper.getNumberOfStarsForResult(correctWindows + correctTimeCount, true);
}
}
@Override
public float getGameScoreResult(Game game) {
if(game.getApplicationVersionCode() > Game.DEFAULT_APPLICATION_VERSION_CODE) {
return Float.parseFloat(game.getGameScore(SCORE_ROUND_COUNT, "0"));
} else {
int wrongTime = Integer.parseInt(game.getGameScore(NightWatchGame.SCORE_WRONG_TIME, Integer.toString(LEVELS_COUNT)));
int wrongWindows = Integer.parseInt(game.getGameScore(NightWatchGame.SCORE_WRONG_WINDOWS, Integer.toString(LEVELS_COUNT)));
return 2 * LEVELS_COUNT - wrongTime - wrongWindows;
}
}
@Override
public float getStatisticsScore(Game game) {
return correctOldScore(game);
}
/**
* Correcting old score.
* Max score in old version is 16.
* New max score is 12, but possible minimum is now 2.
*
* @param game Nightwatch game
* @return Corrected score, if old version. Otherwise former score.
*/
public float correctOldScore(Game game) {
if(game.getApplicationVersionCode() == Game.DEFAULT_APPLICATION_VERSION_CODE) {
return (int) (getGameScoreResult(game) / MAX_OLD_SCORE * (MAX_NEW_SCORE - MIN_NEW_SCORE)) + MIN_NEW_SCORE;
}
return getGameScoreResult(game);
}
@Override
public List<GameScore> getGameScoreList(GameDifficulty difficulty, GameResult result) {
int roundsCount;
switch (result) {
case NO_STAR: