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 {
public static final String LOCALE_KEY = "locale";
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>
private static final int WINTER_MODE_START_MONTH = 10;
private static final int WINTER_MODE_END_MONTH = 2;
......@@ -429,28 +424,28 @@ public class TablexiaSettings {
}
public enum LocaleDefinition {
SYSTEM (null, "system", 0, ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_SYSTEM, true),
cs_CZ (new Locale("cs", "CZ"), "cs_CZ", 1, ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_CZECH, true),
sk_SK (new Locale("sk", "SK"), "sk_SK", 2, ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_SLOVAK, true),
de_DE (new Locale("de", "DE"), "de_DE", 3, ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_GERMAN, true);
SYSTEM (null, null, "system", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_SYSTEM, 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 (cz.nic.tablexia.shared.model.definitions.LocaleDefinition.sk_SK, new Locale("sk", "SK"), "sk_SK", ApplicationTextManager.ApplicationTextsAssets.LANGUAGE_SLOVAK, 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;
private final static LocaleDefinition FALLBACK_VARIANT = LocaleDefinition.SYSTEM;
private final Locale locale;
private final String localeKey;
private final int localeNumber;
private final String descriptionKey;
private boolean enabled;
private final cz.nic.tablexia.shared.model.definitions.LocaleDefinition modelLocaleDefinition;
private final Locale locale;
private final String localeKey;
private final String descriptionKey;
private final boolean enabled;
private static List<LocaleDefinition> enabledLocaleDefinitions;
LocaleDefinition(Locale locale, String localeKey, int localeNumber, String descriptionKey, boolean enabled) {
this.locale = locale;
this.localeKey = localeKey;
this.localeNumber = localeNumber;
this.descriptionKey = descriptionKey;
this.enabled = enabled;
LocaleDefinition(cz.nic.tablexia.shared.model.definitions.LocaleDefinition modelLocaleDefinition, Locale locale, String localeKey, String descriptionKey, boolean enabled) {
this.modelLocaleDefinition = modelLocaleDefinition;
this.locale = locale;
this.localeKey = localeKey;
this.descriptionKey = descriptionKey;
this.enabled = enabled;
}
public String getLocaleKey() {
......@@ -458,7 +453,7 @@ public class TablexiaSettings {
}
public int getLocaleNumber() {
return localeNumber;
return getLocaleDefinitionForLocale(getLocale()).modelLocaleDefinition.number();
}
public String getDescriptionKey() {
......
......@@ -79,6 +79,8 @@ import cz.nic.tablexia.screen.halloffame.trophy.TrophyHelper;
import cz.nic.tablexia.screen.profile.ProfileScreen;
import cz.nic.tablexia.shared.model.Game;
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.MusicUtil;
import cz.nic.tablexia.util.actions.MoveAlongAction;
......@@ -127,30 +129,43 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
public enum GameResult {
NO_STAR(0, null),
ONE_STAR(1, RATINGSTAR1_SOUND),
TWO_STAR(2, RATINGSTAR2_SOUND),
THREE_STAR(3, RATINGSTAR3_SOUND);
NO_STAR (GameResultDefinition.NO_STAR, null),
ONE_STAR (GameResultDefinition.ONE_STAR, RATINGSTAR1_SOUND),
TWO_STAR (GameResultDefinition.TWO_STAR, RATINGSTAR2_SOUND),
THREE_STAR (GameResultDefinition.THREE_STAR, RATINGSTAR3_SOUND);
private int starCount;
private GameResultDefinition gameResultDefinition;
private String startSoundName;
GameResult(int starCount, String startSoundName) {
this.starCount = starCount;
GameResult(GameResultDefinition gameResultDefinition, String startSoundName) {
this.gameResultDefinition = gameResultDefinition;
this.startSoundName = startSoundName;
}
public int getStarCount() {
return starCount;
return gameResultDefinition.number();
}
public String getStartSoundName() {
return startSoundName;
}
public GameResultDefinition getGameResultDefinition() {
return gameResultDefinition;
}
public static GameResult getGameResultForStartCount(int starCount) {
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;
}
}
......@@ -514,7 +529,7 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
@Override
public void clicked(InputEvent event, float x, float y) {
if(getGamePhase() == GamePhase.STARTED) {
forceGameEnd(GameResult.THREE_STAR);
forceGameEnd(GameResultDefinition.THREE_STAR);
debugEndGameButton.setDisabled();
}
}
......@@ -1369,15 +1384,15 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
ApplicationBus.getInstance().publishAsync(new StartIncrementalSynchronizationEvent(getSelectedUser().getId()));
}
private void forceGameEnd(GameResult gameResult) {
List<GameScore> gameScores = GameDefinition.getGameDefinitionForClass(getClass()).getGameResultResolver().getGameScoreList(getGameDifficulty(), gameResult);
private void forceGameEnd(GameResultDefinition gameResult) {
List<GameScore> gameScores = GameDefinition.getGameDefinitionForClass(getClass()).getGameResultResolver().getExampleScoreForGameResult(getGameDifficulty().getDifficultyDefinition(), gameResult);
setGameScores(gameScores);
waitForActualGameScore();
onForceGameEnd(gameResult);
}
protected void onForceGameEnd(GameResult gameResult) {
protected void onForceGameEnd(GameResultDefinition gameResult) {
endGame();
showGameResultDialog();
}
......
......@@ -23,6 +23,7 @@ import java.util.List;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.shared.model.definitions.DifficultyDefinition;
/**
* Game difficulty types
......@@ -31,29 +32,31 @@ import cz.nic.tablexia.shared.model.Game;
*/
public enum GameDifficulty {
TUTORIAL(0, TablexiaSettings.EXPERIENCE_POINTS_TUTORIAL, "gamedifficulty_tutorial", false, false),
EASY (1, TablexiaSettings.EXPERIENCE_POINTS_EASY, "gamedifficulty_easy", true, true),
MEDIUM (2, TablexiaSettings.EXPERIENCE_POINTS_MEDIUM, "gamedifficulty_medium", true, true),
HARD (3, TablexiaSettings.EXPERIENCE_POINTS_HARD, "gamedifficulty_hard", true, true);
TUTORIAL(DifficultyDefinition.TUTORIAL, "gamedifficulty_tutorial", false, false),
EASY (DifficultyDefinition.EASY, "gamedifficulty_easy", true, true),
MEDIUM (DifficultyDefinition.MEDIUM, "gamedifficulty_medium", 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 int experiencePointsMultiplier;
private String descriptionResourceKey;
private boolean visible;
private boolean hasScore;
private final DifficultyDefinition difficultyDefinition;
private final String descriptionResourceKey;
private final boolean visible;
private final boolean hasScore;
GameDifficulty(int difficultyNumber, int experiencePointsMultiplier, String descriptionResourceKey, boolean visible, boolean hasScore) {
this.difficultyNumber = difficultyNumber;
this.experiencePointsMultiplier = experiencePointsMultiplier;
GameDifficulty(DifficultyDefinition difficultyDefinition, String descriptionResourceKey, boolean visible, boolean hasScore) {
this.difficultyDefinition = difficultyDefinition;
this.descriptionResourceKey = descriptionResourceKey;
this.visible = visible;
this.hasScore = hasScore;
}
public DifficultyDefinition getDifficultyDefinition() {
return difficultyDefinition;
}
public int getDifficultyNumber() {
return difficultyNumber;
return difficultyDefinition.number();
}
public String getTextDescription() {
......@@ -85,7 +88,7 @@ public enum GameDifficulty {
public static GameDifficulty getGameDifficultyForDifficultyNumber(int difficultyNumber) {
for (GameDifficulty gameDifficulty: GameDifficulty.values()) {
if (gameDifficulty.difficultyNumber == difficultyNumber) {
if (gameDifficulty.difficultyDefinition.number() == difficultyNumber) {
return gameDifficulty;
}
}
......@@ -97,7 +100,7 @@ public enum GameDifficulty {
}
public int getExperiencePointsMultiplier() {
return experiencePointsMultiplier;
return difficultyDefinition.getExperiencePointsMultiplier();
}
public boolean hasScore() {
......
......@@ -40,7 +40,6 @@ import java.util.TimerTask;
import cz.nic.tablexia.TablexiaApplication;
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.crime_scene.actors.PlaySoundScreen;
import cz.nic.tablexia.game.games.crime_scene.assets.CrimeSceneAssets;
......@@ -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.loader.application.ApplicationAtlasManager;
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.ui.AnimatedImage;
import cz.nic.tablexia.util.ui.actionwidget.Action;
......@@ -82,8 +81,9 @@ public class CrimeSceneGame extends AbstractTablexiaGame<CrimeSceneGameState> {
private static final int GAME_MAP_PADDING = 25;
private static final int GAME_MAP_SIZE = 625;
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 FADE_DURATION = 1f;
......@@ -123,39 +123,6 @@ public class CrimeSceneGame extends AbstractTablexiaGame<CrimeSceneGameState> {
private int level = 1;
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
protected void gameLoaded(java.util.Map gameState) {
setUpActionsStripWidget();
......
......@@ -38,9 +38,8 @@ import java.util.Map;
import cz.nic.tablexia.TablexiaApplication;
import cz.nic.tablexia.TablexiaSettings;
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.shared.model.resolvers.InTheDarknessScoreResolver;
import cz.nic.tablexia.util.ui.actionwidget.Action;
import cz.nic.tablexia.util.ui.actionwidget.ActionContainer;
import cz.nic.tablexia.util.ui.actionwidget.ActionsStripWidget;
......@@ -56,7 +55,6 @@ import cz.nic.tablexia.loader.application.ApplicationInternalTextureManager;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.model.game.GameDAO;
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.ScaleUtil;
import cz.nic.tablexia.util.ui.AnimatedImage;
......@@ -82,48 +80,6 @@ import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence;
* Created by Matyáš Latner on 7.9.15.
*/
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 {
BACKGROUND_TEXTURE_LAYER (0, Touchable.disabled),
......@@ -183,8 +139,8 @@ public class InTheDarknessGame extends AbstractTablexiaGame<List<MapWidget>> imp
}
}
private static final String SCORE_KEY_PLANNING_DURATION = "planning_duration";
public static final String SCORE_KEY_ERRORS_COUNT = "errors_count";
private static final String SCORE_KEY_PLANNING_DURATION = InTheDarknessScoreResolver.SCORE_KEY_PLANNING_DURATION;
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 float FADE_DURATION = 0.4f;
......
......@@ -27,6 +27,7 @@ import java.util.Random;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.kidnapping.generator.PathGenerator;
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.game.games.kidnapping.generator.TileMapGenerator;
import cz.nic.tablexia.game.games.kidnapping.media.DirectionSounds;
......@@ -39,9 +40,9 @@ import cz.nic.tablexia.shared.model.Game;
* Created by lhoracek on 5/15/15.
*/
public class GameState {
public static final String GAME_MISSES = "GAME_MISSES";
public static final String GAME_REPLAYS = "GAME_REPLAYS";
public static final String GAME_STEP = "GAME_STEP";
public static final String GAME_MISSES = KidnappingScoreResolver.GAME_MISSES;
public static final String GAME_REPLAYS = KidnappingScoreResolver.GAME_REPLAYS;
public static final String GAME_STEP = KidnappingScoreResolver.GAME_STEP;
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;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.shared.model.Game;
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.Utility;
import cz.nic.tablexia.util.ui.AnimatedImage;
......@@ -68,77 +69,6 @@ import cz.nic.tablexia.util.ui.dialog.components.TwoColumnContentDialogComponent
* Created by Václav Tarantík on 6.3.15.
*/
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:
roundsCount = GameRulesHelper.ONE_STAR - 1;
break;
case ONE_STAR:
roundsCount = GameRulesHelper.TWO_STARS - 1;
break;
case TWO_STAR:
roundsCount = GameRulesHelper.THREE_STARS - 1;
break;
default:
roundsCount = GameRulesHelper.THREE_STARS;
break;
}
List<GameScore> gameScores = new ArrayList<>(1);
gameScores.add(new GameScore(SCORE_ROUND_COUNT, Integer.toString(roundsCount)));
return gameScores;
}
}
private enum ResultMapping {
NO_STAR_TEXT (GameResult.NO_STAR, NightWatchAssets.VICTORYTEXT_NOSTAR, NightWatchAssets.VICTORYSPEECH_NOSTAR),
......@@ -173,11 +103,10 @@ public class NightWatchGame extends AbstractTablexiaGame<int[][]> {
return null;
}
}
private static final int LEVELS_COUNT = 8;//max correct windows and time
private static final int SCREEN_WIDTH = TablexiaSettings.getWorldSize();
private static final int SCREEN_MIN_HEIGHT = TablexiaSettings.getMinWorldHeight();
private static final int INITIAL_BG_TEXTURE_INDEX = 0;
private static final int MAX_GAME_ERRORS = 2;
private static final int SCREEN_WIDTH = TablexiaSettings.getWorldSize();
private static final int SCREEN_MIN_HEIGHT = TablexiaSettings.getMinWorldHeight();
private static final int INITIAL_BG_TEXTURE_INDEX = 0;
private static final int MAX_GAME_ERRORS = 2;
private static final float SOLUTION_VISIBLE_SECONDS = 2.0f;
private static final float SOLUTION_DELAY = 0.5f;
private static final float TRANSITION_DELAY = 2;
......@@ -185,10 +114,8 @@ public class NightWatchGame extends AbstractTablexiaGame<int[][]> {
private static final float TRANSITION_ANIMATION_FADE_IN = 0.2f;
private static final float WINDOW_IMAGE_RESIZE = 1.03f;
private static final String SUMMARY_TEXT_ROUNDS_KEY = "victory_text_rounds";
private static final String SCORE_ROUND_COUNT = "round_count";
private static final String SCORE_WRONG_WINDOWS = "windows_count";
private static final String SCORE_WRONG_TIME = "time_count";
private static final String SUMMARY_TEXT_ROUNDS_KEY = "victory_text_rounds";
private static final String SCORE_ROUND_COUNT = NightWatchScoreResolver.SCORE_ROUND_COUNT;
private static final int WATCH_WIDTH = 300;
private static final int BUTTON_X = 800;
......@@ -223,7 +150,7 @@ public class NightWatchGame extends AbstractTablexiaGame<int[][]> {
getStage().addActor(contentGroup);
gameSolution = GameSolutionGenerator.generateSolutions(getGameDifficulty(), getRandom());
selectedWindows = new HashSet<Integer>();
selectedWindows = new HashSet<>();
prepareBackground();
prepareWindows();
......
......@@ -19,6 +19,7 @@ package cz.nic.tablexia.game.games.night_watch.helper;
import cz.nic.tablexia.game.AbstractTablexiaGame;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.shared.model.resolvers.NightWatchScoreResolver;
/**
* Created by Vendik on 30.4.2015.
......@@ -30,17 +31,17 @@ public class GameRulesHelper {
private static final float END_LID_TIME = 0.7f;
public static final int NUMBER_OF_ROUNDS = 12;
public static final int ONE_STAR = 4;
public static final int TWO_STARS = 8;
public static final int THREE_STARS = 12;
public static final int OLD_VERSION_ONE_STAR = 4;
public static final int OLD_VERSION_TWO_STARS = 8;
public static final int OLD_VERSION_THREE_STARS = 13;
public static final int ONE_STAR = NightWatchScoreResolver.ONE_STAR;
public static final int TWO_STARS = NightWatchScoreResolver.TWO_STARS;
public static final int THREE_STARS = NightWatchScoreResolver.THREE_STARS;
public static final int OLD_VERSION_ONE_STAR = NightWatchScoreResolver.OLD_VERSION_ONE_STAR;
public static final int OLD_VERSION_TWO_STARS = NightWatchScoreResolver.OLD_VERSION_TWO_STARS;
public static final int OLD_VERSION_THREE_STARS = NightWatchScoreResolver.THREE_STARS;
private static int[] easyLevelWindows = new int[] {1,1,1,2,2,3,3,4,4,4,5,5};
private static int[] mediumLevelWindows = new int[] {1,2,2,3,3,4,4,5,5,5,6,6};
private static int[] hardLevelWindows = new int[] {1,2,3,3,4,4,5,5,6,6,6,7};
private static int[] easyLevelWindows = new int[] {1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5};
private static int[] mediumLevelWindows = new int[] {1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6};
private static int[] hardLevelWindows = new int[] {1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7};
public static int getNumberOfWindowsLightenedInCurrentRound(GameDifficulty gameDifficulty, int round) {
switch (gameDifficulty) {
......
......@@ -66,6 +66,8 @@ import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.model.game.GameDAO;
import cz.nic.tablexia.shared.model.Game;
import cz.nic.tablexia.shared.model.GameScore;
import cz.nic.tablexia.shared.model.definitions.GameResultDefinition;
import cz.nic.tablexia.shared.model.resolvers.PursuitScoreResolver;
import cz.nic.tablexia.util.Log;
import cz.nic.tablexia.util.Point;
import cz.nic.tablexia.util.ScaleUtil;
......@@ -81,41 +83,6 @@ import cz.nic.tablexia.util.ui.dialog.components.TwoColumnContentDialogComponent
* Created by Václav Tarantík on 6.3.15.
*/
public class PursuitGame extends AbstractTablexiaGame<Void> {
public static class GameResultResolver extends GameDefinition.GameResultResolver {
@Override
public GameResult getGameCupsResult(Game game) {
return GameRulesHelper.getNumberOfStarsForTime(GameDifficulty.getGameDifficultyForDifficultyNumber(game.getGameDifficulty()), GameDAO.getGameDuration(game, false));
}
@Override
public float getGameScoreResult(Game game) {
return GameDAO.getGameDuration(game);
}