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: Create failed attempt on crash, out of fuel and red light events #1280

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion game/end_to_end_tests/selenium_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ def tearDownClass(cls):

def __call__(self, result=None):
if hasattr(self, "selenium"):
for width in getattr(settings, "SELENIUM_WIDTHS", [1024]):
for width in getattr(settings, "SELENIUM_WIDTHS", [1624]):
self.selenium.set_window_size(width, 1024)
return super(SeleniumTestCase, self).__call__(result)
17 changes: 11 additions & 6 deletions game/static/game/js/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ ocargo.Model.prototype.getPreviousCoordinate = function() {

ocargo.Model.prototype.moveVan = function(nextNode, action) {
//Crash?
var previousNodeCow = this.getCowForNode(this.van.getPosition().currentNode, ocargo.Cow.ACTIVE);
var collisionWithCow = previousNodeCow && nextNode !== this.van.getPosition().currentNode;
let previousNodeCow = this.getCowForNode(this.van.getPosition().currentNode, ocargo.Cow.ACTIVE);
let collisionWithCow = previousNodeCow && nextNode !== this.van.getPosition().currentNode;

if(collisionWithCow) {
if (collisionWithCow) {
handleCrash(this, gettext('You ran into a cow! Keep in mind that cows can appear anywhere on the map.'),
'COLLISION_WITH_COW', 'collision with cow van move action: ');
return false;
}

var offRoad = nextNode === null;
var offRoadPopupMessage = function(correctSteps){
let offRoad = nextNode === null;
let offRoadPopupMessage = function(correctSteps){
if (correctSteps === 0) {
return gettext('Your first move was a crash. What went wrong?');
}
Expand All @@ -184,6 +184,8 @@ ocargo.Model.prototype.moveVan = function(nextNode, action) {
failures: this.failures,
pythonWorkspace: ocargo.pythonControl.getCode() });

ocargo.game.sendAttempt(0);

ocargo.animation.appendAnimation({
type: 'popup',
popupType: 'FAIL',
Expand Down Expand Up @@ -211,8 +213,10 @@ ocargo.Model.prototype.moveVan = function(nextNode, action) {
return false;
}

var light = this.getTrafficLightForNode(this.van.getPosition());
let light = this.getTrafficLightForNode(this.van.getPosition());
if (light !== null && light.getState() === ocargo.TrafficLight.RED && nextNode !== light.controlledNode) {
ocargo.game.sendAttempt(0);

// Ran a red light
ocargo.event.sendEvent("LevelThroughRedLight", { levelName: LEVEL_NAME,
defaultLevel: DEFAULT_LEVEL,
Expand Down Expand Up @@ -269,6 +273,7 @@ ocargo.Model.prototype.moveVan = function(nextNode, action) {

function handleCrash(model, popupMessage, vanAction, actionDescription) {
model.van.crashStatus = 'CRASHED';
ocargo.game.sendAttempt(0);

ocargo.animation.appendAnimation({
type: 'callable',
Expand Down
14 changes: 8 additions & 6 deletions game/static/game/js/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ocargo.Thread = function(program) {
};

ocargo.Thread.prototype.run = function(model) {
var failed = false;
let failed = false;
while (!failed && this.canStep()) {
failed = !this.step(model);
}
Expand All @@ -39,18 +39,20 @@ ocargo.Thread.prototype.run = function(model) {

ocargo.Thread.prototype.step = function(model) {
// check if any event condition is true
for (var i=0; i<this.program.events.length; i++) {
var event = this.program.events[i];
for (let i = 0; i < this.program.events.length; i++) {
let event = this.program.events[i];
model.shouldObserve = false;
if (event.condition(model)) {
event.execute(this, model);
}
model.shouldObserve = true;
}

var commandToProcess = this.stack.shift();
let commandToProcess = this.stack.shift();
this.noExecutionSteps ++;

if (this.noExecutionSteps > MAX_EXECUTION_STEPS) {
ocargo.game.sendAttempt(0);
// alert user to likely infinite loop
ocargo.animation.appendAnimation({
type: 'popup',
Expand All @@ -63,14 +65,14 @@ ocargo.Thread.prototype.step = function(model) {
return false;
}

var successful = true;
let successful = true;
if (commandToProcess) {
successful = commandToProcess.execute(this, model);
}

if (!successful) {
// Program crashed, queue a block highlight event
var block = commandToProcess.block;
let block = commandToProcess.block;
queueHighlightIncorrect(model, block);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion game/templates/game/level_selection.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<div class="container background">
<div id="episodes">
<div class="panel-intro">
<h4>Blocky levels</h4>
<h4>Blockly levels</h4>
The first set of levels use Blockly to slowly introduce you to Python. You can read more about Blockly
<a href="https://docs.codeforlife.education/rapid-router/blockly-guide" target="_blank">here</a>.
</div>
Expand Down
1 change: 0 additions & 1 deletion game/views/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ def submit_attempt(request):
if attempt:
attempt.score = float(request.POST.get("score"))
attempt.workspace = request.POST.get("workspace")
attempt.workspace = request.POST.get("workspace")
attempt.python_workspace = request.POST.get("python_workspace")

record_best_attempt(attempt)
Expand Down