Skip to content

Commit 07afbf4

Browse files
authored
Merge pull request #911 from pitbull51067/Background
Background
2 parents 7319d2a + 983447d commit 07afbf4

File tree

9 files changed

+314
-71
lines changed

9 files changed

+314
-71
lines changed

src/main/java/edu/rpi/legup/puzzle/fillapix/FillapixCellType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ public enum FillapixCellType {
1414
public String toString() {
1515
return super.toString().toLowerCase();
1616
}
17-
}
17+
}

src/main/java/edu/rpi/legup/ui/ScrollView.java

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -134,39 +134,28 @@ public void updatePosition(Point point, double magnification) {
134134
* @param point position to zoom in on
135135
*/
136136
public void zoom(int n, Point point) {
137-
// if no Point is given, keep current center
138137
if (point == null) {
139-
point =
140-
new Point(
141-
viewport.getWidth() / 2 + viewport.getX(),
142-
viewport.getHeight() / 2 + viewport.getY());
138+
point = new Point(
139+
viewport.getWidth() / 2 + viewport.getX(),
140+
viewport.getHeight() / 2 + viewport.getY());
143141
}
144-
// magnification level
145-
double mag = (double) n * 1.05;
146-
// zoom in
147-
if (n < 0) {
148-
mag = -mag;
149-
// check zoom bounds
150-
if (scale * mag > maxScale) {
151-
mag = maxScale / scale;
152-
}
153-
// update
154-
scale *= mag;
155-
updateSize();
156-
updatePosition(point, mag);
157-
// zoom out
158-
} else {
159-
mag = 1 / mag;
160-
// check zoom bounds
161-
if (scale * mag < minScale) {
162-
mag = minScale / scale;
163-
}
164-
// update
165-
scale *= mag;
166-
updatePosition(point, mag);
167-
updateSize();
142+
143+
double zoomFactor = Math.pow(1.02, -n); // smaller step = smoother
144+
double newScale = scale * zoomFactor;
145+
146+
// Clamp to min/max
147+
newScale = Math.max(minScale, Math.min(maxScale, newScale));
148+
149+
// If change is negligible, ignore
150+
if (Math.abs(newScale - scale) < 0.001) {
151+
return;
168152
}
169-
// update the scrollpane and subclass
153+
154+
double mag = newScale / scale;
155+
scale = newScale;
156+
157+
updateSize();
158+
updatePosition(point, mag);
170159
revalidate();
171160
}
172161

src/main/java/edu/rpi/legup/ui/boardview/GridBoardView.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import edu.rpi.legup.controller.ElementController;
55
import java.awt.Color;
66
import java.awt.Dimension;
7+
import javax.swing.UIManager;
78

89
/**
910
* A view class for a grid-based board that displays elements in a grid layout. This class extends
@@ -39,7 +40,7 @@ public GridBoardView(
3940
*/
4041
private GridBoardView(BoardController boardController, ElementController elementController) {
4142
super(boardController, elementController);
42-
setBackground(new Color(0xE0E0E0));
43+
setBackground(UIManager.getColor("Panel.background"));
4344
}
4445

4546
/**
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package puzzles.fillapix.rules;
2+
3+
import edu.rpi.legup.model.tree.TreeNode;
4+
import edu.rpi.legup.model.tree.TreeTransition;
5+
import edu.rpi.legup.puzzle.fillapix.*;
6+
import edu.rpi.legup.puzzle.fillapix.rules.FinishWithBlackDirectRule;
7+
import edu.rpi.legup.puzzle.fillapix.Fillapix;
8+
import edu.rpi.legup.save.InvalidFileFormatException;
9+
import java.awt.*;
10+
import legup.MockGameBoardFacade;
11+
import legup.TestUtilities;
12+
import org.junit.Assert;
13+
import org.junit.BeforeClass;
14+
import org.junit.Test;
15+
16+
public class FinishWithBlackDirectRuleTest{
17+
private static final FinishWithBlackDirectRule RULE =
18+
new FinishWithBlackDirectRule();
19+
private static Fillapix fillapix;
20+
21+
@BeforeClass
22+
public static void setUp() {
23+
fillapix = new Fillapix();
24+
}
25+
26+
@Test
27+
public void FinishSides() throws InvalidFileFormatException {
28+
TestUtilities.importTestBoard(
29+
"puzzles/fillapix/rules/FinishWithBlackDirectRule/FinishSides.txt", fillapix);
30+
TreeNode rootNode = fillapix.getTree().getRootNode();
31+
TreeTransition transition = rootNode.getChildren().get(0);
32+
transition.setRule(RULE);
33+
// get board state
34+
FillapixBoard board = (FillapixBoard) transition.getBoard();
35+
36+
// change the board's cells considering the TouchingSides rule
37+
//(3 black cells to the left of 6 and 3 white cells to the right of 3)
38+
FillapixCell cell1 = board.getCell(0, 0);
39+
cell1.setData(FillapixCellType.WHITE.value);
40+
board.addModifiedData(cell1);
41+
42+
FillapixCell cell2 = board.getCell(0, 1);
43+
cell2.setData(FillapixCellType.WHITE.value);
44+
board.addModifiedData(cell2);
45+
46+
FillapixCell cell3 = board.getCell(0, 2);
47+
cell3.setData(FillapixCellType.WHITE.value);
48+
board.addModifiedData(cell3);
49+
50+
FillapixCell cell4 = board.getCell(1, 0);
51+
cell4.setData(FillapixCellType.BLACK.value);
52+
board.addModifiedData(cell4);
53+
54+
FillapixCell cell5 = board.getCell(1, 2);
55+
cell5.setData(FillapixCellType.BLACK.value);
56+
board.addModifiedData(cell5);
57+
58+
FillapixCell cell6 = board.getCell(2, 0);
59+
cell6.setData(FillapixCellType.BLACK.value);
60+
board.addModifiedData(cell6);
61+
62+
FillapixCell cell7 = board.getCell(2, 1);
63+
cell7.setData(FillapixCellType.BLACK.value);
64+
board.addModifiedData(cell7);
65+
66+
FillapixCell cell8 = board.getCell(2, 2);
67+
cell8.setData(FillapixCellType.BLACK.value);
68+
board.addModifiedData(cell8);
69+
70+
FillapixCell cell9 = board.getCell(1, 1);
71+
cell9.setData(FillapixCellType.BLACK.value);
72+
board.addModifiedData(cell4);
73+
74+
75+
// confirm there is a logical following of the TouchingSides rule
76+
Assert.assertNull(RULE.checkRule(transition));
77+
}
78+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package puzzles.fillapix.rules;
2+
3+
import edu.rpi.legup.model.tree.TreeNode;
4+
import edu.rpi.legup.model.tree.TreeTransition;
5+
6+
import edu.rpi.legup.puzzle.fillapix.rules.TouchingCornersDirectRule;
7+
import edu.rpi.legup.puzzle.fillapix.Fillapix;
8+
import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
9+
import edu.rpi.legup.puzzle.fillapix.FillapixCell;
10+
import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
11+
12+
import edu.rpi.legup.save.InvalidFileFormatException;
13+
import legup.TestUtilities;
14+
import org.junit.Assert;
15+
import org.junit.BeforeClass;
16+
import org.junit.Test;
17+
18+
public class TouchingCornersDirectRuleTest {
19+
private static final TouchingCornersDirectRule RULE =
20+
new TouchingCornersDirectRule();
21+
private static Fillapix fillapix;
22+
23+
@BeforeClass
24+
public static void setUp() {
25+
fillapix = new Fillapix();
26+
}
27+
28+
@Test
29+
public void TouchingCornersTest() throws InvalidFileFormatException {
30+
TestUtilities.importTestBoard(
31+
"puzzles/fillapix/rules/TouchingCornersDirectRule/TouchingCorners", fillapix);
32+
TreeNode rootNode = fillapix.getTree().getRootNode();
33+
TreeTransition transition = rootNode.getChildren().get(0);
34+
transition.setRule(RULE);
35+
// get board state
36+
FillapixBoard board = (FillapixBoard) transition.getBoard();
37+
38+
// change the board's cells considering the TouchingCorners rule
39+
//(black cells in the corners around a specific target cell)
40+
FillapixCell cell1 = board.getCell(0, 0);
41+
cell1.setData(FillapixCellType.BLACK.value);
42+
board.addModifiedData(cell1);
43+
44+
FillapixCell cell2 = board.getCell(0, 1);
45+
cell2.setData(FillapixCellType.BLACK.value);
46+
board.addModifiedData(cell2);
47+
48+
FillapixCell cell3 = board.getCell(0, 2);
49+
cell3.setData(FillapixCellType.BLACK.value);
50+
board.addModifiedData(cell3);
51+
52+
FillapixCell cell4 = board.getCell(1, 0);
53+
cell4.setData(FillapixCellType.BLACK.value);
54+
board.addModifiedData(cell4);
55+
56+
FillapixCell cell5 = board.getCell(2, 0);
57+
cell5.setData(FillapixCellType.BLACK.value);
58+
board.addModifiedData(cell5);
59+
60+
// confirm there is a logical following of the TouchingCorners rule
61+
Assert.assertNull(RULE.checkRule(transition));
62+
63+
// check each square except the center
64+
/*FillapixCell c;
65+
for (int i = 0; i < board.getHeight(); i++) {
66+
for (int j = 0; j < board.getWidth(); j++) {
67+
c = board.getCell(j, i);
68+
if ((i == 1 || i == 3) && (j == 1 || j == 3)) {
69+
// logically follows
70+
Assert.assertNull(RULE.checkRuleAt(transition, c));
71+
} else {
72+
// does not use the rule to logically follow
73+
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
74+
}
75+
}
76+
}
77+
*/
78+
}
79+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package puzzles.fillapix.rules;
2+
3+
import edu.rpi.legup.model.tree.TreeNode;
4+
import edu.rpi.legup.model.tree.TreeTransition;
5+
6+
import edu.rpi.legup.puzzle.fillapix.rules.TouchingSidesDirectRule;
7+
import edu.rpi.legup.puzzle.fillapix.Fillapix;
8+
import edu.rpi.legup.puzzle.fillapix.FillapixBoard;
9+
import edu.rpi.legup.puzzle.fillapix.FillapixCell;
10+
import edu.rpi.legup.puzzle.fillapix.FillapixCellType;
11+
12+
import edu.rpi.legup.save.InvalidFileFormatException;
13+
import legup.TestUtilities;
14+
import org.junit.Assert;
15+
import org.junit.BeforeClass;
16+
import org.junit.Test;
17+
18+
public class TouchingSidesDirectRuleTest {
19+
private static final TouchingSidesDirectRule RULE =
20+
new TouchingSidesDirectRule();
21+
private static Fillapix fillapix;
22+
23+
@BeforeClass
24+
public static void setUp() {
25+
fillapix = new Fillapix();
26+
}
27+
28+
@Test
29+
public void TouchingSidesTest() throws InvalidFileFormatException {
30+
TestUtilities.importTestBoard(
31+
"puzzles/fillapix/rules/TouchingSidesDirectRule/TouchingSides", fillapix);
32+
TreeNode rootNode = fillapix.getTree().getRootNode();
33+
TreeTransition transition = rootNode.getChildren().get(0);
34+
transition.setRule(RULE);
35+
// get board state
36+
FillapixBoard board = (FillapixBoard) transition.getBoard();
37+
38+
// change the board's cells considering the TouchingSides rule
39+
//(3 black cells to the left of 6 and 3 white cells to the right of 3)
40+
FillapixCell cell1 = board.getCell(0, 1);
41+
cell1.setData(FillapixCellType.BLACK.value);
42+
board.addModifiedData(cell1);
43+
44+
FillapixCell cell2 = board.getCell(0, 2);
45+
cell2.setData(FillapixCellType.BLACK.value);
46+
board.addModifiedData(cell2);
47+
48+
FillapixCell cell3 = board.getCell(0, 3);
49+
cell3.setData(FillapixCellType.BLACK.value);
50+
board.addModifiedData(cell3);
51+
52+
FillapixCell cell4 = board.getCell(3, 1);
53+
cell4.setData(FillapixCellType.WHITE.value);
54+
board.addModifiedData(cell4);
55+
56+
FillapixCell cell5 = board.getCell(3, 2);
57+
cell5.setData(FillapixCellType.WHITE.value);
58+
board.addModifiedData(cell5);
59+
60+
FillapixCell cell6 = board.getCell(3, 3);
61+
cell6.setData(FillapixCellType.WHITE.value);
62+
board.addModifiedData(cell6);
63+
64+
// confirm there is a logical following of the TouchingSides rule
65+
Assert.assertNull(RULE.checkRule(transition));
66+
67+
// check every square except the top center (2,0)
68+
/*LightUpCell c;
69+
for (int i = 0; i < board.getHeight(); i++) {
70+
for (int j = 0; j < board.getWidth(); j++) {
71+
c = board.getCell(j, i);
72+
if (i == 0 && j == 1) {
73+
// logically follows
74+
Assert.assertNull(RULE.checkRuleAt(transition, c));
75+
} else {
76+
// does not use the rule to logically follow
77+
Assert.assertNotNull(RULE.checkRuleAt(transition, c));
78+
}
79+
}
80+
}
81+
*/
82+
83+
}
84+
}

0 commit comments

Comments
 (0)