Commit 128e677e authored by Matyáš Latner's avatar Matyáš Latner

#45 Added TUTORIAL to game difficulty definitions

parent b680b154
......@@ -20,6 +20,7 @@ mainmenu_panorama=Panorama
usermenu_newuser=+ Nový detektiv
gamedifficulty_tutorial=Cvičení
gamedifficulty_easy=Lehká
gamedifficulty_medium=Střední
gamedifficulty_hard=Těžká
......
......@@ -20,6 +20,7 @@ mainmenu_panorama=Panorama
usermenu_newuser=+ Neuer Detektiv
gamedifficulty_tutorial=Lernprogramm
gamedifficulty_easy=Leicht
gamedifficulty_medium=Mittel
gamedifficulty_hard=Schwierig
......
......@@ -20,6 +20,7 @@ mainmenu_panorama=Panorama
usermenu_newuser=+ Nový detektív
gamedifficulty_tutorial=Cvičenie
gamedifficulty_easy=Ľahká
gamedifficulty_medium=Stredná
gamedifficulty_hard=Ťažká
......
......@@ -227,8 +227,8 @@ public abstract class AbstractTablexiaGame<T> extends AbstractTablexiaScreen<T>
if (game == null) {
// create new
TablexiaRandom random = new TablexiaRandom();
GameDifficulty gameDifficulty = TablexiaSettings.getInstance().getGameDifficulty(GameDefinition.getGameDefinitionForClass((Class<? extends AbstractTablexiaGame<?>>) getClass()));
GameDefinition gameDefinition = GameDefinition.getGameDefinitionForClass(AbstractTablexiaGame.this.getClass());
GameDifficulty gameDifficulty = gameDefinition.hasTutorial() && getSelectedUser().isTutorialForGameDefinition(gameDefinition) ? GameDifficulty.TUTORIAL : TablexiaSettings.getInstance().getGameDifficulty(gameDefinition);
game = Game.createGame(getSelectedUser(), gameDifficulty, gameDefinition, random);
Log.info(getClass(), "[DB] Created new GAME object: " + game);
} else {
......
......@@ -19,7 +19,7 @@ import cz.nic.tablexia.menu.IMenuItem;
public enum GameDefinition implements ApplicationEvent, IMenuItem {
ROBBERY(1, "game_robbery_title", RobberyGame.class, new GameResultResolver() {
ROBBERY(1, "game_robbery_title", RobberyGame.class, false, new GameResultResolver() {
@Override
public AbstractTablexiaGame.GameResult getGameResult(Map<String, String> gameScore) {
int creaturesCount = Integer.valueOf(gameScore.get(RobberyGame.SCORE_KEY_PERSON_NUMBER)) + 1;
......@@ -34,31 +34,31 @@ public enum GameDefinition implements ApplicationEvent, IMenuItem {
}
}
}),
PURSUIT(2, "game_pursuit_title", PursuitGame.class, new GameResultResolver() {
PURSUIT(2, "game_pursuit_title", PursuitGame.class, false, new GameResultResolver() {
@Override
public AbstractTablexiaGame.GameResult getGameResult(Map<String, String> gameScore) {
return AbstractTablexiaGame.GameResult.NO_STAR;
}
}),
KIDNAPPING(3, "game_kidnapping_title", KidnappingGame.class, new GameResultResolver() {
KIDNAPPING(3, "game_kidnapping_title", KidnappingGame.class, false, new GameResultResolver() {
@Override
public AbstractTablexiaGame.GameResult getGameResult(Map<String, String> gameScore) {
return AbstractTablexiaGame.GameResult.NO_STAR;
}
}),
NIGHT_WATCH(4, "game_night_watch_title", NightWatchGame.class, new GameResultResolver() {
NIGHT_WATCH(4, "game_night_watch_title", NightWatchGame.class, false, new GameResultResolver() {
@Override
public AbstractTablexiaGame.GameResult getGameResult(Map<String, String> gameScore) {
return AbstractTablexiaGame.GameResult.NO_STAR;
}
}),
SHOOTING_RANGE(5, "game_shooting_range_title", ShootingRangeGame.class, new GameResultResolver() {
SHOOTING_RANGE(5, "game_shooting_range_title", ShootingRangeGame.class, false, new GameResultResolver() {
@Override
public AbstractTablexiaGame.GameResult getGameResult(Map<String, String> gameScore) {
return AbstractTablexiaGame.GameResult.NO_STAR;
}
}),
IN_THE_DARKNESS(6, "game_in_the_darkness_title", InTheDarknessGame.class, new GameResultResolver() {
IN_THE_DARKNESS(6, "game_in_the_darkness_title", InTheDarknessGame.class, true, new GameResultResolver() {
@Override
public AbstractTablexiaGame.GameResult getGameResult(Map<String, String> gameScore) {
Integer errorsCount = Integer.valueOf(gameScore.get(InTheDarknessGame.SCORE_KEY_ERRORS_COUNT));
......@@ -82,16 +82,18 @@ public enum GameDefinition implements ApplicationEvent, IMenuItem {
private int gameNumber;
private String menuTextKey;
private Class<? extends AbstractTablexiaGame<?>> screenClass;
private boolean hasTutorial;
private GameResultResolver gameResultResolver;
public static GameDefinition[] getActiveGames(){
return new GameDefinition[]{ROBBERY, PURSUIT, KIDNAPPING, NIGHT_WATCH, SHOOTING_RANGE, IN_THE_DARKNESS};
}
GameDefinition(int gameNumber, String nameResource, Class<? extends AbstractTablexiaGame<?>> screenClass, GameResultResolver gameResultResolver) {
GameDefinition(int gameNumber, String nameResource, Class<? extends AbstractTablexiaGame<?>> screenClass, boolean hasTutorial, GameResultResolver gameResultResolver) {
this.gameNumber = gameNumber;
this.menuTextKey = nameResource;
this.screenClass = screenClass;
this.hasTutorial = hasTutorial;
this.gameResultResolver = gameResultResolver;
}
......@@ -104,6 +106,10 @@ public enum GameDefinition implements ApplicationEvent, IMenuItem {
return ApplicationTextManager.getInstance().getResult().get(menuTextKey);
}
public boolean hasTutorial() {
return hasTutorial;
}
@Override
public void performAction() {
ApplicationBus.getInstance().publishAsync(this);
......
......@@ -19,6 +19,9 @@
package cz.nic.tablexia.game.difficulty;
import java.util.ArrayList;
import java.util.List;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
/**
......@@ -28,18 +31,21 @@ import cz.nic.tablexia.loader.application.ApplicationTextManager;
*/
public enum GameDifficulty {
EASY (1, "gamedifficulty_easy"),
MEDIUM (2, "gamedifficulty_medium"),
HARD (3, "gamedifficulty_hard");
TUTORIAL(0, "gamedifficulty_tutorial", false),
EASY (1, "gamedifficulty_easy", true),
MEDIUM (2, "gamedifficulty_medium", true),
HARD (3, "gamedifficulty_hard", true);
public static final GameDifficulty DEFAULT_DIFFICULTY = EASY;
private int difficultyNumber;
private String descriptionResourceKey;
private boolean visible;
GameDifficulty(int difficultyNumber, String descriptionResourceKey) {
GameDifficulty(int difficultyNumber, String descriptionResourceKey, boolean visible) {
this.difficultyNumber = difficultyNumber;
this.descriptionResourceKey = descriptionResourceKey;
this.visible = visible;
}
public int getDifficultyNumber() {
......@@ -50,6 +56,20 @@ public enum GameDifficulty {
return ApplicationTextManager.getInstance().getText(getDescriptionResourceKey());
}
public boolean isVisible() {
return visible;
}
public static List<GameDifficulty> getVisibleGameDifficultyList() {
List<GameDifficulty> gameDifficultyList = new ArrayList<GameDifficulty>();
for (GameDifficulty gameDifficulty: GameDifficulty.values()) {
if (gameDifficulty.isVisible()) {
gameDifficultyList.add(gameDifficulty);
}
}
return gameDifficultyList;
}
/**
* Returns key of description for current difficulty
*
......
......@@ -19,10 +19,10 @@ import cz.nic.tablexia.util.Log;
*/
public enum InTheDarknessDifficulty {
TUTORIAL(null, false, MapTutorial.class, 1, Arrays.asList(new ActionType[]{})),
EASY (GameDifficulty.EASY, true, MapGenerator.class, 1, Arrays.asList(new ActionType[]{})),
MEDIUM (GameDifficulty.MEDIUM, true, MapGenerator.class, 1, Arrays.asList(new ActionType[]{ActionType.KEY})),
HARD (GameDifficulty.HARD, true, MapGenerator.class, 2, Arrays.asList(new ActionType[]{ActionType.KEY}));
TUTORIAL(GameDifficulty.TUTORIAL, false, MapTutorial.class, 1, Arrays.asList(new ActionType[]{})),
EASY (GameDifficulty.EASY, true, MapGenerator.class, 1, Arrays.asList(new ActionType[]{})),
MEDIUM (GameDifficulty.MEDIUM, true, MapGenerator.class, 1, Arrays.asList(new ActionType[]{ActionType.KEY})),
HARD (GameDifficulty.HARD, true, MapGenerator.class, 2, Arrays.asList(new ActionType[]{ActionType.KEY}));
private GameDifficulty gameDifficulty;
private int floorCount;
......@@ -50,10 +50,7 @@ public enum InTheDarknessDifficulty {
return difficultyActionTypes.contains(actionType);
}
public static InTheDarknessDifficulty getInTheDarknessDifficultyForGameDifficulty(GameDifficulty gameDifficulty, boolean isFirstGame) {
if (isFirstGame) {
return TUTORIAL;
}
public static InTheDarknessDifficulty getInTheDarknessDifficultyForGameDifficulty(GameDifficulty gameDifficulty) {
for (InTheDarknessDifficulty inTheDarknessDifficulty : InTheDarknessDifficulty.values()) {
if (inTheDarknessDifficulty.gameDifficulty == gameDifficulty) {
return inTheDarknessDifficulty;
......
......@@ -213,14 +213,15 @@ public class InTheDarknessGame extends AbstractTablexiaGame<Void> implements Map
mapWidgets = new ArrayList<MapWidget>();
actualMapWidgetNumber = 0;
planningStartTime = 0;
inTheDarknessDifficulty = null;
// screen components
prepareBackground();
showMapWidgets(getPotmeDifficulty(), getRandom());
showMapWidgets(getInTheDarknessDifficulty(), getRandom());
startButton = showStartButton();
actionsStripWidget = showActionsStripWidget();
actionsStripWidget.setStartButton(startButton);
actionsWidget = showActionsWidget(actionsStripWidget, getPotmeDifficulty());
actionsWidget = showActionsWidget(actionsStripWidget, getInTheDarknessDifficulty());
player = showPlayer();
......@@ -288,12 +289,9 @@ public class InTheDarknessGame extends AbstractTablexiaGame<Void> implements Map
//////////////////////////////////////////// IN THE DARKNESS DIFFICULTY
public InTheDarknessDifficulty getPotmeDifficulty() {
public InTheDarknessDifficulty getInTheDarknessDifficulty() {
if (inTheDarknessDifficulty == null) {
User selectedUser = getSelectedUser();
// TODO check for first play
// boolean firstPlay = currentFirstPlay && (selectedUser != null && !selectedUser.wasGameTutorialPlayed(getGameDefinition()));
inTheDarknessDifficulty = InTheDarknessDifficulty.getInTheDarknessDifficultyForGameDifficulty(getGameDifficulty(), false);
inTheDarknessDifficulty = InTheDarknessDifficulty.getInTheDarknessDifficultyForGameDifficulty(getGameDifficulty());
}
return inTheDarknessDifficulty;
}
......@@ -313,7 +311,7 @@ public class InTheDarknessGame extends AbstractTablexiaGame<Void> implements Map
}
MapObject mapObject = tileMap.getTileAtPosition(player.getActualTileMapPosition()).getMapObject();
if ((mapObject != null) &&
(!getPotmeDifficulty().hasDifficultyActionType(ActionType.KEY) || player.hasKey()) &&
(!getInTheDarknessDifficulty().hasDifficultyActionType(ActionType.KEY) || player.hasKey()) &&
(mapObject.getMapObjectType() == MapObjectType.SAFE) &&
(selectedActionPosition == selectedActions.size() - 1)) {
getSound(InTheDarknessAssets.SOUND_SAVE).play();
......@@ -476,8 +474,8 @@ public class InTheDarknessGame extends AbstractTablexiaGame<Void> implements Map
// GameLayer.BACKGROUND_TEXTURE_LAYER.getLayerEntity().attachChild(actionStripBackground);
ActionsStripWidget actionStripWidget = new ActionsStripWidget(ACTION_STRIP_WIDGET_WIDTH, contentGroup.getHeight(), this);
actionStripWidget.setPosition(getStage().getWidth() - actionStripWidget.getWidth(), -SCREEN_Y_CORRECTION_OFFSET);
// actionStripWidget.enableActionSorting(getPotmeDifficulty() != PotmeDifficulty.TUTORIAL);
// actionStripWidget.enableStartButtonControl(getPotmeDifficulty() != PotmeDifficulty.TUTORIAL);
// actionStripWidget.enableActionSorting(getInTheDarknessDifficulty() != PotmeDifficulty.TUTORIAL);
// actionStripWidget.enableStartButtonControl(getInTheDarknessDifficulty() != PotmeDifficulty.TUTORIAL);
GameLayer.ACTION_STRIP_LAYER.getLayerEntity().addActor(actionStripWidget);
return actionStripWidget;
}
......
package cz.nic.tablexia.game.games.in_the_darkness.map;
import java.util.Random;
import cz.nic.tablexia.game.games.in_the_darkness.InTheDarknessGame;
import cz.nic.tablexia.game.games.in_the_darkness.map.TileMap.TileMapPosition;
import cz.nic.tablexia.game.games.in_the_darkness.map.mapobject.MapObjectType;
......@@ -10,6 +12,8 @@ import cz.nic.tablexia.game.games.in_the_darkness.map.tile.TileType;
public class MapTutorial implements IMapProvider {
public MapTutorial(Random randomAccess) {}
@Override
public TileMap prepareMap(Tile lastFinishTile, int mapXSize, int mapYSize, MapObjectType finishMapObject, boolean hasKey) {
TileMap tileMap = new TileMap(mapXSize, mapYSize);
......
......@@ -9,7 +9,10 @@ import java.util.List;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.TablexiaStorage;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.menu.user.UserMenu;
import cz.nic.tablexia.model.game.Game;
import cz.nic.tablexia.util.Log;
/**
......@@ -214,6 +217,10 @@ public class User extends UserMenu.UserMenuItem {
return selectedUser;
}
public boolean isTutorialForGameDefinition(GameDefinition gameDefinition) {
return Game.getNumberOfCompleteGamesForGameDefinitionAndDifficulty(gameDefinition, GameDifficulty.TUTORIAL, this) < 1;
}
//////////////////////////// EVENT
......
......@@ -159,6 +159,10 @@ public class Game {
return getGameDefinition().getGameResult(gameScoreMap);
}
public static Integer getNumberOfCompleteGamesForGameDefinitionAndDifficulty(GameDefinition gameDefinition, GameDifficulty gameDifficulty, User user) {
return selectCompleteGameCountForGameNumberAndDifficultyNumber(gameDefinition.getGameNumber(), gameDifficulty.getDifficultyNumber(), user.getId());
}
//////////////////////////// DB ACCESS
......@@ -168,6 +172,7 @@ public class Game {
public static final String GAME_UPDATE_END = "UPDATE game SET end_time = ? WHERE id = ?";
public static final String GAME_SELECT_FOR_ID = "SELECT id, user_id, difficulty_number, game_number, random_seed, start_time, end_time FROM game WHERE id = ?";
public static final String GAME_SELECT_LAST_ID = "SELECT max(id) FROM game";
public static final String GAME_SELECT_COUNT_FOR_GAME_AND_DIFFICULTY = "SELECT count(id) FROM game WHERE game_number = ? AND difficulty_number = ? AND user_id = ? AND end_time IS NOT NULL";
private static Long insertNewGame(User user, GameDifficulty difficulty, GameDefinition gameDefinition, TablexiaRandom random) {
try {
......@@ -235,6 +240,29 @@ public class Game {
return id;
}
private static int selectCompleteGameCountForGameNumberAndDifficultyNumber(int gameNumber, int difficultyNumber, long userId) {
Integer count = null;
try {
PreparedStatement statement = TablexiaStorage.getInstance().prepareStatement(GAME_SELECT_COUNT_FOR_GAME_AND_DIFFICULTY);
try {
statement.setInt(1, gameNumber);
statement.setInt(2, difficultyNumber);
statement.setLong(3, userId);
ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
count = resultSet.getInt(1);
}
resultSet.close();
} catch (SQLException e) {
Log.err(User.class, "Cannot select games count for game definition number: " + gameNumber + " and difficulty number: " + difficultyNumber, e);
}
statement.close();
} catch (SQLException e) {
Log.err(User.class, "Cannot select games count for game definition number: " + gameNumber + " and difficulty number: " + difficultyNumber, e);
}
return count;
}
private static Long gameUpdateStart(long id, long startTime) {
try {
PreparedStatement updateStatement = TablexiaStorage.getInstance().prepareStatement(GAME_UPDATE_START);
......
......@@ -73,7 +73,7 @@ public class StatisticsScreen extends AbstractTablexiaScreen<Void> {
content.addActor(switchGraphType);
difficulties = new HorizontalGroup().space(10f);
for (GameDifficulty gameDifficulty : GameDifficulty.values()) {
for (GameDifficulty gameDifficulty : GameDifficulty.getVisibleGameDifficultyList()) {
String diffString = gameDifficulty.name().toLowerCase();
Button diffButton = new Button(new TextureRegionDrawable(getScreenTextureRegion(GFX_PATH + "difficultyradio_" + diffString + "_unpressed")), new TextureRegionDrawable(getScreenTextureRegion(GFX_PATH + "difficultyradio_" + diffString + "_pressed")), new TextureRegionDrawable(getScreenTextureRegion(GFX_PATH + "difficultyradio_" + diffString + "_pressed")));
Label diffLabel = setSmallFont(new Label(ApplicationTextManager.getInstance().getText("gamedifficulty_" + diffString), new Label.LabelStyle(getDefaultRegularFont(), Color.BLACK)));
......
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