Skip to content

Commit fcb8e9b

Browse files
committed
Support showing optimal number of steps
1 parent 17eb25f commit fcb8e9b

File tree

15 files changed

+54
-18
lines changed

15 files changed

+54
-18
lines changed

app/src/main/java/com/bytehamster/flowitgame/model/Level.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ public class Level {
66
private int number;
77
private int indexInPack;
88
private LevelPack pack;
9+
private int optimalSteps;
910

10-
public Level(int indexInPack, int number, LevelPack pack, String color, String modifier) {
11+
public Level(int indexInPack, int number, LevelPack pack, String color, String modifier, int optimalSteps) {
1112
this.number = number;
1213
this.indexInPack = indexInPack;
1314
this.pack = pack;
15+
this.optimalSteps = optimalSteps;
1416

1517
color = color.replaceAll("\\s", "");
1618
modifier = modifier.replaceAll("\\s", "");
@@ -74,4 +76,8 @@ public int getIndexInPack() {
7476
public LevelPack getPack() {
7577
return pack;
7678
}
79+
80+
public int getOptimalSteps() {
81+
return optimalSteps;
82+
}
7783
}

app/src/main/java/com/bytehamster/flowitgame/model/LevelPack.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ private LevelPack(int id, String fileName, Context context) {
4848
int number = Integer.parseInt(levelEl.getAttribute("number"));
4949
String colors = levelEl.getAttribute("color");
5050
String modifiers = levelEl.getAttribute("modifier");
51+
int optimalSteps = 0;
52+
if (levelEl.hasAttribute("solution")) {
53+
String solution = levelEl.getAttribute("solution");
54+
optimalSteps = solution.split(",").length;
55+
}
5156

52-
levels.add(new Level(indexInPack, number, this, colors, modifiers));
57+
levels.add(new Level(indexInPack, number, this, colors, modifiers, optimalSteps));
5358
indexInPack++;
5459
}
5560
}

app/src/main/java/com/bytehamster/flowitgame/object/LevelList.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
public class LevelList extends Drawable {
1212
private final Plane planeLevel;
1313
private final Plane planeLevelDone;
14+
private final Plane planeLevelPerfect;
1415
private final Plane planeLevelLocked;
1516
private final Number number;
1617
private final float boxHeight;
@@ -25,9 +26,11 @@ public LevelList(float boxSize, State context) {
2526

2627
TextureCoordinates coordinatesLevel = TextureCoordinates.getFromBlocks(6, 0, 7, 1);
2728
TextureCoordinates coordinatesLevelDone = TextureCoordinates.getFromBlocks(7, 0, 8, 1);
28-
TextureCoordinates coordinatesLevelLocked = TextureCoordinates.getFromBlocks(6, 3, 7, 4);
29+
TextureCoordinates coordinatesLevelPerfect = TextureCoordinates.getFromBlocks(6, 1, 7, 2);
30+
TextureCoordinates coordinatesLevelLocked = TextureCoordinates.getFromBlocks(7, 1, 8, 2);
2931
planeLevel = new Plane(0, 0, boxSize, boxSize, coordinatesLevel);
3032
planeLevelDone = new Plane(0, 0, boxSize, boxSize, coordinatesLevelDone);
33+
planeLevelPerfect = new Plane(0, 0, boxSize, boxSize, coordinatesLevelPerfect);
3134
planeLevelLocked = new Plane(0, 0, boxSize, boxSize, coordinatesLevelLocked);
3235
number = new Number();
3336
number.setFontSize(boxSize / 3);
@@ -55,7 +58,11 @@ private float getYFor(int num) {
5558
private void drawButton(int indexInPack, Level level, GL10 gl) {
5659
Plane draw;
5760
if (context.isSolved(level.getNumber())) {
58-
draw = planeLevelDone;
61+
if (level.getOptimalSteps() != 0 && context.loadSteps(level.getNumber()) <= level.getOptimalSteps()) {
62+
draw = planeLevelPerfect;
63+
} else {
64+
draw = planeLevelDone;
65+
}
5966
} else if (!context.isPlayable(level)) {
6067
draw = planeLevelLocked;
6168
} else {

app/src/main/java/com/bytehamster/flowitgame/state/GameState.java

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.bytehamster.flowitgame.R;
1010
import com.bytehamster.flowitgame.animation.Animation;
1111
import com.bytehamster.flowitgame.animation.AnimationFactory;
12-
import com.bytehamster.flowitgame.animation.AnimationRepeated;
1312
import com.bytehamster.flowitgame.animation.ScaleAnimation;
1413
import com.bytehamster.flowitgame.animation.TranslateAnimation;
1514
import com.bytehamster.flowitgame.filler.Filler;
@@ -41,6 +40,7 @@ public class GameState extends State {
4140
private Plane headerBackground;
4241
private Number stepsUsed;
4342
private Number stepsBest;
43+
private Number stepsOptimal;
4444
private boolean isFilling = false;
4545
private boolean won = false;
4646
private float topBarHeight;
@@ -49,6 +49,7 @@ public class GameState extends State {
4949
private float topBarPadding;
5050
private float stepsUsedCurrentYDelta;
5151
private float stepsUsedBestYDelta;
52+
private float stepsOptimalYDelta;
5253
private LastLevelState lastLevelState = LastLevelState.NO_LEVEL;
5354
private Filler filler;
5455

@@ -75,6 +76,7 @@ protected void initialize(GLRenderer glRenderer) {
7576
topButtonY = glRenderer.getHeight() - topButtonSize - topBarPadding;
7677
stepsUsedCurrentYDelta = topButtonSize * 0.6f;
7778
stepsUsedBestYDelta = topButtonSize * 0.1f;
79+
stepsOptimalYDelta = topButtonSize * -0.4f;
7880

7981
TextureCoordinates coordinatesHeader = TextureCoordinates.getFromBlocks(14, 12, 15, 13);
8082
headerBackground = new Plane(0, glRenderer.getHeight(), glRenderer.getWidth(), topBarHeight, coordinatesHeader);
@@ -109,19 +111,25 @@ protected void initialize(GLRenderer glRenderer) {
109111
stepsUsed = new Number();
110112
stepsUsed.setFontSize(topButtonSize * 0.35f);
111113
stepsUsed.setX(5 * topButtonSize + 3 * topBarPadding);
112-
stepsUsed.setY(glRenderer.getHeight() + topBarPadding + stepsUsedCurrentYDelta);
114+
stepsUsed.setY(glRenderer.getHeight() + topBarPadding + stepsUsedCurrentYDelta + 0.25f * topButtonSize);
113115
glRenderer.addDrawable(stepsUsed);
114116

115117
stepsBest = new Number();
116118
stepsBest.setFontSize(topButtonSize * 0.35f);
117119
stepsBest.setX(5 * topButtonSize + 3 * topBarPadding);
118-
stepsBest.setY(glRenderer.getHeight() + topBarPadding + stepsUsedBestYDelta);
120+
stepsBest.setY(glRenderer.getHeight() + topBarPadding + stepsUsedBestYDelta + 0.25f * topButtonSize);
119121
glRenderer.addDrawable(stepsBest);
120122

121-
TextureCoordinates coordinateSteps = TextureCoordinates.getFromBlocks(12, 10, 15, 11);
122-
stepsLabel = new Plane(0, 0, 3 * topButtonSize, topButtonSize, coordinateSteps);
123+
stepsOptimal = new Number();
124+
stepsOptimal.setFontSize(topButtonSize * 0.35f);
125+
stepsOptimal.setX(5 * topButtonSize + 3 * topBarPadding);
126+
stepsOptimal.setY(glRenderer.getHeight() + topBarPadding + stepsOptimalYDelta + 0.25f * topButtonSize);
127+
glRenderer.addDrawable(stepsOptimal);
128+
129+
TextureCoordinates coordinateSteps = TextureCoordinates.getFromBlocks(12, 10, 15, 12);
130+
stepsLabel = new Plane(0, 0, 3 * topButtonSize, 2 * topButtonSize, coordinateSteps);
123131
stepsLabel.setX(2 * topButtonSize + 3 * topBarPadding);
124-
stepsLabel.setY(glRenderer.getHeight() + topBarPadding);
132+
stepsLabel.setY(glRenderer.getHeight() + topBarPadding - 0.75f * topButtonSize);
125133
stepsLabel.setVisible(false);
126134
glRenderer.addDrawable(stepsLabel);
127135

@@ -160,9 +168,10 @@ public void entry() {
160168
AnimationFactory.startMoveYTo(left, topButtonY);
161169
AnimationFactory.startMoveYTo(right, topButtonY);
162170
AnimationFactory.startMoveYTo(restart, topButtonY);
163-
AnimationFactory.startMoveYTo(stepsLabel, topButtonY);
164-
AnimationFactory.startMoveYTo(stepsBest, topButtonY + stepsUsedBestYDelta);
165-
AnimationFactory.startMoveYTo(stepsUsed, topButtonY + stepsUsedCurrentYDelta);
171+
AnimationFactory.startMoveYTo(stepsLabel, topButtonY - 0.75f * topButtonSize);
172+
AnimationFactory.startMoveYTo(stepsBest, topButtonY + stepsUsedBestYDelta + 0.25f * topButtonSize);
173+
AnimationFactory.startMoveYTo(stepsUsed, topButtonY + stepsUsedCurrentYDelta + 0.25f * topButtonSize);
174+
AnimationFactory.startMoveYTo(stepsOptimal, topButtonY + stepsOptimalYDelta + 0.25f * topButtonSize);
166175
AnimationFactory.startMoveYTo(headerBackground, getScreenHeight() - topBarHeight);
167176
}
168177

@@ -174,6 +183,11 @@ private void reloadLevel() {
174183
} else {
175184
stepsBest.setValue(loadSteps(level.getNumber()));
176185
}
186+
if (level.getOptimalSteps() <= 0) {
187+
stepsOptimal.setValue(Number.VALUE_NAN);
188+
} else {
189+
stepsOptimal.setValue(level.getOptimalSteps());
190+
}
177191
AnimationFactory.startScaleHide(stepsImproved, 0);
178192
isFilling = false;
179193
level.reset();
@@ -261,9 +275,13 @@ public void exit() {
261275
AnimationFactory.startMoveYTo(right, getScreenHeight() + topBarPadding);
262276
AnimationFactory.startMoveYTo(restart, getScreenHeight() + topBarPadding);
263277
AnimationFactory.startMoveYTo(solved, getScreenHeight() + topBarPadding);
264-
AnimationFactory.startMoveYTo(stepsLabel, getScreenHeight() + topBarPadding);
265-
AnimationFactory.startMoveYTo(stepsBest, getScreenHeight() + topBarPadding + stepsUsedBestYDelta);
266-
AnimationFactory.startMoveYTo(stepsUsed, getScreenHeight() + topBarPadding + stepsUsedCurrentYDelta);
278+
AnimationFactory.startMoveYTo(stepsLabel, getScreenHeight() + topBarPadding - 0.75f * topButtonSize);
279+
AnimationFactory.startMoveYTo(stepsBest, getScreenHeight() + topBarPadding
280+
+ stepsUsedBestYDelta + 0.25f * topButtonSize);
281+
AnimationFactory.startMoveYTo(stepsUsed, getScreenHeight() + topBarPadding
282+
+ stepsUsedCurrentYDelta + 0.25f * topButtonSize);
283+
AnimationFactory.startMoveYTo(stepsOptimal, getScreenHeight() + topBarPadding
284+
+ stepsOptimalYDelta + 0.25f * topButtonSize);
267285
AnimationFactory.startMoveYTo(headerBackground, getScreenHeight());
268286
AnimationFactory.startMoveYTo(winMessage, -getScreenWidth() * 0.5f);
269287
AnimationFactory.startScaleHide(stepsImproved, 0);

app/src/main/java/com/bytehamster/flowitgame/state/State.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void saveSteps(int level, int steps) {
6767
}
6868
}
6969

70-
int loadSteps(int level) {
70+
public int loadSteps(int level) {
7171
return playedPrefs.getInt("s"+level, STEPS_NOT_SOLVED);
7272
}
7373

8.59 KB
Loading
8.62 KB
Loading
8.13 KB
Loading
8.53 KB
Loading

0 commit comments

Comments
 (0)