Commit 87030869 authored by Luboš Horáček's avatar Luboš Horáček

#11 Using GameDifficulty enum in game menu

parent 8d4c5572
......@@ -10,9 +10,9 @@ mainmenu_preferences=Nastavení
mainmenu_about=O aplikaci
mainmenu_logout=Odhlásit
gamemenu_easy=Lehká
gamemenu_medium=Střední
gamemenu_hard=Těžká
gamedifficulty_easy=Lehká
gamedifficulty_medium=Střední
gamedifficulty_hard=Těžká
game_robbery_title=Lupiči
game_kidnapping_title=Únos
......
......@@ -10,9 +10,9 @@ mainmenu_preferences=Nastavenie
mainmenu_about=O aplikácií
mainmenu_logout=Odhlásiť
gamemenu_easy=Ľahká
gamemenu_medium=Stredná
gamemenu_hard=Ťažká
gamedifficulty_easy=Ľahká
gamedifficulty_medium=Stredná
gamedifficulty_hard=Ťažká
game_robbery_title=Lupiči
game_kidnapping_title=Únos
......
package cz.nic.tablexia.game;
import cz.nic.tablexia.Tablexia.ChangeScreenEvent;
import cz.nic.tablexia.TablexiaApplication.ScreenTransaction;
import cz.nic.tablexia.bus.ApplicationBus;
import cz.nic.tablexia.bus.ApplicationBus.ApplicationEvent;
import cz.nic.tablexia.game.games.in_the_darkness.InTheDarknessScreen;
import cz.nic.tablexia.game.games.kidnapping.KidnappingScreen;
import cz.nic.tablexia.game.games.night_watch.NightWatchScreen;
import cz.nic.tablexia.game.games.pursuit.PursuitScreen;
import cz.nic.tablexia.game.games.robbery.RobberyScreen;
import cz.nic.tablexia.game.games.shooting_range.ShootingRangeScreen;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.menu.IMenuItem;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
public enum GameDefinition implements ApplicationEvent, IMenuItem {
ROBBERY ("game_robbery_title", RobberyScreen.class, true),
PURSUIT ("game_pursuit_title", PursuitScreen.class, true),
KIDNAPPING ("game_kidnapping_title", KidnappingScreen.class, true),
NIGHT_WATCH ("game_night_watch_title", NightWatchScreen.class, true),
SHOOTING_RANGE ("game_shooting_range_title", ShootingRangeScreen.class, true),
IN_THE_DARKNESS ("game_in_the_darkness_title", InTheDarknessScreen.class, true);
private String menuTextKey;
private Class<? extends AbstractTablexiaScreen<?>> screenClass;
private boolean isCloseMenu;
<<<<<<< HEAD
public static GameDefinition[] getActiveGames(){
return new GameDefinition[]{ROBBERY, PURSUIT, KIDNAPPING, NIGHT_WATCH, SHOOTING_RANGE, IN_THE_DARKNESS};
}
private GameDefinition(String nameResource, Class<? extends AbstractTablexiaScreen<?>> screenClass, boolean isCloseMenu) {
=======
private GameDefinition(String nameResource, Class<? extends AbstractTablexiaGame<?>> screenClass, boolean isCloseMenu) {
>>>>>>> feature-pauseresume
this.menuTextKey = nameResource;
this.screenClass = screenClass;
this.isCloseMenu = isCloseMenu;
}
@Override
public String getTitle() {
return ApplicationTextManager.getInstance().getResult().get(menuTextKey);
}
@Override
public void performAction() {
ApplicationBus.getInstance().publishAsync(this);
ApplicationBus.getInstance().publishAsync(new ChangeScreenEvent(screenClass, ScreenTransaction.FADE));
}
@Override
public boolean isCloseMenu() {
return isCloseMenu;
}
}
......@@ -27,13 +27,14 @@ package cz.nic.tablexia.game.difficulty;
public enum GameDifficulty {
// TODO use string resources
EASY(1),
MEDIUM(2),
HARD(3);
EASY("gamedifficulty_easy"),
MEDIUM("gamedifficulty_medium"),
HARD("gamedifficulty_hard");
private int descriptionResourceId;
private String descriptionResourceId;
private GameDifficulty(int descriptionResourceId) {
private GameDifficulty(String descriptionResourceId) {
this.descriptionResourceId = descriptionResourceId;
}
......@@ -42,7 +43,7 @@ public enum GameDifficulty {
*
* @return id of description string resource
*/
public int getDescriptionResourceId() {
public String getDescriptionResourceId() {
return descriptionResourceId;
}
......
......@@ -16,6 +16,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.game.GameDefinition;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.loader.application.ApplicationTextManager;
import cz.nic.tablexia.screen.AbstractTablexiaScreen;
import cz.nic.tablexia.screen.gamemenu.GameMenuAssets;
......@@ -31,6 +32,7 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener {
private float diffEasyX, diffMediumX, diffHardX;
private Actor diffEasy, diffMedium, diffHard;
private Stack diffStack;
private GameDifficulty gameDifficulty = GameDifficulty.EASY;
private float scrollOffset = TablexiaSettings.getDefaultScreenWidth(); // hack to keep paralax layers out of picture before scrolled for first time
......@@ -118,13 +120,13 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener {
diffHardX = diffMediumX + (diffBarWidth / 2) - (diffWidth * 0.1f);
// Labels for diffuculty slider
BitmapFont font = screen.getDefaultRegularFont();
BitmapFont font = screen.getDefaultBoldFont();
font.setScale(0.5f);
Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.BLACK);
Label easy = new Label(ApplicationTextManager.getInstance().getText("gamemenu_easy"), labelStyle);
Label medium = new Label(ApplicationTextManager.getInstance().getText("gamemenu_medium"), labelStyle);
Label hard = new Label(ApplicationTextManager.getInstance().getText("gamemenu_hard"), labelStyle);
Label easy = new Label(ApplicationTextManager.getInstance().getText(GameDifficulty.EASY.getDescriptionResourceId()), labelStyle);
Label medium = new Label(ApplicationTextManager.getInstance().getText(GameDifficulty.MEDIUM.getDescriptionResourceId()), labelStyle);
Label hard = new Label(ApplicationTextManager.getInstance().getText(GameDifficulty.HARD.getDescriptionResourceId()), labelStyle);
float labelY = screen.getStage().getHeight() * 0.06f;
float labelAddX = diffWidth / 2;
......@@ -146,7 +148,7 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener {
diffStack.setSize(diffWidth, diffHeight);
diffStack.setPosition(diffX, diffY);
addActor(diffStack);
fixDiffImage();
setDifficulty(gameDifficulty);
diffStack.addListener(new InputListener() {
float lastX;
......@@ -166,7 +168,7 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener {
if (bx >= diffEasyX && bx <= diffHardX) {
diffStack.setPosition(bx, diffStack.getY());
}
fixDiffImage();
showDifficulty(getDifficulty());
event.stop();
}
......@@ -174,60 +176,95 @@ public class GameMenuPage extends MenuPage implements ViewPager.ScrollListener {
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
super.touchUp(event, x, y, pointer, button);
float bx = diffStack.getX() + (x - lastX);
MoveToAction ma = new MoveToAction();
switch (getDifficulty()) {
case 0:
ma.setPosition(diffEasyX, diffStack.getY());
break;
case 1:
ma.setPosition(diffMediumX, diffStack.getY());
break;
case 2:
ma.setPosition(diffHardX, diffStack.getY());
break;
GameDifficulty newDiff = getDifficulty();
setDifficulty(newDiff);
if (gameDifficulty != newDiff) {
difficultyChanged(newDiff);
}
diffStack.addAction(ma);
event.stop();
}
});
}
private void fixDiffImage() {
switch (getDifficulty()) {
case 0:
showDifficulty(diffEasy);
/**
* Change selector to custom difficulty
*
* @param difficulty
*/
public void setDifficulty(GameDifficulty difficulty) {
showDifficulty(difficulty);
MoveToAction ma = new MoveToAction();
switch (difficulty) {
case EASY:
ma.setPosition(diffEasyX, diffStack.getY());
break;
case 1:
showDifficulty(diffMedium);
case MEDIUM:
ma.setPosition(diffMediumX, diffStack.getY());
break;
case 2:
showDifficulty(diffHard);
case HARD:
ma.setPosition(diffHardX, diffStack.getY());
break;
}
diffStack.addAction(ma);
if (gameDifficulty != difficulty) {
difficultyChanged(difficulty);
}
}
private int getDifficulty() {
/**
* Called when difficulty is changed
*
* @param difficulty
*/
public void difficultyChanged(GameDifficulty difficulty) {
gameDifficulty = difficulty;
// TODO
}
/**
* Get nearest difficulty from current slider position
*
* @return
*/
private GameDifficulty getDifficulty() {
float bx = diffStack.getX();
if (bx < diffMediumX) {
if ((diffEasyX + ((diffMediumX - diffEasyX) / 2)) > bx) {
return 0;
return GameDifficulty.EASY;
} else {
return 1;
return GameDifficulty.MEDIUM;
}
} else {
if ((diffMediumX + ((diffHardX - diffMediumX) / 2)) > bx) {
return 1;
return GameDifficulty.MEDIUM;
} else {
return 2;
return GameDifficulty.HARD;
}
}
}
private void showDifficulty(Actor diff) {
/**
* Check difficulty image and display corresponding image
*
* @param diff
*/
private void showDifficulty(GameDifficulty diff) {
diffEasy.setVisible(false);
diffMedium.setVisible(false);
diffHard.setVisible(false);
diff.setVisible(true);
switch (diff) {
case EASY:
diffEasy.setVisible(true);
break;
case MEDIUM:
diffMedium.setVisible(true);
break;
case HARD:
diffHard.setVisible(true);
break;
}
}
@Override
......
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