diff --git a/core/src/cz/nic/tablexia/game/games/night_watch/NightWatchGame.java b/core/src/cz/nic/tablexia/game/games/night_watch/NightWatchGame.java index b679d62c8641f94b09a6304799e63b2a4ecf63b4..c98cf572c814e9bcbd43ca16434a3800a445f397 100644 --- a/core/src/cz/nic/tablexia/game/games/night_watch/NightWatchGame.java +++ b/core/src/cz/nic/tablexia/game/games/night_watch/NightWatchGame.java @@ -38,13 +38,15 @@ public class NightWatchGame extends AbstractTablexiaGame<int[][]> { private static final int SCREEN_WIDTH = TablexiaSettings.getWorldWidth(); private static final int SCREEN_MIN_HEIGHT = TablexiaSettings.getMinWorldHeight(); private static final int INITIAL_BG_TEXTURE_INDEX = 0; + private static final float SOLUTION_VISIBLE_SECONDS = 2.0f; private int difficulty = 2; + private int points = 0; private boolean userPlaying = false; private int numberOfSelectedWindows; private Set<Integer> selectedWindows; - private int currentLevel = 1; + private int currentLevel = 0; private int currentRound; private Image backgroundImage; private Group windowsGroup; @@ -99,6 +101,7 @@ public class NightWatchGame extends AbstractTablexiaGame<int[][]> { lightUpWindow(touchedWindowIndex.intValue(), Color.YELLOW); if (numberOfSelectedWindows == maxNumberOfWindows) { button.setVisible(true); + button.setChecked(false); } } } @@ -130,10 +133,11 @@ public class NightWatchGame extends AbstractTablexiaGame<int[][]> { button.addListener(new ClickListener(){ @Override public void clicked(InputEvent event, float x, float y) { + userPlaying = false; button.setVisible(false); //disabling background so windows cannot be clicked until enableClickables(false); - addAction(evaluate()); + addAction(Actions.sequence(evaluate(),Actions.delay(SOLUTION_VISIBLE_SECONDS),resetScene(),Actions.delay(0.5f),decideWhatFollows())); } }); button.setVisible(false); @@ -177,6 +181,7 @@ public class NightWatchGame extends AbstractTablexiaGame<int[][]> { @Override public boolean act(float delta) { Log.info(getClass(),"RESET SCENE"); + selectedWindows.clear(); resetWindows(); watch.resetWatch(); return true; @@ -189,7 +194,8 @@ public class NightWatchGame extends AbstractTablexiaGame<int[][]> { Action action = new Action() { @Override public boolean act(float delta) { - Log.info(getClass(), "PLAY"); + Log.info(getClass(),"PLAY"); + userPlaying = true; enableClickables(true); return true; } @@ -207,6 +213,12 @@ public class NightWatchGame extends AbstractTablexiaGame<int[][]> { Solution correctSolution = gameSolutions.get(currentLevel).get(currentRound); boolean correct = correctSolution.check(windows,userSetTime); + if(correctSolution.checkWindows(windows)){ + points++; + } + if(correctSolution.checkTime(userSetTime)){ + points++; + } Log.info(getClass(),"CORRECT: "+correct); for (int i = 0; i < correctSolution.getWindowSequence().size(); i++) { @@ -256,7 +268,23 @@ public class NightWatchGame extends AbstractTablexiaGame<int[][]> { Action acition = new Action() { @Override public boolean act(float delta) { - Log.info(getClass(),"DECIDING.."); + int numberOfRoundsInThisLevel = GameRulesHelper.getRoundsPerLevelCount(difficulty,currentLevel); + int numberOfLevelsForCurrentDifficulty = GameRulesHelper.getNumberOfLevelsPerGame(); + currentRound++; + if(currentRound<numberOfRoundsInThisLevel){ + startRound(); + }else{ + currentLevel++; + if(currentLevel<numberOfLevelsForCurrentDifficulty){ + currentRound = 0; + startRound(); + }else{ + Log.info(this.getClass(),"Finishing..."); + int numberOfStars = GameRulesHelper.getNumberOfStarsForResult(points); + gameComplete(numberOfStars); + } + } + //TODO put code here that checks current round and progress and either animates new day or finishes game return true; } @@ -286,7 +314,12 @@ public class NightWatchGame extends AbstractTablexiaGame<int[][]> { //TODO add reset scene action here //user is playing, increment number of lid windows + int maxNumberOfWindows = GameRulesHelper.getNumberOfWindowsLightenedInCurrentRound(difficulty,currentLevel); numberOfSelectedWindows++; + if(numberOfSelectedWindows==maxNumberOfWindows && userPlaying){ + button.setVisible(true); + } + } //method enables or disables all clickables so it cannot be clicked while animating or during screen transitions diff --git a/core/src/cz/nic/tablexia/game/games/night_watch/helper/GameRulesHelper.java b/core/src/cz/nic/tablexia/game/games/night_watch/helper/GameRulesHelper.java index c4c57376cc5e1d809347c7d9d1f5d2368857c0fc..a8cabd5cb9190327c766ab7021ad93ab15c4dede 100644 --- a/core/src/cz/nic/tablexia/game/games/night_watch/helper/GameRulesHelper.java +++ b/core/src/cz/nic/tablexia/game/games/night_watch/helper/GameRulesHelper.java @@ -86,4 +86,15 @@ public class GameRulesHelper { return STARTING_LID_TIME - (timeUnit * currentRound); } + public static int getNumberOfStarsForResult(int points){ + if (points > 13) { + return 3; + } else if (points > 8) { + return 2; + } else if (points > 4) { + return 1; + } + return 0; + } + } diff --git a/core/src/cz/nic/tablexia/game/games/night_watch/solution/Solution.java b/core/src/cz/nic/tablexia/game/games/night_watch/solution/Solution.java index 7737b5c90e5b2cbdc709771f93f16e5368f3668c..d0320a841cf4e94704ee0cbf604ed93f0efc3487 100644 --- a/core/src/cz/nic/tablexia/game/games/night_watch/solution/Solution.java +++ b/core/src/cz/nic/tablexia/game/games/night_watch/solution/Solution.java @@ -25,16 +25,24 @@ public class Solution { //returns whether passed parameters fulfill this solution public boolean check(List<Integer>chosenWindows,int chosenTime){ + return checkTime(chosenTime)&&checkWindows(chosenWindows); + } + + + public boolean checkWindows(List<Integer>chosenWindows){ for(int correctWindow: windowSequence){ if(!chosenWindows.contains(correctWindow)){ return false; } } + return true; + } + + public boolean checkTime(int chosenTime){ if(chosenTime != time){ return false; } return true; - } @Override