-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHurdleKarel.js
64 lines (59 loc) · 1.09 KB
/
HurdleKarel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* This program has karel jump over two
* hurdles and then move all of the way
* to the edge of the world.
*/
function start(){
// Karel jumps two hurdles in this
// program.
runToHurdle();
jumpHurdle();
runToHurdle();
jumpHurdle();
runToFinish();
}
/*
* Precondition: Karel has just jumped the
* last hurdle, and is facing east.
* Postcondition: Karel is all of the way
* at the end of the world.
*/
function runToFinish(){
move();
move();
move();
move();
}
/*
* Precondition: Karel is facing east, three
* spots away from a hurdle.
* Postcondition: Karel is standing right in * front of a hurdle.
*/
function runToHurdle(){
move();
move();
move();
}
/*
* This function has karel jump over a
* hurdle that is one row high.
* Precondition: Karel is standing in front
* of a hurdle, facing east.
* Postcondition: Karel has just jumped over
* a hurdle, and is facing east.
*/
function jumpHurdle(){
turnLeft();
move();
turnRight();
move();
turnRight();
move();
turnLeft();
}
/* This function has karel turn right. */
function turnRight(){
turnLeft();
turnLeft();
turnLeft();
}