Commit 69684aa8 authored by Vitaliy Vashchenko's avatar Vitaliy Vashchenko

Merge branch 'feature-safe-refactoring' into 'V3.7'

Feature safe refactoring

See merge request !657
parents 8b5aa1e4 8a82e27f
......@@ -29,6 +29,8 @@ import cz.nic.tablexia.game.games.safe.model.SafeSequence;
public abstract class AbstractMechanics extends Group {
private static final int ANGLE_SPREAD = 17;
private static final int FULL_DEGREES = 360;
private static final int QUARTER_OF_CIRCLE = 90;
public static final String LIGHT_NAME = "light";
public static final String LIGHT_LIGHTED_UP = "light lighted up";
public static boolean holding = false;
......@@ -44,7 +46,7 @@ public abstract class AbstractMechanics extends Group {
boolean foundValid = false;
for (SafeLightImage lightImage : listOfLights) {
float testedAngle = lightImage.getAngle();
if (testedAngle < 0) testedAngle += 360;
if (testedAngle < 0) testedAngle += FULL_DEGREES;
if (testedAngle - ANGLE_SPREAD <= angle && testedAngle + ANGLE_SPREAD > angle) {
foundValid = true;
if (!lightImage.equals(safeGame.getSelectedLight())) {
......@@ -63,7 +65,7 @@ public abstract class AbstractMechanics extends Group {
protected void rotateSafeCircleTo(Vector2 dest, Image rotationObject) {
Vector2 safeOrigin = rotationObject.localToStageCoordinates(new Vector2(rotationObject.getOriginX(), rotationObject.getOriginY()));
float angle = dest.sub(safeOrigin).angle() - 90;
float angle = dest.sub(safeOrigin).angle() - QUARTER_OF_CIRCLE;
rotationObject.setRotation(angle);
}
......
......@@ -46,7 +46,9 @@ public class Cable extends Group {
private static final int INC_SHAPING = 100;
private static final int CNT_PARTS_MIN_SHAPING = 5;
private static final int MIN_CABLE_LENGTH = 30;
private static final int SAMPLES = 10;
private static final int FULL_DEGREES = 360;
private static final int QUARTER_OF_CIRCLE = 90;
public static final int CABLE_WIDTH = 20;
private static final float UV_TEXTURE_BLEEDING_FIX = 0.003f;
......@@ -189,7 +191,7 @@ public class Cable extends Group {
cableSpriteBatch.reset();
spline.set(splineVectors, false);
float approxLength = spline.approxLength(10);
float approxLength = spline.approxLength(SAMPLES);
int minParts = getCableLength() > MIN_CABLE_LENGTH ? MINUMUM_CABLE_PARTS : 2;
int cableSegments = (int) (approxLength / PREFFERED_CABLE_PART_LENGTH);
......@@ -208,7 +210,7 @@ public class Cable extends Group {
spline.valueAt(tempPoint, progress);
spline.derivativeAt(tempDir, progress);
distances.add(prevPoint.dst(tempPoint));
float angle = (tempDir.angle() + 90) % 360;
float angle = (tempDir.angle() + QUARTER_OF_CIRCLE) % FULL_DEGREES;
float cos = MathUtils.cosDeg(angle) * CABLE_WIDTH / 2;
float sin = MathUtils.sinDeg(angle) * CABLE_WIDTH / 2;
......
......@@ -39,6 +39,7 @@ import cz.nic.tablexia.game.games.safe.listeners.DoneButtonClickListener;
import cz.nic.tablexia.game.games.safe.listeners.HelpButtonClickListener;
import cz.nic.tablexia.game.games.safe.listeners.ReplayButtonClickListener;
import cz.nic.tablexia.game.games.safe.model.SafeDifficulty;
import cz.nic.tablexia.game.games.safe.model.SafeGameResultStars;
import cz.nic.tablexia.game.games.safe.model.SafeSequence;
import cz.nic.tablexia.game.games.safe.gameobject.VisualizationDialog;
import cz.nic.tablexia.loader.application.ApplicationAtlasManager;
......@@ -451,33 +452,11 @@ public class SafeGame extends AbstractTablexiaGame<Void> {
@Override
protected String getTextKeyForGameResult(GameResult gameResult) {
switch (gameResult) {
case NO_STAR:
return SafeAssets.SCORE_0_TEXT;
case ONE_STAR:
return SafeAssets.SCORE_1_TEXT;
case TWO_STAR:
return SafeAssets.SCORE_2_TEXT;
case THREE_STAR:
return SafeAssets.SCORE_3_TEXT;
default:
return SafeAssets.SCORE_0_TEXT;
}
return SafeGameResultStars.getTextForGameResult(gameResult);
}
@Override
protected String getSoundNameForGameResult(GameResult gameResult) {
switch (gameResult) {
case NO_STAR:
return SafeAssets.SCORE_0_SOUND;
case ONE_STAR:
return SafeAssets.SCORE_1_SOUND;
case TWO_STAR:
return SafeAssets.SCORE_2_SOUND;
case THREE_STAR:
return SafeAssets.SCORE_3_SOUND;
default:
return SafeAssets.SCORE_0_SOUND;
}
return SafeGameResultStars.getSoundForGameResult(gameResult);
}
}
......@@ -48,12 +48,14 @@ import cz.nic.tablexia.util.ui.TablexiaLabel;
*/
public class SequenceGenerator extends Group {
public static final String SCENARIO_STEP_SEQUENCE_PLAYED = "sequence played";
public static final String SCENARIO_STEP_SEQUENCE_PLAYED = "sequence played";
private static final ApplicationFontManager.FontType FONT_TYPE = ApplicationFontManager.FontType.REGULAR_30;
private static final Color FONT_COLOR = Color.WHITE;
private static final Color PLAY_COLOR = new Color(0x29abe1ff); //baby blue
private static final Color NORMAL_COLOR = Color.BLACK;
private static final float SILENCE_DELAY = 2f;
private static final float SEQUENCE_DELAY = 1f;
private Image earImage, backgroundImage;
private TablexiaLabel text;
......@@ -99,7 +101,7 @@ public class SequenceGenerator extends Group {
* @param afterAction do this after sound sequence has been played
*/
public void playSequenceVisualization(SafeSequence safeSequence, SafeGame safeGame, List<Actor> listOfChars, RunnableAction afterAction) {
SequenceGenerator.this.addAction(Actions.sequence(Actions.delay(1f), soundSequence(safeSequence, safeGame, listOfChars)));
SequenceGenerator.this.addAction(Actions.sequence(Actions.delay(SEQUENCE_DELAY), soundSequence(safeSequence, safeGame, listOfChars)));
SequenceGenerator.this.addAction(Actions.after(afterAction));
}
......@@ -137,7 +139,7 @@ public class SequenceGenerator extends Group {
private static int addSound(SequenceAction sa, SafeSounds safeSequenceSound, int charNum, List<Actor> listOfChars, List<Action> playMusicActionList, SafeSequence safeSequence) {
if (safeSequenceSound.equals(SafeSounds.SILENCE)) {
sa.addAction(Actions.delay(2f));
sa.addAction(Actions.delay(SILENCE_DELAY));
soundSequence += " - ";
} else {
soundSequence += safeSequenceSound.toString() + " ";
......
......@@ -44,15 +44,17 @@ import cz.nic.tablexia.screen.AbstractTablexiaScreen;
*/
public class CableGroup extends Group {
private final int SOCKET_WIDTH = 125;
private final int SOCKET_HEIGHT = 75;
private static final int SOCKET_WIDTH = 125;
private static final int SOCKET_HEIGHT = 75;
private final int CONNECTOR_WIDTH = 80;
private final int CONNECTOR_HEIGHT = 40;
private final int MAX_CABLE_PARTS = 18;
private static final int CONNECTOR_WIDTH = 80;
private static final int CONNECTOR_HEIGHT = 40;
private static final int MAX_CABLE_PARTS = 18;
private final int SAFE_LIGHT_SIZE = 40;
private final int SAFE_LIGHT_X_POS = 50;
private static final int SAFE_LIGHT_SIZE = 40;
private static final int SAFE_LIGHT_X_POS = 50;
private static final float LIGHT_DELAY = 1;
private SafeGame safeGame;
private SafeMechanicsMedium mechanicsMedium;
......@@ -106,7 +108,7 @@ public class CableGroup extends Group {
public void run() {
lightImage.light(listOfLights, safeGame.getSelectedLight());
}
}), Actions.delay(1), Actions.run(new Runnable() {
}), Actions.delay(LIGHT_DELAY), Actions.run(new Runnable() {
@Override
public void run() {
if (safeGame.getSelectedLight() != null)
......
......@@ -33,6 +33,7 @@ import cz.nic.tablexia.game.AbstractTablexiaGame;
*/
public class SafeLightImage extends Image {
private static final float DEFAULT_ANGLE = -1;
private TextureRegion screenTextureGrey;
private TextureRegion screenTextureRed;
......@@ -67,7 +68,7 @@ public class SafeLightImage extends Image {
this.screenTextureGreen = game.getScreenTextureRegion(greenTextureRegion);
this.screenTextureBlue = game.getScreenTextureRegion(blueTextureRegion);
this.sound = music;
this.angle = -1;
this.angle = DEFAULT_ANGLE;
}
public Music getSound() {
......
......@@ -48,12 +48,22 @@ public class VisualizationDialog {
private static final int VISUALIZATION_OK_HEIGHT = 50;
private static final String VISUALIZATION_OK_TEXT = "OK";
private final float BUTTON_Y_POSITION_RATIO = 0.15f;
private final float VIZUALIZATION_PAPER_WIDTH = 0.95f;
private final float VIZUALIZATION_PAPER_HEIGHT = 0.4f;
private final int VIZUALIZATION_PAPER_LEFT_BORDER = 5;
private static final float BUTTON_Y_POSITION_RATIO = 0.15f;
private static final float VIZUALIZATION_PAPER_WIDTH = 0.95f;
private static final float VIZUALIZATION_PAPER_HEIGHT = 0.4f;
private static final int VIZUALIZATION_PAPER_LEFT_BORDER = 5;
private static final float VISUALIZATION_DIALOG_PAPER_PART = 0.85f;
private static final float CHARACTER_SPACE = 40;
private static final float ONE_IMAGE_WITH_SPACE = 40;
private static final float ONE_IMAGE_WIDTH_AND_HEIGHT = 30;
private static final float IMAGE_SPACE = 10;
private static final Color CHARACTER_COLOR = Color.BLACK;
private static final int ALPHA = 0;
SafeGame safeGame;
Group paperVizualizationGroup;
public VisualizationDialog(SafeGame safeGame, Image dimmer) {
this.safeGame = safeGame;
......@@ -68,6 +78,10 @@ public class VisualizationDialog {
paper.setBounds(paperX, paperY, paperWidth, paperHeight);
vizualizationGroup.addActor(paper);
paperVizualizationGroup = new Group(); //part of paper for writing help into
paperVizualizationGroup.setBounds(paper.getX(), paper.getY(), VISUALIZATION_DIALOG_PAPER_PART * paperWidth, paperHeight);
vizualizationGroup.addActor(paperVizualizationGroup);
List<Actor> listOfChars = new ArrayList<Actor>();
if (safeGame.getGameDifficulty().equals(GameDifficulty.EASY))
addImagesToSounds(vizualizationGroup, paper, listOfChars);
......@@ -76,11 +90,11 @@ public class VisualizationDialog {
TablexiaButton buttonOK = new StandardTablexiaButton(VISUALIZATION_OK_TEXT);
buttonOK.setSize(VISUALIZATION_OK_WIDTH, VISUALIZATION_OK_HEIGHT);
buttonOK.setPosition(
paperX + paperWidth / 2 - buttonOK.getWidth() / 2,
paper.getX() + ((paperVizualizationGroup.getWidth() / 2) - (buttonOK.getWidth() / 2)),
paperY + (paperHeight * BUTTON_Y_POSITION_RATIO)
);
buttonOK.setSize(VISUALIZATION_OK_WIDTH, VISUALIZATION_OK_HEIGHT);
buttonOK.setInputListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
......@@ -99,7 +113,7 @@ public class VisualizationDialog {
vizualizationGroup.setVisible(false);
safeGame.getStage().addActor(vizualizationGroup);
vizualizationGroup.addAction(Actions.sequence(Actions.alpha(0), Actions.visible(true), Actions.fadeIn(SafeGame.FADE_ANIMATION_DURATION), Actions.run(new Runnable() {
vizualizationGroup.addAction(Actions.sequence(Actions.alpha(ALPHA), Actions.visible(true), Actions.fadeIn(SafeGame.FADE_ANIMATION_DURATION), Actions.run(new Runnable() {
@Override
public void run() {
safeGame.getSequenceGenerator().playSequenceVisualization(safeGame.getSafeSequence(), safeGame, listOfChars, Actions.run(new Runnable() {
......@@ -114,30 +128,28 @@ public class VisualizationDialog {
private void addImagesToSounds(Group vizualizationGroup, Image paper, List<Actor> listOfChars) {
Group soundImageGroup = new Group();
float oneImageWithSpace = 40;
float oneImageWidthanHeight = 30;
float imageSpace = 10;
int space = VIZUALIZATION_PAPER_LEFT_BORDER;
for (SafeSounds safeSound : safeGame.getSafeSequence().getGeneratedSoundSequence()) {
if (safeSound.equals(SafeSounds.SILENCE)) {
space += oneImageWithSpace;
space += ONE_IMAGE_WITH_SPACE;
} else
space = createAndAddImage(safeSound, soundImageGroup, space, oneImageWidthanHeight, imageSpace, listOfChars);
space = createAndAddImage(safeSound, soundImageGroup, space, ONE_IMAGE_WIDTH_AND_HEIGHT, IMAGE_SPACE, listOfChars);
}
for (int i = 0; i < safeGame.getSafeSequence().getPlayAgainFirstXSounds(); i++) {
SafeSounds safeSound = safeGame.getSafeSequence().getGeneratedSoundSequence()[i];
if (safeSound.equals(SafeSounds.SILENCE)) {
space += oneImageWithSpace;
space += ONE_IMAGE_WITH_SPACE;
} else
space = createAndAddImage(safeSound, soundImageGroup, space, oneImageWidthanHeight, imageSpace, listOfChars);
space = createAndAddImage(safeSound, soundImageGroup, space, ONE_IMAGE_WIDTH_AND_HEIGHT, IMAGE_SPACE, listOfChars);
}
makePositioning(soundImageGroup, paper, space, imageSpace);
soundImageGroup.setWidth(space);
makePositioning(soundImageGroup, paper, space, IMAGE_SPACE);
vizualizationGroup.addActor(soundImageGroup);
}
private void makePositioning(Group soundImageGroup, Image paper, int space, float imageSpace) {
soundImageGroup.setPosition(paper.getX() + (paper.getWidth() - (3 * safeGame.getViewportWidth() * SIDEBAR_RELATIVE_WIDTH / 4)) / 2 - (space + imageSpace) / 2, paper.getY() + paper.getHeight() / 2);
soundImageGroup.setPosition(paper.getX() + paperVizualizationGroup.getWidth() / 2 - soundImageGroup.getWidth() / 2, paper.getY() + paper.getHeight() / 2);
}
private int createAndAddImage(SafeSounds safeSound, Group soundImageGroup, int space, float oneImageWidthanHeight, float imageSpace, List<Actor> listOfChars) {
......@@ -147,7 +159,7 @@ public class VisualizationDialog {
return space;
}
Image soundImage = new Image(safeGame.getScreenTextureRegion(VisualizationObject.getImageForID(imageID)));
soundImage.setColor(Color.BLACK);
soundImage.setColor(CHARACTER_COLOR);
soundImage.setWidth(oneImageWidthanHeight);
soundImage.setHeight(oneImageWidthanHeight);
soundImage.setPosition(space + soundImage.getWidth() / 2, 0);
......@@ -159,17 +171,17 @@ public class VisualizationDialog {
private void addCharactersToSounds(Group vizualizationGroup, Image paper, List<Actor> listOfChars) {
Group soundImageGroup = new Group();
float imageSpace = 40;
int space = VIZUALIZATION_PAPER_LEFT_BORDER;
for (SafeSounds safeSound : safeGame.getSafeSequence().getGeneratedSoundSequence()) {
TablexiaLabel textLabel = new TablexiaLabel(safeSound.getSoundName(), new TablexiaLabel.TablexiaLabelStyle(ApplicationFontManager.FontType.REGULAR_35, Color.WHITE), false);
textLabel.setColor(Color.BLACK);
textLabel.setColor(CHARACTER_COLOR);
textLabel.setPosition(space + textLabel.getWidth() / 2, 0);
space += textLabel.getWidth() + imageSpace;
space += textLabel.getWidth() + CHARACTER_SPACE;
soundImageGroup.addActor(textLabel);
listOfChars.add(textLabel);
}
makePositioning(soundImageGroup, paper, space, imageSpace);
soundImageGroup.setWidth(space);
makePositioning(soundImageGroup, paper, space, CHARACTER_SPACE);
vizualizationGroup.addActor(soundImageGroup);
}
......
......@@ -28,6 +28,8 @@ import cz.nic.tablexia.util.ui.button.ImageTablexiaButton;
*/
public class DoneButtonClickListener extends AbstractButtonClickListener {
private static final int NEXT_ROUND_DELAY = 2;
public DoneButtonClickListener(SafeGame safeGame) {
super(safeGame);
}
......@@ -39,7 +41,7 @@ public class DoneButtonClickListener extends AbstractButtonClickListener {
public void run() {
safeGame.evaluate();
}
}), Actions.delay(2), Actions.run(new Runnable() {
}), Actions.delay(NEXT_ROUND_DELAY), Actions.run(new Runnable() {
@Override
public void run() {
firstClickedButton.set(null);
......
......@@ -18,6 +18,10 @@
package cz.nic.tablexia.game.games.safe.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import cz.nic.tablexia.game.difficulty.GameDifficulty;
import cz.nic.tablexia.game.games.safe.AbstractMechanics;
import cz.nic.tablexia.game.games.safe.SafeMechanicsEasy;
......@@ -30,16 +34,18 @@ import cz.nic.tablexia.util.Log;
*/
public enum SafeDifficulty {
EASY(GameDifficulty.EASY, new SafeMechanicsEasy()),
MEDIUM(GameDifficulty.MEDIUM, new SafeMechanicsMedium()),
HARD(GameDifficulty.HARD, new SafeMechanicsHard());
EASY(GameDifficulty.EASY, new SafeMechanicsEasy(), SafeEasyLevelDefinition.makeArrayOfListOfSequences()),
MEDIUM(GameDifficulty.MEDIUM, new SafeMechanicsMedium(), SafeMediumLevelDefinition.makeArrayOfListOfSequences()),
HARD(GameDifficulty.HARD, new SafeMechanicsHard(), SafeHardLevelDefinition.makeArrayOfListOfSequences());
private GameDifficulty gameDifficulty;
private AbstractMechanics mechanics;
private ArrayList<List<SafeSequence>> arrayListOfsafeSequences;
SafeDifficulty(GameDifficulty gameDifficulty, AbstractMechanics mechanics) {
SafeDifficulty(GameDifficulty gameDifficulty, AbstractMechanics mechanics, ArrayList<List<SafeSequence>> arrayListOfsafeSequences) {
this.gameDifficulty = gameDifficulty;
this.mechanics = mechanics;
this.arrayListOfsafeSequences = arrayListOfsafeSequences;
}
public GameDifficulty getGameDifficulty() {
......@@ -67,19 +73,15 @@ public enum SafeDifficulty {
* @return
*/
public static SafeSequence getGeneratedSequence(GameDifficulty gameDifficulty, int level) {
switch (getSafeDifficultyForGameDifficulty(gameDifficulty)) {
case EASY:
SafeEasyLevelDefinition easySequence = SafeEasyLevelDefinition.getSequenceForLevel(level);
return (new SafeSequence(easySequence.getSoundSequence(), easySequence.getSoundsToSequence(), easySequence.getSoundsToLights(), easySequence.getExpectedSound(), easySequence.getPlayAgainFirstXSounds()));
case MEDIUM:
SafeMediumLevelDefinition mediumSequence = SafeMediumLevelDefinition.getSequenceForLevel(level);
return (new SafeSequence(mediumSequence.getSoundSequence(), mediumSequence.getSoundsToSequence(), mediumSequence.getSoundsToLights(), mediumSequence.getExpectedSound(), mediumSequence.getPlayAgainFirstXSounds()));
case HARD:
SafeHardLevelDefinition hardSequence = SafeHardLevelDefinition.getSequenceForLevel(level);
return (new SafeSequence(hardSequence.getSoundSequence(), hardSequence.getSoundsToSequence(), hardSequence.getSoundsToLights(), hardSequence.getExpectedSound(), hardSequence.getPlayAgainFirstXSounds()));
default:
Log.err("getGeneratedSequence", "Undefined safe difficulty!");
throw new IllegalArgumentException();
Random random = new Random();
List<SafeSequence> listOfSafeSequences;
for (SafeDifficulty safeDifficulty : SafeDifficulty.values()) {
if (safeDifficulty.getGameDifficulty().equals(gameDifficulty)) {
listOfSafeSequences = safeDifficulty.arrayListOfsafeSequences.get(level);
return listOfSafeSequences.get(random.nextInt(listOfSafeSequences.size()));
}
}
Log.err("getGeneratedSequence", "Undefined safe difficulty!");
throw new IllegalArgumentException();
}
}
......@@ -24,7 +24,6 @@ import java.util.List;
import java.util.Random;
import cz.nic.tablexia.game.games.safe.gameobject.SafeSounds;
import cz.nic.tablexia.util.Log;
/**
* Created by Aneta Steimarová on 17.5.17.
......@@ -196,26 +195,25 @@ public enum SafeEasyLevelDefinition implements SafeLevelDefinition {
return listOfSequences;
}
private static List<SafeSequence> makeListOfSequences(List<SafeEasyLevelDefinition> possibilitiesList) {
List<SafeSequence> listOfSequences = new ArrayList<>();
for (SafeEasyLevelDefinition easySequence : possibilitiesList) {
listOfSequences.add(new SafeSequence(easySequence.getSoundSequence(), easySequence.getSoundsToSequence(), easySequence.getSoundsToLights(), easySequence.getExpectedSound(), easySequence.getPlayAgainFirstXSounds()));
}
return listOfSequences;
}
/**
* Choose random sequence from SafeEasyLevelDefinition for specified round
* Make list of sound sequences from SafeEasyLevelDefinition for whole levels
*
* @param level = actual round
* @return chosen sound sequence for specified level
* @return list of sound sequence for for whole levels
*/
public static SafeEasyLevelDefinition getSequenceForLevel(int level) {
Random random = new Random();
switch (level) {
case 0:
return getSequencesForFirstLevel().get(random.nextInt(getSequencesForFirstLevel().size()));
case 1:
return getSequencesForSecondLevel().get(random.nextInt(getSequencesForSecondLevel().size()));
case 2:
return getSequencesForThirdLevel().get(random.nextInt(getSequencesForThirdLevel().size()));
case 3:
return getSequencesForFourthLevel().get(random.nextInt(getSequencesForFourthLevel().size()));
default:
Log.err("getSequenceForLevel", "Undefined level!");
return null;
}
public static ArrayList<List<SafeSequence>> makeArrayOfListOfSequences() {
ArrayList<List<SafeSequence>> arrayOfListOfSequences = new ArrayList<List<SafeSequence>>();
arrayOfListOfSequences.add(makeListOfSequences(getSequencesForFirstLevel()));
arrayOfListOfSequences.add(makeListOfSequences(getSequencesForSecondLevel()));
arrayOfListOfSequences.add(makeListOfSequences(getSequencesForThirdLevel()));
arrayOfListOfSequences.add(makeListOfSequences(getSequencesForFourthLevel()));
return arrayOfListOfSequences;
}
}
/*
* Copyright (C) 2017 CZ.NIC, z.s.p.o. (http://www.nic.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.safe.model;
import cz.nic.tablexia.game.AbstractTablexiaGame;
import cz.nic.tablexia.game.games.safe.assets.SafeAssets;
/**
* Created by Aneta Steimarová on 13.2.18.
*/
public enum SafeGameResultStars {
NO(AbstractTablexiaGame.GameResult.NO_STAR, SafeAssets.SCORE_0_TEXT, SafeAssets.SCORE_0_SOUND),
ONE(AbstractTablexiaGame.GameResult.ONE_STAR, SafeAssets.SCORE_1_TEXT, SafeAssets.SCORE_1_SOUND),
TWO(AbstractTablexiaGame.GameResult.TWO_STAR, SafeAssets.SCORE_2_TEXT, SafeAssets.SCORE_2_SOUND),
THREE(AbstractTablexiaGame.GameResult.THREE_STAR, SafeAssets.SCORE_3_TEXT, SafeAssets.SCORE_3_SOUND);
private AbstractTablexiaGame.GameResult gameResult;
private String text;
private String sound;
SafeGameResultStars(AbstractTablexiaGame.GameResult gameResult, String text, String sound) {
this.gameResult = gameResult;
this.text = text;
this.sound = sound;
}
public static String getTextForGameResult(AbstractTablexiaGame.GameResult gameResult) throws IllegalArgumentException {
for (SafeGameResultStars safeGameResultStars : SafeGameResultStars.values()) {
if (safeGameResultStars.gameResult == gameResult) {
return safeGameResultStars.text;
}
}
throw new IllegalArgumentException();
}
public static String getSoundForGameResult(AbstractTablexiaGame.GameResult gameResult) throws IllegalArgumentException {
for (SafeGameResultStars safeGameResultStars : SafeGameResultStars.values()) {
if (safeGameResultStars.gameResult == gameResult) {
return safeGameResultStars.sound;
}
}
throw new IllegalArgumentException();
}
}
......@@ -20,10 +20,8 @@ package cz.nic.tablexia.game.games.safe.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import cz.nic.tablexia.game.games.safe.gameobject.SafeSounds;
import cz.nic.tablexia.util.Log;
/**
* Created by Aneta Steimarová on 1.6.17.
......@@ -151,21 +149,25 @@ public enum SafeHardLevelDefinition implements SafeLevelDefinition {
return listOfSequences;
}
public static SafeHardLevelDefinition getSequenceForLevel(int level) {
Random random = new Random();
switch (level) {
case 0:
return getSequencesForFirstLevel().get(random.nextInt(getSequencesForFirstLevel().size()));
case 1:
return getSequencesForSecondLevel().get(random.nextInt(getSequencesForSecondLevel().size()));
case 2:
return getSequencesForThirdLevel().get(random.nextInt(getSequencesForThirdLevel().size()));
case 3:
return getSequencesForFourthLevel().get(random.nextInt(getSequencesForFourthLevel().size()));
default:
Log.err("getSequenceForLevel", "Undefined level!");
return null;
private static List<SafeSequence> makeListOfSequences(List<SafeHardLevelDefinition> possibilitiesList) {
List<SafeSequence> listOfSequences = new ArrayList<>();
for (SafeHardLevelDefinition easySequence : possibilitiesList) {
listOfSequences.add(new SafeSequence(easySequence.getSoundSequence(), easySequence.getSoundsToSequence(), easySequence.getSoundsToLights(), easySequence.getExpectedSound(), easySequence.getPlayAgainFirstXSounds()));
}
return listOfSequences;
}
/**
* Make list of sound sequences from SafeHardLevelDefinition for whole levels
*
* @return list of sound sequence for for whole levels
*/
public static ArrayList<List<SafeSequence>> makeArrayOfListOfSequences() {
ArrayList<List<SafeSequence>> arrayOfListOfSequences = new ArrayList<List<SafeSequence>>();
arrayOfListOfSequences.add(makeListOfSequences(getSequencesForFirstLevel()));
arrayOfListOfSequences.add(makeListOfSequences(getSequencesForSecondLevel()));
arrayOfListOfSequences.add(makeListOfSequences(getSequencesForThirdLevel()));
arrayOfListOfSequences.add(makeListOfSequences(getSequencesForFourthLevel()));
return arrayOfListOfSequences;
}
}
......@@ -20,10 +20,8 @@ package cz.nic.tablexia.game.games.safe.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import cz.nic.tablexia.game.games.safe.gameobject.SafeSounds;
import cz.nic.tablexia.util.Log;
/**
* Created by Aneta Steimarová on 1.6.17.
......@@ -171,21 +169,25 @@ public enum SafeMediumLevelDefinition implements SafeLevelDefinition {
return listOfSequences;
}
public static SafeMediumLevelDefinition getSequenceForLevel(int level) {
Random random = new Random();
switch (level) {
case 0:
return getSequencesForFirstLevel().get(random.nextInt(getSequencesForFirstLevel().size()));
case 1:
return getSequencesForSecondLevel().get(random.nextInt(getSequencesForSecondLevel().size()));
case 2:
return getSequencesForThirdLevel().get(random.nextInt(getSequencesForThirdLevel().size()));
case 3:
return getSequencesForFourthLevel().get(random.nextInt(getSequencesForFourthLevel().size()));
default:
Log.err("getSequenceForLevel", "Undefined level!");
return null;
private static List<SafeSequence> makeListOfSequences(List<SafeMediumLevelDefinition> possibilitiesList) {
List<SafeSequence> listOfSequences = new ArrayList<>();
for (SafeMediumLevelDefinition easySequence : possibilitiesList) {
listOfSequences.add(new SafeSequence(easySequence.getSoundSequence(), easySequence.getSoundsToSequence(), easySequence.getSoundsToLights(), easySequence.getExpectedSound(), easySequence.getPlayAgainFirstXSounds()));
}
return listOfSequences;
}
/**
* Make list of sound sequences from SafeMediumLevelDefinition for whole levels
*
* @return list of sound sequence for for whole levels
*/
public static ArrayList<List<SafeSequence>> makeArrayOfListOfSequences() {
ArrayList<List<SafeSequence>> arrayOfListOfSequences = new ArrayList<List<SafeSequence>>();
arrayOfListOfSequences.add(makeListOfSequences(getSequencesForFirstLevel()));
arrayOfListOfSequences.add(makeListOfSequences(getSequencesForSecondLevel()));
arrayOfListOfSequences.add(makeListOfSequences(getSequencesForThirdLevel()));
arrayOfListOfSequences.add(makeListOfSequences(getSequencesForFourthLevel()));
return arrayOfListOfSequences;
}
}
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