[vc_section css=”.vc_custom_1617918856380{margin-top: 0px !important;margin-right: 50px !important;margin-left: 50px !important;}”][vc_row][vc_column css=”.vc_custom_1617915222310{margin-bottom: 40px !important;}”][vc_single_image image=”3286″ img_size=”large” alignment=”center” css_animation=”bounceIn”][/vc_column][/vc_row][vc_row][vc_column width=”1/2″][vc_column_text css=”.vc_custom_1617918784068{margin-right: 20px !important;}”]

Take to the high seas, visit islands and code your robot to dig for buried treasure – but watch out, you’re not alone!

This is the story of Cody, a pirate robot in the quest for golden treasures. We will follow Cody from one island to another and we will be an active partner during the adventure.[/vc_column_text][vc_column_text css_animation=”fadeIn” css=”.vc_custom_1617918802844{margin-top: 20px !important;}”]

Objective

You are going to learn how to write real algorithms that solve challenges. At each challenge, you need to find the correct sequence of actions that lead Cody to find a treasure. The code editor is on the left-hand side. The Play button in the middle will make Cody execute the code, step by step.

The following topics will be covered all along the adventure.

  • Sequence of actions
  • Loops (repeat, while)
  • Defining and calling methods
  • Variables
  • Conditionals
  • … And more advanced topics

[/vc_column_text][/vc_column][vc_column width=”1/2″][vc_single_image image=”3314″ img_size=”large” alignment=”center” css_animation=”fadeIn”][/vc_column][/vc_row][vc_row][vc_column][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Basic actions

We need to help Cody by writing the needed sequence of actions to get the treasure.

The code editor is on the left side. The Play button in the middle will make Cody start the introduced instructions.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3325″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Walking

For example, right(2) means to take two steps to the right. The steps can be easily measured through the grid shown in the island.

right(2) in the following island will make Cody to arrive to the treasure position.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3330″ img_size=”medium” css_animation=”fadeIn”][vc_empty_space height=”64px”][/vc_column_inner][/vc_row_inner][vc_message icon_fontawesome=”fa fa-exclamation-circle” css_animation=”fadeInUp”]right() does not mean to make Cody turn right, not left() to turn left. Go right is from the view of the person who plays.[/vc_message][vc_row_inner][vc_column_inner][vc_column_text]

The level is restarted if …

[/vc_column_text][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_hoverbox image=”3344″ primary_title=”” primary_align=”right” hover_title=”” hover_background_color=”white” el_width=”50″ css_animation=”fadeIn”]

Cody falls into the water

[/vc_hoverbox][/vc_column_inner][vc_column_inner width=”1/2″][vc_hoverbox image=”3346″ primary_title=”” primary_align=”left” hover_title=”” hover_background_color=”white” el_width=”50″ css_animation=”fadeIn”]

Cody walk close to an skeleton without fighting

[/vc_hoverbox][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text css=”.vc_custom_1617919880829{margin-right: 20px !important;}”]Cody will not advance if there are blocking objects such as bushes, palm trees or barrels.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3187″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Fight

To destroy an enemy, Cody should be one step close to the enemy and then fight(). That means that Cody should not try to go to the exact position of an enemy but one step less and fight().[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3190″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text css=”.vc_custom_1617919866553{margin-right: 20px !important;}”]The direction is not important. For example, Cody can go up() and then fight() an enemy which is on its right.

Cody can only beat one enemy at a time. If there are several enemies around the position of Cody, Cody will beat one but the other one will attack and the level will be restarted.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3350″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Jump

Jumping is specially useful when the next step is water. This way, Cody avoid to fall in the water. In general, when Cody jumps, it advances two steps.

[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3201″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Cody needs to take a little run to jump in a direction. Otherwise, it will jump vertically and fall in the same position.

[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3203″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Blocking objects (palm trees or bushes) cannot be jumped.

[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3206″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_empty_space height=”64px”][vc_message icon_fontawesome=”fa fa-exclamation-circle” css_animation=”fadeInUp”]Cody will lose the little run if blocked. [/vc_message][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]Cody cannot attack during a jump. If Cody jump() and then fight(), the fight() will happen once Cody is on the ground.

Skeletons will attack while Cody is jumping if Cody is close to them. The level will be restarted.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3208″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Teleporters

Teleporters come in pairs which are distinguishable by the color. If Cody is in the teleporter position (walking or while jumping) it will appear in the counterpart teleporter and it will be dropped one step further of its previous direction.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3353″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]If Cody jumps in the position of a teleporter, the jump will happen after it landed at the other side. The little run is kept in the current direction.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3355″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]Teleporter pairs can be chained.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3357″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]Teleporter pairs can be chained.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3357″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]Skeletons will attack if Cody appear in one teleporter.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3359″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]If there is a blocking element in the landing place. Cody will come back inside the teleporter in the opposite direction.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3364″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Push Button

Buttons serve to activate or deactivate a set of mechanisms associated with the color of the button. pushButton outside of a button position has no side effect.

 

 

[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3230″ img_size=”medium” css_animation=”fadeIn”][vc_empty_space][/vc_column_inner][/vc_row_inner][vc_message icon_fontawesome=”fa fa-exclamation-circle” css_animation=”fadeInUp”]For pushing a button, Cody needs to stop. Cody will lose the little run for jumping.[/vc_message][vc_row_inner][vc_column_inner][vc_column_text]

Time limit

Some levels can have time limit to solve them. However, the level can be played again and the inserted code will be kept.

The time progress is shown in the form of Voltar progressing to a treasure.[/vc_column_text][/vc_column_inner][/vc_row_inner][/vc_column][/vc_row][vc_row][vc_column][vc_column_text css=”.vc_custom_1618088749523{margin-top: 20px !important;}”]

Play language

[/vc_column_text][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Procedures

The play language (the one that Cody understands) is a case-sensitive procedural programming language.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]The main procedure, the entry point to start the actions, is always :[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3235″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]In the same way, we can define other procedures to be reused by calling them as many times as we want.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3237″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]We can use any name for the procedure (no whitespaces nor special characters) and names cannot be repeated if they take the same number of parameters.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Variables

The play language only allows numeric variables.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][/vc_column_inner][/vc_row_inner][vc_empty_space][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text css=”.vc_custom_1617919222661{margin-right: 20px !important;}”]For example, in the following code, we declare the variable x and we assign it the value of 2. This way, we can use x in the actions. In the example, to take 2 steps to the right.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3239″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text css=”.vc_custom_1617919207775{margin-right: 20px !important;}”]The value of x can change during the execution of the program. By adding x = x + 1 we are saying that the new value of x is the previous value of x (it was 2) plus 1. That means that in the following code, Cody will go right 2 steps and then 3 steps up.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3241″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Parameters

The basic actions already have parameters. For example, in the following action 2 is the parameter that we use in this call to the right action.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3243″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]We can declare our own procedures with parameters. This procedure will make Cody to go x steps to the right and x up.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3245″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text css=”.vc_custom_1617918159604{margin-right: 20px !important;}”]This way we can call this procedure with different values. In the following code we will make Cody to go 3 steps right and 3 up, and then 5 steps right and 5 up.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3247″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]We can also declare a procedure with as much input parameters as we want.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3249″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text css=”.vc_custom_1617918172716{margin-right: 20px !important;}”]

Loops: Repeat

The play language allows to write loops for repeating a sequence of actions. The language has two kinds of loops: repeats and whiles.

The following code will make to repeat 5 times the sequence of going right and then up.

The 5 can be replaced with other number or with a variable. If it was a variable and you change its value inside the repeat, it will have no effect in the number of times that it will be repeated. The number of times to repeat will be the first value it got when calling the repeat.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3251″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text css=”.vc_custom_1617918189012{margin-right: 20px !important;}”]

Loops: While

Compared to the repeat loop, when using a while loop, we have more control for when to finish the loop. A condition (a boolean true or false value) will be checked after the end of each repetition to decide if the loop will continue or not.

The following code shows a variable declaration and then a while where the variable is incremented by one in each iteration. The loop will repeat the sequence of actions 5 times because when x will get the value of 6, the condition will be false.[/vc_column_text][vc_empty_space][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3253″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/4″][vc_column_text]The value of x, can be used inside the actions of the loop. In the previous example, if we have right(x) inside the loop, the first iteration will go right one step, then 2 in the 2nd iteration, 3 in the 3rd and so on.[/vc_column_text][/vc_column_inner][vc_column_inner width=”3/4″][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Conditionals

Conditions allow to execute one sequence of actions or not.[/vc_column_text][vc_empty_space][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3255″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/4″][vc_column_text]The value of x, can be used inside the actions of the loop. In the previous example, if we have right(x) inside the loop, the first iteration will go right one step, then 2 in the 2nd iteration, 3 in the 3rd and so on.[/vc_column_text][vc_empty_space][/vc_column_inner][vc_column_inner width=”3/4″][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/4″][vc_column_text]

Variables scope

The scope of a variable defines when we can make use of a variable.

The play language has:

  • Global variables
  • Procedure variables
  • Block variables (inside a loop or if)

[/vc_column_text][vc_empty_space][/vc_column_inner][vc_column_inner width=”3/4″][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Recursion

When you define a procedure that, inside the procedure, we call the same procedure, we have a case of recursion.[/vc_column_text][vc_empty_space][vc_column_text]To avoid infinite recursion we should include a stop condition that will make the procedure not to call itself again.[/vc_column_text][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3257″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_empty_space height=”64px”][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]

Operators

[/vc_column_text][vc_empty_space][vc_tta_tabs][vc_tta_section title=”Numerical operators” tab_id=”1549029508718-570f015d-ff78″][vc_column_text]The following math operators can be applied to numerical values and variables.

Addition

 Subtraction or negative number

Multiplication

Division

Remainder, modulo[/vc_column_text][/vc_tta_section][vc_tta_section title=”Boolean operators” tab_id=”1549029508845-630f6f71-d479″][vc_column_text]The following Boolean operators can be applied in conditionals (ifs, or whiles)

Between numerical values:

== Equal

!= Not equal

< Less than

<= Less than or equal

>= Greater or equal

Greater[/vc_column_text][/vc_tta_section][vc_tta_section title=”Operators for Booleans” tab_id=”1549029638039-e3e2bf3d-1bf6″][vc_column_text]and  the and operator

or the or operator

not negation of a Boolean value[/vc_column_text][/vc_tta_section][/vc_tta_tabs][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Procedure overloading

We can declare the same procedure name with different number of parameters. For example, these three procedures can coexist in the same program.[/vc_column_text][vc_empty_space][/vc_column_inner][vc_column_inner width=”1/2″][vc_single_image image=”3259″ img_size=”medium” css_animation=”fadeIn”][vc_empty_space][vc_single_image image=”3261″ img_size=”medium” css_animation=”fadeIn”][vc_empty_space][vc_single_image image=”3263″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_empty_space height=”64px”][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]

Characters

[/vc_column_text][vc_row_inner][vc_column_inner width=”1/3″][vc_column_text]

Cody

A pirate robot that wants to find treasures.

[/vc_column_text][vc_single_image image=”3265″ img_size=”medium” alignment=”center” css_animation=”fadeIn”][/vc_column_inner][vc_column_inner width=”1/3″][vc_column_text]

Chipset

A robotic parrot that always follows Cody. Chipset has the information of the treasure maps.

[/vc_column_text][vc_single_image image=”3267″ img_size=”medium” alignment=”center” css_animation=”fadeIn”][/vc_column_inner][vc_column_inner width=”1/3″][vc_column_text]

Luna

A mechanic pirate that helps Cody by providing tips and tricks for solving the levels.

[/vc_column_text][vc_single_image image=”3273″ img_size=”medium” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][vc_row_inner][vc_column_inner width=”1/2″][vc_column_text]

Skeleton

A pirate that will attack if Cody is around.

[/vc_column_text][vc_single_image image=”3280″ img_size=”medium” alignment=”center” css_animation=”fadeIn”][/vc_column_inner][vc_column_inner width=”1/2″][vc_column_text]

Voltar

Half-human and half-robot, Voltar tries also to get the treasures from the islands. Cody needs to be faster than Voltar to get the treasure in some levels.

[/vc_column_text][vc_single_image image=”3282″ img_size=”medium” alignment=”center” css_animation=”fadeIn”][/vc_column_inner][/vc_row_inner][/vc_column][/vc_row][/vc_section]