SOLUTION TASK 1.01: First Steps
class MyPlayer extends Player { start() { move(); putStar(); move(); } }
SOLUTION TASK 1.02: World Design
class MyPlayer extends Player { start() { move(); putStar(); move(); } } main() { character = 'catgirl'; field = 'stone'; createWorld('scenario.txt', MyPlayer()); }
SOLUTION TASK 1.03 Around Tree
class MyPlayer extends Player { start() { move(); turnLeft(); move(); turnRight(); move(); move(); turnRight(); move(); turnLeft(); turnLeft(); move(); turnRight(); move(); move(); turnRight(); move(); turnLeft(); move(); turnLeft(); move(); turnRight(); move(); move(); turnRight(); move(); turnLeft(); removeStar(); } }
Explanations
The comments in the source code have been omitted (that is the text that is displayed in green in the Editor).
Comments in the source code are written for additional information. Comments are intended only for humans and are ignored by the computer. There are several ways to write comments in the source code:
- Simple comments with a double slash
//
(everything between the slashes and the end of line is a comment). - Comments for functions and classes are written with a tripple slash
///
. - (Rarely used) Longer comments over multiple lines that start with
/*
and end with*/
.
SOLUTION TASK 1.04: Around Tree with Function
class MyPlayer extends Player { start() { move(); goAroundTree(); goAroundTree(); move(); goAroundTree(); removeStar(); } goAroundTree() { turnLeft(); move(); turnRight(); move(); move(); turnRight(); move(); turnLeft(); } }
Explanations
- For a better overview and to avoid that we have to write the same code three times, we have introduced a new function called
goAroundTree()
. - After each function is a set of parentheses
()
, which means that no parameters are passed to this function. Later we will learn about functions with parameters.