Skip to content

Commit 9580caa

Browse files
committed
added new recipe w/@dcoopersmith
Pyramids Of Giz
1 parent 26fafbe commit 9580caa

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.teachingkidsprogramming.recipes.inDevelopment;
2+
3+
import org.teachingextensions.logo.Tortoise;
4+
// NOTE: this might need to be broken into several different recipes??
5+
// e.g. PyramidsOfGiza01, PyramidsOfGiza02, PyramidsOfGiza03, etc...
6+
// This is a very simple/basic recipe introducing passing multiple values
7+
// into methods and reinforcing basic refactoring.
8+
// This can be completed in several 'passes' or 'steps of refactoring' as follows:
9+
//
10+
// 1. entire recipe written in linear fashion with lots of repeated code
11+
// 2. a) turnAndMove() method created
12+
// b) every 2 linear turn() and move() calls are replaced by 1 call to new turnAndMove() method
13+
// 3. Now another pattern emerges, and a 3rd refactoring/abstraction takes place
14+
// when the student notices that there are several each of
15+
// turnAndMove(90, 100) & turnAndMove(-90, 100), so 2 new methods are written:
16+
// turnAndMove(90, 100) becomes -> moveDown() & turnAndMove(-90, 100) -> moveUp()
17+
// 4. At this point, students are encouraged to see if there might be any other possible patterns
18+
// to refactor
19+
20+
// Where to add? In Course 1 or Course 2 - concepts taught: refactoring
21+
public class PyramidsOfGiza
22+
{
23+
public static void main(String[] args) throws Exception
24+
{
25+
Tortoise.show();
26+
Tortoise.setSpeed(10);
27+
turnAndMove(-90, 220);
28+
// Tortoise.turn(-90);
29+
// Tortoise.move(220);
30+
turnAndMove(135, 100);
31+
// Tortoise.turn(135);
32+
// Tortoise.move(100);
33+
moveDown();
34+
// turnAndMove(90, 100);
35+
// Tortoise.turn(90);
36+
// Tortoise.move(100);
37+
moveUp();
38+
// turnAndMove(-90, 100);
39+
// Tortoise.turn(-90);
40+
// Tortoise.move(100);
41+
moveDown();
42+
// turnAndMove(90, 100);
43+
// Tortoise.turn(90);
44+
// Tortoise.move(100);
45+
moveUp();
46+
//turnAndMove(-90, 100);
47+
// Tortoise.turn(-90);
48+
// Tortoise.move(100);
49+
moveDown();
50+
// turnAndMove(90, 100);
51+
// Tortoise.turn(90);
52+
// Tortoise.move(100);
53+
Tortoise.turn(135);
54+
Tortoise.move(210);
55+
}
56+
public static void moveDown()
57+
{
58+
turnAndMove(90, 100);
59+
}
60+
public static void moveUp()
61+
{
62+
turnAndMove(-90, 100);
63+
}
64+
public static void turnAndMove(int degrees, int length)
65+
{
66+
Tortoise.turn(degrees);
67+
Tortoise.move(length);
68+
}
69+
}

0 commit comments

Comments
 (0)