Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rename v to my_van #1327

Merged
merged 9 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions game/end_to_end_tests/game_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ def run_undefined_procedure_program(self):

def run_parse_error_program(self):
return self._run_failing_python_program_console(
"v.", "ParseError: bad input on line"
"my_van.", "ParseError: bad input on line"
)

def run_attribute_error_program(self):
return self._run_failing_python_program_console(
"v.go()", "AttributeError: 'Van' object has no attribute"
"my_van.go()", "AttributeError: 'Van' object has no attribute"
)

def run_print_program(self):
Expand All @@ -181,7 +181,7 @@ def check_python_commands(self):
return self

def write_to_then_clear_console(self):
self._write_code("v.")
self._write_code("my_van.")
self.browser.find_element_by_id("fast_tab").click()
time.sleep(1)
console = self.browser.find_element_by_id("consoleOutput")
Expand Down
42 changes: 21 additions & 21 deletions game/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2012,8 +2012,8 @@ def description_level92():

def hint_level92():
return (
"Try using the following commands:<br><pre>v.move_forwards()<br>v.turn_left()"
"<br>v.turn_right()</pre>"
"Try using the following commands:<br><pre>my_van.move_forwards()<br>my_van.turn_left()"
"<br>my_van.turn_right()</pre>"
+ PYTHON_HINT
)

Expand All @@ -2033,9 +2033,9 @@ def description_level93():
def hint_level93():
return (
"""Try using the following commands:
<pre>v.move_forwards()
v.turn_left()
v.turn_right()</pre>"""
<pre>my_van.move_forwards()
my_van.turn_left()
my_van.turn_right()</pre>"""
+ PYTHON_HINT
)

Expand All @@ -2055,9 +2055,9 @@ def description_level94():
def hint_level94():
return (
"""Try using the following commands:
<pre>v.move_forwards()
v.turn_left()
v.turn_right()</pre>"""
<pre>my_van.move_forwards()
my_van.turn_left()
my_van.turn_right()</pre>"""
+ PYTHON_HINT
)

Expand All @@ -2078,7 +2078,7 @@ def hint_level95():
return (
"""To repeat some statements a set number of times you can use something like the following:
<pre>for count in range(3):
v.turn left
my_van.turn left
print count</pre>
The print statement will output the value of count to the console."""
+ PYTHON_HINT
Expand All @@ -2102,7 +2102,7 @@ def hint_level96():
return (
"""To repeat some statements a set number of times you can use something like the following:
<pre>for count in range(3):
v.turn left
my_van.turn left
print count</pre>
The print statement will output the value of count to the console."""
+ PYTHON_HINT
Expand All @@ -2126,7 +2126,7 @@ def hint_level97():
"""To repeat within a repeats a set number of times you can use something like the following:
<pre>for i in range(3):
for j in range(5):
v.turn left
my_van.turn left
print count</pre>
The print statement will output the value of count to the console."""
+ PYTHON_HINT
Expand All @@ -2150,11 +2150,11 @@ def description_level98():
def hint_level98():
return (
"""To repeat while a condition is met you can use something like the following:
<pre>while not v.at_destination():
v.move_forwards()</pre>
<pre>while not my_van.at_destination():
my_van.move_forwards()</pre>
To check whether a condition is met you can use something like the following:
<pre>if v.is_road_forward():
v.move_forwards()</pre>
<pre>if my_van.is_road_forward():
my_van.move_forwards()</pre>
You may also need to use the <b>else</b> statement."""
+ PYTHON_HINT
)
Expand All @@ -2176,11 +2176,11 @@ def description_level99():
def hint_level99():
return (
"""To repeat while a condition is met you can use something like the following:
<pre>while not v.at_destination():
v.move_forwards()</pre>
<pre>while not my_van.at_destination():
my_van.move_forwards()</pre>
To check whether a condition is met you can use something like the following:
<pre>if v.is_road_forward():
v.move_forwards()</pre>
<pre>if my_van.is_road_forward():
my_van.move_forwards()</pre>
You may also need to use the <b>elif</b> and <b>else</b> statements."""
+ PYTHON_HINT
)
Expand All @@ -2200,7 +2200,7 @@ def description_level100():

def hint_level100():
return (
"Try using<br><pre>if v.at_dead_end():</pre><br>to check if the van is at a dead end."
"Try using<br><pre>if my_van.at_dead_end():</pre><br>to check if the van is at a dead end."
+ PYTHON_HINT
)

Expand Down Expand Up @@ -2344,7 +2344,7 @@ def hint_level106():
return (
"""To use a variable to store the number of grid squares the van has to move you can do something like the following:
<pre>n = 1
while not v.at_destination():
while not my_van.at_destination():
print n
n += 1</pre>
Variables can be used in place of constants when calling functions. For example to repeat something n times you can do something like the following:
Expand Down
24 changes: 12 additions & 12 deletions game/static/game/js/blocklyCustomBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,23 +378,23 @@ function initCustomBlocksPython() {
};

Blockly.Python['move_forwards'] = function(block) {
return 'v.move_forwards()\n';
return 'my_van.move_forwards()\n';
};

Blockly.Python['turn_left'] = function(block) {
return 'v.turn_left()\n';
return 'my_van.turn_left()\n';
};

Blockly.Python['turn_right'] = function(block) {
return 'v.turn_right()\n';
return 'my_van.turn_right()\n';
};

Blockly.Python['turn_around'] = function(block) {
return 'v.turn_around()\n';
return 'my_van.turn_around()\n';
};

Blockly.Python['wait'] = function(block) {
return 'v.wait()\n';
return 'my_van.wait()\n';
};

Blockly.Python['deliver'] = function(block) {
Expand All @@ -403,11 +403,11 @@ function initCustomBlocksPython() {

Blockly.Python['road_exists'] = function(block) {
if(block.inputList[0].fieldRow[1].value_ === 'FORWARD'){
var python = "v.is_road('FORWARD')";
var python = "my_van.is_road('FORWARD')";
}else if(block.inputList[0].fieldRow[1].value_ === 'LEFT'){
var python = "v.is_road('LEFT')";
var python = "my_van.is_road('LEFT')";
}else{
var python = "v.is_road('RIGHT')";
var python = "my_van.is_road('RIGHT')";
}

return [python, Blockly.Python.ORDER_NONE];
Expand All @@ -417,16 +417,16 @@ function initCustomBlocksPython() {
Blockly.Python['traffic_light'] = function(block) {
var python;
if(block.inputList[0].fieldRow[1].value_ === ocargo.TrafficLight.RED){
python = "v.at_traffic_light('RED')";
python = "my_van.at_traffic_light('RED')";
}else{
python = "v.at_traffic_light('GREEN')";
python = "my_van.at_traffic_light('GREEN')";
}

return [python, Blockly.Python.ORDER_NONE]; //TODO: figure out what this ordering relates to
};

Blockly.Python['dead_end'] = function(block) {
return ['v.at_dead_end()', Blockly.Python.ORDER_NONE];
return ['my_van.at_dead_end()', Blockly.Python.ORDER_NONE];
// TODO: figure out what this ordering relates to
};

Expand All @@ -436,7 +436,7 @@ function initCustomBlocksPython() {
};

Blockly.Python['at_destination'] = function(block) {
return ['v.at_destination()', Blockly.Python.ORDER_NONE];
return ['my_van.at_destination()', Blockly.Python.ORDER_NONE];
// TODO: figure out what this ordering relates to;
};

Expand Down
30 changes: 15 additions & 15 deletions game/static/game/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ ocargo.Game.prototype._setupPythonTab = function () {
gettext(
'Run the following commands on the van object %(var_name)s, e.g. %(example)s'
),
{ var_name: 'v', example: 'v.move_forwards()' },
{ var_name: 'v', example: 'my_van.move_forwards()' },
true
) +
'</p>' +
Expand All @@ -731,21 +731,21 @@ ocargo.Game.prototype._setupPythonTab = function () {
'<p><b>' +
gettext('Movement') +
'</b>' +
'<br>v.move_forwards()' +
'<br>v.turn_left()' +
'<br>v.turn_right()' +
'<br>v.turn_around()' +
'<br>v.wait()</p>' +
'<br>my_van.move_forwards()' +
'<br>my_van.turn_left()' +
'<br>my_van.turn_right()' +
'<br>my_van.turn_around()' +
'<br>my_van.wait()</p>' +
'</div>' +
'<div class="large-4 columns">' +
'<p><b>' +
gettext('Position') +
'</b>' +
'<br>v.at_dead_end()' +
'<br>v.at_destination()' +
'<br>v.at_red_traffic_light()' +
'<br>v.at_green_traffic_light()' +
'<br>v.at_traffic_light(c)' +
'<br>my_van.at_dead_end()' +
'<br>my_van.at_destination()' +
'<br>my_van.at_red_traffic_light()' +
'<br>my_van.at_green_traffic_light()' +
'<br>my_van.at_traffic_light(c)' +
'<br><i>' +
interpolate(
gettext("where %(arg_name)s is '%(red_color)s' or '%(green_color)s'"),
Expand All @@ -756,10 +756,10 @@ ocargo.Game.prototype._setupPythonTab = function () {
'</div>' +
'<div class="large-4 columns">' +
'<p>' +
'<br>v.is_road_forward()' +
'<br>v.is_road_left()' +
'<br>v.is_road_right()' +
'<br>v.is_road(d)' +
'<br>my_van.is_road_forward()' +
'<br>my_van.is_road_left()' +
'<br>my_van.is_road_right()' +
'<br>my_van.is_road(d)' +
'<br><i>' +
interpolate(
gettext(
Expand Down
4 changes: 2 additions & 2 deletions game/static/game/js/pythonControl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var ocargo = ocargo || {};

var DEFAULT_CODE = "import van\n\nv = van.Van()\n";
var DEFAULT_CODE = "from van import Van\n\nmy_van = Van()\n";
var appendCodeToPanel = function (code, panel) {
var oldValue = panel.getValue();
var newValue = DEFAULT_CODE + code.replace(/<br\s*[\/]?>/gi, '\n');
Expand Down Expand Up @@ -134,7 +134,7 @@ ocargo.PythonControl = function () {
text: outputText
});
}

/*************************/
/** Initialisation code **/
/*************************/
Expand Down
Loading