Skip to content

Commit 3667537

Browse files
committed
small updates in Course08
1 parent 29362d5 commit 3667537

3 files changed

Lines changed: 25 additions & 25 deletions

File tree

src/main/java/org/teachingextensions/logo/utils/MazeUtils/Maze.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
* Generates a perfect N-by-N maze using depth-first search with a stack.
99
*
1010
* % java Maze 62
11-
*
1211
* % java Maze 61
1312
*
1413
* Note: this program generalizes nicely to finding a random tree
1514
* in a graph.
16-
*
1715
******************************************************************************/
1816
public class Maze
1917
{
@@ -46,7 +44,7 @@ private void init()
4644
visited[0][y] = true;
4745
visited[N + 1][y] = true;
4846
}
49-
// initialze all walls as present
47+
// initialize all walls as present
5048
north = new boolean[N + 2][N + 2];
5149
east = new boolean[N + 2][N + 2];
5250
south = new boolean[N + 2][N + 2];
@@ -190,7 +188,7 @@ public static void main(String[] args)
190188
// This line throws an index out bounds with any value in args ???
191189
//int N = Integer.parseInt(args[0]);
192190
//TODO: change this value to increase the complexity of the Maze
193-
int N = 10;
191+
int N = 8;
194192
Maze maze = new Maze(N);
195193
StdDraw.show(0);
196194
maze.draw();

src/main/java/org/teachingkidsprogramming/recipes/completed/section08events/TortoiseMaze.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ public static void main(String[] args)
2020
}
2121
public TortoiseMaze()
2222
{
23-
Tortoise.show();
24-
Tortoise.setSpeed(10);
25-
Tortoise.setPenColor(PenColors.Greens.Green);
26-
Tortoise.setPenWidth(4);
23+
setUpTortoise();
2724
// add image icons
2825
ImageIcon leftArrow = new ImageIcon(
2926
"../TeachingKidsProgramming.Source.Java/src/main/resources/icons/arrow-left.png");
@@ -34,16 +31,16 @@ public TortoiseMaze()
3431
ImageIcon rightArrow = new ImageIcon(
3532
"../TeachingKidsProgramming.Source.Java/src/main/resources/icons/arrow-right.png");
3633
// add buttons using icons
37-
JButton leftButton = new JButton(leftArrow);
38-
JButton upButton = new JButton(upArrow);
39-
JButton downButton = new JButton(downArrow);
40-
JButton rightButton = new JButton(rightArrow);
41-
// add buttons to your window
42-
Tortoise.getBackgroundWindow().addButton(leftButton);
43-
Tortoise.getBackgroundWindow().addButton(upButton);
44-
Tortoise.getBackgroundWindow().addButton(downButton);
45-
Tortoise.getBackgroundWindow().addButton(rightButton);
46-
// add actions to your buttons
34+
JButton leftButton = new JButton("left", leftArrow);
35+
JButton upButton = new JButton("forward", upArrow);
36+
JButton downButton = new JButton("back", downArrow);
37+
JButton rightButton = new JButton("right", rightArrow);
38+
// add button(s) to your window
39+
addButtonToWindow(leftButton);
40+
addButtonToWindow(upButton);
41+
addButtonToWindow(downButton);
42+
addButtonToWindow(rightButton);
43+
// add action(s) to your buttons
4744
rightButton.addActionListener(new ActionListener()
4845
{
4946
@Override
@@ -78,4 +75,16 @@ public void actionPerformed(ActionEvent e)
7875
});
7976
Tortoise.setVisible(true);
8077
}
78+
/* setup code */
79+
private void setUpTortoise()
80+
{
81+
Tortoise.show();
82+
Tortoise.setSpeed(10);
83+
Tortoise.setPenColor(PenColors.Greens.Green);
84+
Tortoise.setPenWidth(4);
85+
}
86+
private void addButtonToWindow(JButton button)
87+
{
88+
Tortoise.getBackgroundWindow().addButton(button);
89+
}
8190
}

src/main/java/org/teachingkidsprogramming/recipes/completed/section09final/DeepDive09.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ public void exceptionsShouldExplainAllPreconditions() throws Exception
5858
*
5959
*
6060
*
61-
*
62-
*
63-
*
64-
*
65-
*
66-
*
67-
*
6861
*/
6962
public String ___ = "You need to fill in the blank ___";
7063
public Integer ____ = -99;

0 commit comments

Comments
 (0)