Commit 0723a198 authored by Matyáš Latner's avatar Matyáš Latner

#83 Zobrazení mapy pro tutorial při prvním spuštění hry

parent 46a007c9
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<string name="game_potme_loading_text_2">Přetahuj správné úkony do pásu vpravo a dávej pozor na všechny překážky. Teprve až budeš mít naplánovanou celou trasu, stiskni tlačítko HOTOVO.</string> <string name="game_potme_loading_text_2">Přetahuj správné úkony do pásu vpravo a dávej pozor na všechny překážky. Teprve až budeš mít naplánovanou celou trasu, stiskni tlačítko HOTOVO.</string>
<string name="game_potme_start">HOTOVO</string> <string name="game_potme_start">HOTOVO</string>
<string name="game_potme_floor">Patro</string> <string name="game_potme_floor">Patro</string>
<string name="game_potme_victory_tutorial">Gratuluji! A teď to zkus sám&#8230;</string>
<string name="game_potme_victory_0">Au au, tolik chyb! To muselo bolet.</string> <string name="game_potme_victory_0">Au au, tolik chyb! To muselo bolet.</string>
<string name="game_potme_victory_1">Krůček za krůčkem. To chce klid, soustředit se a úspěchy se brzy dostaví.</string> <string name="game_potme_victory_1">Krůček za krůčkem. To chce klid, soustředit se a úspěchy se brzy dostaví.</string>
<string name="game_potme_victory_2">Chybička se vždycky vloudí, ale dobrému detektivovi by se to stávat nemělo.</string> <string name="game_potme_victory_2">Chybička se vždycky vloudí, ale dobrému detektivovi by se to stávat nemělo.</string>
......
...@@ -116,6 +116,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -116,6 +116,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
protected boolean afterResume = false; protected boolean afterResume = false;
protected boolean paused = false; protected boolean paused = false;
private boolean playVictorySpeech = false; private boolean playVictorySpeech = false;
private boolean useGameManager = true;
private static final int STEPS_PER_SECOUND = 60; private static final int STEPS_PER_SECOUND = 60;
protected static final int VICTORY_SCREEN_STARS_COUNT = 3; protected static final int VICTORY_SCREEN_STARS_COUNT = 3;
...@@ -169,6 +170,10 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -169,6 +170,10 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
public boolean isGameActive(GamesDefinition gameDefinitionToCheck) { public boolean isGameActive(GamesDefinition gameDefinitionToCheck) {
return (gamesDefinition == gameDefinitionToCheck) && (gameState == GameState.STARTED); return (gamesDefinition == gameDefinitionToCheck) && (gameState == GameState.STARTED);
} }
protected void disableGameManagerForCurrentGame() {
useGameManager = false;
}
/* //////////////////////////////////////////// TABLEXIA LIFECYCLE */ /* //////////////////////////////////////////// TABLEXIA LIFECYCLE */
...@@ -220,6 +225,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -220,6 +225,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
scene.clearTouchAreas(); scene.clearTouchAreas();
clearScene(); clearScene();
useGameManager = true;
gameManager = null; gameManager = null;
} }
...@@ -252,7 +258,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -252,7 +258,7 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
*/ */
protected void initGame() { protected void initGame() {
getTablexiaContext().showScreenContent(null); getTablexiaContext().showScreenContent(null);
if (gameManager == null) { if (gameManager == null && useGameManager) {
gameManager = new GameManager(gamesDefinition, getTablexiaContext().getSelectedUser(), getDifficulty()); gameManager = new GameManager(gamesDefinition, getTablexiaContext().getSelectedUser(), getDifficulty());
} }
} }
...@@ -302,8 +308,11 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -302,8 +308,11 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
if (gameTrophy == null) { if (gameTrophy == null) {
gameTrophy = GameTrophy.createGameTrophyAndSave(userId, gameNumber); gameTrophy = GameTrophy.createGameTrophyAndSave(userId, gameNumber);
} }
List<TrophyEnum> trophies = gameTrophy.nextGameComplete(getDifficulty(), score); List<TrophyEnum> trophies = null;
trophies.addAll(UserTrophyDefinition.processUserTrophies(selectedUser)); if (score >= 0) {
trophies = gameTrophy.nextGameComplete(getDifficulty(), score);
trophies.addAll(UserTrophyDefinition.processUserTrophies(selectedUser));
}
showVictoryScreen(score, trophies); showVictoryScreen(score, trophies);
GameTrophy.logAllGameTrophysForUser(userId); GameTrophy.logAllGameTrophysForUser(userId);
} }
...@@ -906,7 +915,9 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -906,7 +915,9 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
@Override @Override
public void run() { public void run() {
if (playVictorySpeech == true) { if (playVictorySpeech == true) {
soundControl.playSound(getVictorySpeech()[score], false); if (score >= 0 && score < getVictorySpeech().length) {
soundControl.playSound(getVictorySpeech()[score], false);
}
} }
} }
...@@ -952,12 +963,13 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -952,12 +963,13 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
* @param trophies game trophies * @param trophies game trophies
*/ */
private void showTrophies(List<TrophyEnum> trophies) { private void showTrophies(List<TrophyEnum> trophies) {
if (trophies != null) {
for (int i = 0; i < trophies.size(); i++) { for (int i = 0; i < trophies.size(); i++) {
if (i < VICTORY_SCREEN_TROPHIES_LAYOUTS.length) { if (i < VICTORY_SCREEN_TROPHIES_LAYOUTS.length) {
showTrophyImage(VICTORY_SCREEN_TROPHIES_LAYOUTS[i], trophies.get(i)); showTrophyImage(VICTORY_SCREEN_TROPHIES_LAYOUTS[i], trophies.get(i));
} }
} }
}
} }
/** /**
...@@ -1008,15 +1020,24 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -1008,15 +1020,24 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
* @param score score to show in victory screen (number of stars) * @param score score to show in victory screen (number of stars)
*/ */
private void setVictoryScreenScore(int score) { private void setVictoryScreenScore(int score) {
if (score > 0) { if (score < 0) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar1), SfxSounds.VICTORYSCREEN_STAR1_SOUND, VICTORYSCREEN_STAR1_DELAY); victoryLayout.findViewById(R.id.victoryscreen_ratingstar1).setVisibility(View.GONE);
} victoryLayout.findViewById(R.id.victoryscreen_ratingstar2).setVisibility(View.GONE);
if (score > 1) { victoryLayout.findViewById(R.id.victoryscreen_ratingstar3).setVisibility(View.GONE);
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar2), SfxSounds.VICTORYSCREEN_STAR2_SOUND, VICTORYSCREEN_STAR2_DELAY); } else {
} victoryLayout.findViewById(R.id.victoryscreen_ratingstar1).setVisibility(View.VISIBLE);
if (score > 2) { victoryLayout.findViewById(R.id.victoryscreen_ratingstar2).setVisibility(View.VISIBLE);
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar3), SfxSounds.VICTORYSCREEN_STAR3_SOUND, VICTORYSCREEN_STAR3_DELAY); victoryLayout.findViewById(R.id.victoryscreen_ratingstar3).setVisibility(View.VISIBLE);
} if (score > 0) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar1), SfxSounds.VICTORYSCREEN_STAR1_SOUND, VICTORYSCREEN_STAR1_DELAY);
}
if (score > 1) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar2), SfxSounds.VICTORYSCREEN_STAR2_SOUND, VICTORYSCREEN_STAR2_DELAY);
}
if (score > 2) {
showStar((FrameLayout) victoryLayout.findViewById(R.id.victoryscreen_ratingstar3), SfxSounds.VICTORYSCREEN_STAR3_SOUND, VICTORYSCREEN_STAR3_DELAY);
}
}
} }
/** /**
...@@ -1074,14 +1095,14 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct ...@@ -1074,14 +1095,14 @@ public abstract class GameActivity extends LayoutGameActivity implements MenuAct
* @param score score to show on victory screen * @param score score to show on victory screen
*/ */
public void setVictoriousTextsAndProgress(int score) { public void setVictoriousTextsAndProgress(int score) {
TextView txtvVictory = (TextView) victoryLayout.findViewById(R.id.victoryscreen_message); TextView txtvVictory = (TextView) victoryLayout.findViewById(R.id.victoryscreen_message);
txtvVictory.setText(getVictoryText(score)); txtvVictory.setText(getVictoryText(score));
TextView tvStats = (TextView) victoryLayout.findViewById(R.id.victoryscreen_result); TextView tvStats = (TextView) victoryLayout.findViewById(R.id.victoryscreen_result);
tvStats.setText(getStatsText()); tvStats.setText(getStatsText());
resetVictoryScreenScore(); resetVictoryScreenScore();
setVictoryScreenScore(score); setVictoryScreenScore(score);
} }
/** /**
......
...@@ -74,6 +74,7 @@ import cz.nic.tablexia.game.games.potme.map.mapobject.MapObjectType; ...@@ -74,6 +74,7 @@ import cz.nic.tablexia.game.games.potme.map.mapobject.MapObjectType;
import cz.nic.tablexia.game.games.potme.map.tile.Tile; import cz.nic.tablexia.game.games.potme.map.tile.Tile;
import cz.nic.tablexia.game.games.potme.map.widget.MapWidget; import cz.nic.tablexia.game.games.potme.map.widget.MapWidget;
import cz.nic.tablexia.game.games.potme.map.widget.MapWidget.TileMapClickListener; import cz.nic.tablexia.game.games.potme.map.widget.MapWidget.TileMapClickListener;
import cz.nic.tablexia.game.manager.GameManager;
/** /**
* Activity for "Potmě" game * Activity for "Potmě" game
...@@ -176,7 +177,10 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener ...@@ -176,7 +177,10 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
public static int ACTION_SIZE_SMALLER; public static int ACTION_SIZE_SMALLER;
private int planningStartTime = 0; private int planningStartTime = 0;
private PotmeDifficulty potmeDifficulty;
private boolean currentFirstPlay = true;
private RandomAccess randomAccess; private RandomAccess randomAccess;
private ActionsStripWidget actionsStripWidget; private ActionsStripWidget actionsStripWidget;
private ActionsWidget actionsWidget; private ActionsWidget actionsWidget;
...@@ -335,6 +339,8 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener ...@@ -335,6 +339,8 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
protected void resetGame() { protected void resetGame() {
super.resetGame(); super.resetGame();
potmeDifficulty = null;
randomAccess = null; randomAccess = null;
mapWidgets = null; mapWidgets = null;
...@@ -348,6 +354,10 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener ...@@ -348,6 +354,10 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
@Override @Override
protected void initGame() { protected void initGame() {
if (!getPotmeDifficulty().hasResults()) {
disableGameManagerForCurrentGame();
currentFirstPlay = false;
}
super.initGame(); super.initGame();
// calculate widgets sizes // calculate widgets sizes
...@@ -359,8 +369,7 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener ...@@ -359,8 +369,7 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
TILE_SIZE = (int)(((displaySize.x - actionStripWidgetWidth - actionPanelWidth) / MAP_X_SIZE) * TILE_SIZE_RATIO); TILE_SIZE = (int)(((displaySize.x - actionStripWidgetWidth - actionPanelWidth) / MAP_X_SIZE) * TILE_SIZE_RATIO);
MAP_START_POSITION_X = (int)(TILE_SIZE * MAP_START_X_TILE_SIZE_RATIO); MAP_START_POSITION_X = (int)(TILE_SIZE * MAP_START_X_TILE_SIZE_RATIO);
MAP_START_POSITION_Y = (int)(displaySize.y - (TILE_SIZE * MAP_START_Y_TILE_SIZE_RATIO)); MAP_START_POSITION_Y = (int)(displaySize.y - (TILE_SIZE * MAP_START_Y_TILE_SIZE_RATIO));
PotmeDifficulty potmeDifficulty = PotmeDifficulty.getPotmeDifficultyForGameDifficulty(getDifficulty());
mapWidgets = new ArrayList<MapWidget>(); mapWidgets = new ArrayList<MapWidget>();
errorCount = 0; errorCount = 0;
...@@ -371,11 +380,11 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener ...@@ -371,11 +380,11 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
GameLayer.attachLayersToScene(scene); GameLayer.attachLayersToScene(scene);
showMapWidgets(potmeDifficulty); showMapWidgets(getPotmeDifficulty());
prepareBackground(); prepareBackground();
actionsStripWidget = showActionsStripWidget(actionStripWidgetWidth); actionsStripWidget = showActionsStripWidget(actionStripWidgetWidth);
actionsWidget = showActionsWidget(potmeDifficulty, actionStripWidgetWidth); actionsWidget = showActionsWidget(getPotmeDifficulty(), actionStripWidgetWidth);
startButton = showStartButton((int)actionsWidget.getX()); startButton = showStartButton((int)actionsWidget.getX());
//TODO remove and use event bus //TODO remove and use event bus
actionsStripWidget.setStartButton(startButton); actionsStripWidget.setStartButton(startButton);
...@@ -491,34 +500,34 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener ...@@ -491,34 +500,34 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
private void showMapWidgets(PotmeDifficulty potmeDifficulty) { private void showMapWidgets(PotmeDifficulty potmeDifficulty) {
try { try {
Tile lastFinishPosition = null; Tile lastFinishPosition = null;
int floorCount = potmeDifficulty.getFloorCount(); int floorCount = potmeDifficulty.getFloorCount();
boolean hasKey = potmeDifficulty.hasDifficultyActionType(ActionType.KEY); boolean hasKey = potmeDifficulty.hasDifficultyActionType(ActionType.KEY);
for (int i = 0; i < floorCount; i++) { for (int i = 0; i < floorCount; i++) {
MapObjectType finishMapObjetcMapObjectType; MapObjectType finishMapObjetcMapObjectType;
if (i == (floorCount - 1)) { if (i == (floorCount - 1)) {
finishMapObjetcMapObjectType = MapObjectType.SAFE; finishMapObjetcMapObjectType = MapObjectType.SAFE;
} else { } else {
finishMapObjetcMapObjectType = MapObjectType.STAIRS; finishMapObjetcMapObjectType = MapObjectType.STAIRS;
} }
boolean floorHasKey = hasKey && ((floorCount - 1) / 2) == i; boolean floorHasKey = hasKey && ((floorCount - 1) / 2) == i;
MapWidget mapWidget = new MapWidget(lastFinishPosition, finishMapObjetcMapObjectType, i, floorCount > 1, MAP_START_POSITION_X, MAP_START_POSITION_Y, MAP_X_SIZE, MAP_Y_SIZE, floorHasKey, randomAccess, getResources().getText(R.string.game_potme_floor).toString(), getVertexBufferObjectManager()); MapWidget mapWidget = new MapWidget(potmeDifficulty.getMapProviderNewInstance(randomAccess), lastFinishPosition, finishMapObjetcMapObjectType, i, floorCount > 1, MAP_START_POSITION_X, MAP_START_POSITION_Y, MAP_X_SIZE, MAP_Y_SIZE, floorHasKey, getResources().getText(R.string.game_potme_floor).toString(), getVertexBufferObjectManager());
mapWidgets.add(mapWidget); mapWidgets.add(mapWidget);
if (i == 0) { if (i == 0) {
mapWidget.setInFront(); mapWidget.setInFront();
} else { } else {
mapWidget.setInBottom(); mapWidget.setInBottom();
} }
mapWidget.setClickable(scene, this); mapWidget.setClickable(scene, this);
GameLayer.MAP_LAYER.getLayerEntity().attachChild(mapWidget); GameLayer.MAP_LAYER.getLayerEntity().attachChild(mapWidget);
lastFinishPosition = mapWidget.getTileMap().getTileAtPosition(mapWidget.getTileMap().getMapFinishPosition()); lastFinishPosition = mapWidget.getTileMap().getTileAtPosition(mapWidget.getTileMap().getMapFinishPosition());
} }
} catch (Throwable t) { } catch (Throwable t) {
throw new RuntimeException("Error during generating map with random seed: " + randomAccess.getRandomSeed(), t); throw new RuntimeException("Error during generating map with random seed: " + randomAccess.getRandomSeed(), t);
} }
...@@ -615,7 +624,9 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener ...@@ -615,7 +624,9 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
} }
private void goToPlayMode() { private void goToPlayMode() {
getGameManager().setExtraInt1(getGameManager().getExtraInt1() + ((int)scene.getSecondsElapsedTotal() - planningStartTime)); if (getGameManager() != null) {
getGameManager().setExtraInt1(getGameManager().getExtraInt1() + ((int)scene.getSecondsElapsedTotal() - planningStartTime));
}
startButton.disable(); startButton.disable();
actionsWidget.disableActions(); actionsWidget.disableActions();
actionsStripWidget.disableControl(); actionsStripWidget.disableControl();
...@@ -728,7 +739,7 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener ...@@ -728,7 +739,7 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
} }
MapObject mapObject = tileMap.getTileAtPosition(player.getActualTileMapPosition()).getMapObject(); MapObject mapObject = tileMap.getTileAtPosition(player.getActualTileMapPosition()).getMapObject();
if ((mapObject != null) && if ((mapObject != null) &&
(!PotmeDifficulty.getPotmeDifficultyForGameDifficulty(getDifficulty()).hasDifficultyActionType(ActionType.KEY) || player.hasKey()) && (!getPotmeDifficulty().hasDifficultyActionType(ActionType.KEY) || player.hasKey()) &&
(mapObject.getMapObjectType() == MapObjectType.SAFE) && (mapObject.getMapObjectType() == MapObjectType.SAFE) &&
(selectedActionPosition == selectedActions.size() - 1)) { (selectedActionPosition == selectedActions.size() - 1)) {
...@@ -739,7 +750,9 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener ...@@ -739,7 +750,9 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
player.registerEntityModifier(new DelayModifier(FINISH_ACTION_DELAY, new EntityModifierListenerAdapter() { player.registerEntityModifier(new DelayModifier(FINISH_ACTION_DELAY, new EntityModifierListenerAdapter() {
@Override @Override
public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) { public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
getGameManager().setCounterAndSave(errorCount); if (getGameManager() != null) {
getGameManager().setCounterAndSave(errorCount);
}
gameComplete(); gameComplete();
} }
})); }));
...@@ -901,24 +914,36 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener ...@@ -901,24 +914,36 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
seedTextView.setPadding(0, 0, 200, 0); seedTextView.setPadding(0, 0, 200, 0);
} }
} }
/* //////////////////////////////////////////// POTME DIFFICULTY */
public PotmeDifficulty getPotmeDifficulty() {
if (potmeDifficulty == null) {
boolean firstPlay = currentFirstPlay && (getTablexiaContext().getSelectedUser() != null) && (GameManager.getGamePlayCountForUser(getTablexiaContext().getSelectedUser(), getGameDefinition()) == 0);
potmeDifficulty = PotmeDifficulty.getPotmeDifficultyForGameDifficulty(getDifficulty(), firstPlay);
}
return potmeDifficulty;
}
/* //////////////////////////////////////////// VICTORY SCREEN CALLBACKS */ /* //////////////////////////////////////////// VICTORY SCREEN CALLBACKS */
@Override @Override
public CharSequence getVictoryText(int progress) { public CharSequence getVictoryText(int progress) {
switch (progress) { switch (progress) {
case 0: case -1:
return getString(R.string.game_potme_victory_0); return getString(R.string.game_potme_victory_tutorial);
case 1: case 0:
return getString(R.string.game_potme_victory_1); return getString(R.string.game_potme_victory_0);
case 2: case 1:
return getString(R.string.game_potme_victory_2); return getString(R.string.game_potme_victory_1);
case 3: case 2:
return getString(R.string.game_potme_victory_3); return getString(R.string.game_potme_victory_2);
default: case 3:
throw new IllegalStateException("Unknown progress"); return getString(R.string.game_potme_victory_3);
} default:
throw new IllegalStateException("Unknown progress");
}
} }
@Override @Override
public String[] getVictorySpeech() { public String[] getVictorySpeech() {
...@@ -927,12 +952,14 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener ...@@ -927,12 +952,14 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
@Override @Override
public CharSequence getStatsText() { public CharSequence getStatsText() {
return Html.fromHtml(getString(R.string.game_potme_error_count, errorCount)); return !getPotmeDifficulty().hasResults() ? "" : Html.fromHtml(getString(R.string.game_potme_error_count, errorCount));
} }
@Override @Override
public int countProgress() { public int countProgress() {
if (errorCount < 1) { if (!getPotmeDifficulty().hasResults()) {
return -1;
} else if (errorCount < 1) {
return 3; return 3;
} else if (errorCount < 3) { } else if (errorCount < 3) {
return 2; return 2;
......
...@@ -3,8 +3,13 @@ package cz.nic.tablexia.game.games.potme; ...@@ -3,8 +3,13 @@ package cz.nic.tablexia.game.games.potme;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import android.util.Log;
import cz.nic.tablexia.game.common.RandomAccess;
import cz.nic.tablexia.game.difficulty.GameDifficulty; import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.potme.action.ActionType; import cz.nic.tablexia.game.games.potme.action.ActionType;
import cz.nic.tablexia.game.games.potme.map.IMapProvider;
import cz.nic.tablexia.game.games.potme.map.MapGenerator;
import cz.nic.tablexia.game.games.potme.map.MapTutorial;
/** /**
* Game potme difficulty definition and mapping to game difficulty * Game potme difficulty definition and mapping to game difficulty
...@@ -14,18 +19,27 @@ import cz.nic.tablexia.game.games.potme.action.ActionType; ...@@ -14,18 +19,27 @@ import cz.nic.tablexia.game.games.potme.action.ActionType;
*/ */
public enum PotmeDifficulty { public enum PotmeDifficulty {
EASY (GameDifficulty.EASY, 1, Arrays.asList(new ActionType[]{})), TUTORIAL(null, false, MapTutorial.class, 1, Arrays.asList(new ActionType[]{})),
MEDIUM (GameDifficulty.MEDIUM, 1, Arrays.asList(new ActionType[]{ActionType.KEY})), EASY (GameDifficulty.EASY, true, MapGenerator.class, 1, Arrays.asList(new ActionType[]{})),
HARD (GameDifficulty.HARD, 2, Arrays.asList(new ActionType[]{ActionType.KEY})); 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 GameDifficulty gameDifficulty;
private int floorCount; private int floorCount;
private List<ActionType> difficultyActionTypes; private List<ActionType> difficultyActionTypes;
private Class<? extends IMapProvider> mapProviderClass;
private boolean hasResults;
private PotmeDifficulty(GameDifficulty gameDifficulty, int floorCount, List<ActionType> difficultyActionTypes) { private PotmeDifficulty(GameDifficulty gameDifficulty, boolean hasResults, Class<? extends IMapProvider> mapProviderClass, int floorCount, List<ActionType> difficultyActionTypes) {
this.gameDifficulty = gameDifficulty; this.gameDifficulty = gameDifficulty;
this.floorCount = floorCount; this.hasResults = hasResults;
this.difficultyActionTypes = difficultyActionTypes; this.mapProviderClass = mapProviderClass;
this.floorCount = floorCount;
this.difficultyActionTypes = difficultyActionTypes;
}
public boolean hasResults() {
return hasResults;
} }
public int getFloorCount() { public int getFloorCount() {
...@@ -36,7 +50,10 @@ public enum PotmeDifficulty { ...@@ -36,7 +50,10 @@ public enum PotmeDifficulty {
return difficultyActionTypes.contains(actionType); return difficultyActionTypes.contains(actionType);
} }
public static PotmeDifficulty getPotmeDifficultyForGameDifficulty(GameDifficulty gameDifficulty) { public static PotmeDifficulty getPotmeDifficultyForGameDifficulty(GameDifficulty gameDifficulty, boolean isFirstGame) {
if (isFirstGame) {
return TUTORIAL;
}
for (PotmeDifficulty potmeDifficulty : PotmeDifficulty.values()) { for (PotmeDifficulty potmeDifficulty : PotmeDifficulty.values()) {
if (potmeDifficulty.gameDifficulty == gameDifficulty) { if (potmeDifficulty.gameDifficulty == gameDifficulty) {
return potmeDifficulty; return potmeDifficulty;
...@@ -45,4 +62,13 @@ public enum PotmeDifficulty { ...@@ -45,4 +62,13 @@ public enum PotmeDifficulty {
return null; return null;
} }
public IMapProvider getMapProviderNewInstance(RandomAccess randomAccess) {
try {
return mapProviderClass.getConstructor(RandomAccess.class).newInstance(randomAccess);
} catch (Exception e) {
Log.e(PotmeDifficulty.class.getCanonicalName(), "Cannot create instance for IMapProvider class: " + mapProviderClass, e);
}
return null;
}
} }
package cz.nic.tablexia.game.games.potme.map;
import cz.nic.tablexia.game.games.potme.map.mapobject.MapObjectType;
import cz.nic.tablexia.game.games.potme.map.tile.Tile;
public interface IMapProvider {
public TileMap prepareMap(Tile lastFinishTile, int mapXSize, int mapYSize, MapObjectType finishMapObject, boolean hasKey);
}
...@@ -39,7 +39,7 @@ import cz.nic.tablexia.game.games.potme.map.tile.TileType; ...@@ -39,7 +39,7 @@ import cz.nic.tablexia.game.games.potme.map.tile.TileType;
* @author Matyáš Latner * @author Matyáš Latner
* *
*/ */
public class MapGenerator { public class MapGenerator implements IMapProvider {
private static final double OBSTACLE_PROBABILITY = 0.4; private static final double OBSTACLE_PROBABILITY = 0.4;
...@@ -82,7 +82,7 @@ public class MapGenerator { ...@@ -82,7 +82,7 @@ public class MapGenerator {
this.randomAccess = randomAccess; this.randomAccess = randomAccess;
} }
public TileMap generateRandomMap(Tile lastFinishTile, int mapXSize, int mapYSize, MapObjectType finishMapObject, boolean hasKey) { public TileMap prepareMap(Tile lastFinishTile, int mapXSize, int mapYSize, MapObjectType finishMapObject, boolean hasKey) {
Log.d(MapGenerator.class.getCanonicalName(), "Start generating with random seed: " + randomAccess.getRandomSeed()); Log.d(MapGenerator.class.getCanonicalName(), "Start generating with random seed: " + randomAccess.getRandomSeed());
TileMap tileMap = new TileMap(mapXSize, mapYSize); TileMap tileMap = new TileMap(mapXSize, mapYSize);
...@@ -103,7 +103,7 @@ public class MapGenerator { ...@@ -103,7 +103,7 @@ public class MapGenerator {
// connect all tile groups // connect all tile groups
connectAllGroups(tileMap, Arrays.asList(new TileMapPosition[] {startPosition})); connectAllGroups(tileMap, Arrays.asList(new TileMapPosition[] {startPosition}));
// selects best tile for safe // select best tile for safe
Tile finishTile = createFinishTile(tileMap, finishMapObject); Tile finishTile = createFinishTile(tileMap, finishMapObject);
tileMap.setMapFinishPosition(finishTile.getTileMapPosition()); tileMap.setMapFinishPosition(finishTile.getTileMapPosition());
......
package cz.nic.tablexia.game.games.potme.map;
import android.util.Log;
import cz.nic.tablexia.game.common.RandomAccess;
import cz.nic.tablexia.game.games.potme.PotmeActivity;
import cz.nic.tablexia.game.games.potme.map.TileMap.TileMapPosition;
import cz.nic.tablexia.game.games.potme.map.mapobject.MapObjectType;
import cz.nic.tablexia.game.games.potme.map.mapobstacle.MapObstacleType;
import cz.nic.tablexia.game.games.potme.map.mapobstacle.MapObstacleType.MapObstaclePosition;
import cz.nic.tablexia.game.games.potme.map.tile.Tile;
import cz.nic.tablexia.game.games.potme.map.tile.TileType;
public class MapTutorial implements IMapProvider {
protected RandomAccess randomAccess;
public MapTutorial(RandomAccess randomAccess) {
this.randomAccess = randomAccess;
}
@Override
public TileMap prepareMap(Tile lastFinishTile, int mapXSize, int mapYSize, MapObjectType finishMapObject, boolean hasKey) {
Log.d(MapGenerator.class.getCanonicalName(), "Start preparing tutorial map with random seed: " + randomAccess.getRandomSeed());
TileMap tileMap = new TileMap(mapXSize, mapYSize);
TileMapPosition position1 = PotmeActivity.DEFAULT_MAP_START_POSITION;
TileMapPosition position2 = new TileMapPosition(position1.getPositionX() - 1, position1.getPositionY());
TileMapPosition position3 = new TileMapPosition(position1.getPositionX() - 1, position1.getPositionY() - 1);
tileMap.setMapStartPosition(position1);
tileMap.setMapFinishPosition(position3);
Tile tile1 = new Tile(TileType.TILE_2IH);
Tile tile2 = new Tile(TileType.TILE_2LA);
Tile tile3 = new Tile(TileType.TILE_1C);
tileMap.addTileAtPosition(position1, tile1);
tileMap.addTileAtPosition(position2, tile2);
tileMap.addTileAtPosition(position3, tile3);
tile3.setMapObstacle(MapObstaclePosition.BOTTOM_POSITION, MapObstacleType.DOOR_H);
tile3.setMapObject(finishMapObject);
// fill all map
for (int i = 0; i < tileMap.getMapXSize(); i++) {
for (int j = 0; j < tileMap.getMapYSize(); j++) {
if (!tileMap.isTileAtPosition(i, j)) {
Tile tile = new Tile(TileType.TILE_0);
tileMap.addTileAtPosition(i, j, tile);
}
}
}
return tileMap;
}
}
\ No newline at end of file
...@@ -30,10 +30,9 @@ import org.andengine.opengl.vbo.DrawType; ...@@ -30,10 +30,9 @@ import org.andengine.opengl.vbo.DrawType;
import org.andengine.opengl.vbo.VertexBufferObjectManager; import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.adt.color.Color; import org.andengine.util.adt.color.Color;
import cz.nic.tablexia.game.common.RandomAccess;
import cz.nic.tablexia.game.games.potme.PotmeActivity; import cz.nic.tablexia.game.games.potme.PotmeActivity;
import cz.nic.tablexia.game.games.potme.ResourceManager; import cz.nic.tablexia.game.games.potme.ResourceManager;
import cz.nic.tablexia.game.games.potme.map.MapGenerator;