Skip to content

Commit

Permalink
feat: add cows to existing levels (#1492)
Browse files Browse the repository at this point in the history
* level 38

* update level 38 solution

* level 47

* fix level 47 decor

* level 47 solution

* level 47 hint

* level 39 cows

* level 39 decor quick save

* level 39 decor

* level 39 solution

* level 39 message

* fix algorithm score

* Remove unnecessary node push

* Remove route score and update test

* feedback

Co-Authored-By: faucomte97 <f.aucomte@hotmail.co.uk>
  • Loading branch information
SKairinos and faucomte97 authored Oct 16, 2023
1 parent c0a33b7 commit a57c0b3
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 16 deletions.
2 changes: 1 addition & 1 deletion game/end_to_end_tests/test_play_through.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_level_038(self):
self._complete_level(38)

def test_level_039(self):
self._complete_level(39)
self._complete_level(39, check_route_score=False)

def test_level_040(self):
self._complete_level(40)
Expand Down
34 changes: 23 additions & 11 deletions game/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,22 +905,29 @@ def hint_level37():


def title_level38():
return "Third time lucky!"
return "Where did the cows come from?"


def description_level38():
message = (
"Well done! You've got so far. <br> Can you apply the knowledge you "
"gained going through this part of the game to this level?"
"Well done! You've got so far."
"<br>"
"Can you apply the knowledge you gained going through this part of the "
"game to this level? This time there are some hidden cows that you "
"need to get out of the road! Can you work out what to do?"
"<br><br>"
"Hint: Cows don't like noise"
)
return build_description(title_level38(), message)


def hint_level38():
return (
"This is a really long route. With a counted loop, your program would be quite "
"long but is this program going to be any longer than your solution to the "
"last level?"
"This is a really long route. With a counted loop, your program would "
"be quite long but is this program going to be any longer than your "
"solution to the last level?"
"<br><br>"
"Hint: Cows don't like noise"
)


Expand All @@ -930,9 +937,10 @@ def title_level39():

def description_level39():
message = (
"Can you use the 'general algorithm' here so that the van takes a "
"shorter route? Or maybe there's a more efficient way? <br><br>Keep "
"an eye on the fuel level - try to use as little as possible."
"It looks like the cows have escaped when you get to the side roads, "
"so be careful not to hit them!"
"<br><br>"
"Hint: Cows don't like noise"
)
return build_description(title_level39(), message)

Expand All @@ -943,6 +951,8 @@ def hint_level39():
"Uh oh, moving around the blocks in your 'general algorithm' might not "
"be the most efficient solution. How about creating a simple solution "
"without 'if statements' that will help the van reach the house?"
"<br><br>"
"Hint: Cows don't like noise"
)


Expand Down Expand Up @@ -1106,8 +1116,10 @@ def description_level47():

def hint_level47():
return (
"This route is similar to the last one but the turn is in the other direction. "
"Can you adapt your program?"
"This route is similar to the last one but the turn is in a different "
"direction, and there are now cows instead of traffic lights!!"
"<br><br>"
"Do you remember what to do?"
)


Expand Down
195 changes: 195 additions & 0 deletions game/migrations/0083_add_cows_to_existing_levels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
from django.apps.registry import Apps
from django.db import migrations


def add_cows_to_existing_levels(apps: Apps, *args):
Level = apps.get_model("game", "Level")
Block = apps.get_model("game", "Block")
LevelBlock = apps.get_model("game", "LevelBlock")
LevelDecor = apps.get_model("game", "LevelDecor")

level_38 = Level.objects.get(name="38", default=1)
level_38.cows = '[{"minCows":1,"maxCows":1,"potentialCoordinates":[{"x":2,"y":6},{"x":3,"y":4},{"x":3,"y":1}],"type":"WHITE"}]'
level_38.theme_name = "farm"
level_38.model_solution = "[10]"
level_38.save()

level_39 = Level.objects.get(name="39", default=1)
level_39.cows = '[{"minCows":1,"maxCows":1,"potentialCoordinates":[{"x":4,"y":4},{"x":8,"y":4},{"x":8,"y":6}],"type":"WHITE"}]'
level_39.theme_name = "farm"
level_39.model_solution = "[10]"
level_39.disable_route_score = True
level_39.save()

level_47 = Level.objects.get(name="47", default=1)
level_47.traffic_lights = "[]"
level_47.cows = '[{"minCows":1,"maxCows":1,"potentialCoordinates":[{"x":6,"y":4},{"x":4,"y":6},{"x":2,"y":4}],"type":"WHITE"}]'
level_47.theme_name = "farm"
level_47.model_solution = "[8]"
level_47.save()

block_sound_horn = Block.objects.get(type="sound_horn")
block_cow_crossing = Block.objects.get(type="cow_crossing")

LevelBlock.objects.filter(
level=level_47,
type__type__in=["traffic_light", "wait"],
).delete()

LevelBlock.objects.bulk_create(
[
LevelBlock(level=level_38, type=block_sound_horn),
LevelBlock(level=level_38, type=block_cow_crossing),
LevelBlock(level=level_39, type=block_sound_horn),
LevelBlock(level=level_39, type=block_cow_crossing),
LevelBlock(level=level_47, type=block_sound_horn),
LevelBlock(level=level_47, type=block_cow_crossing),
]
)

LevelDecor.objects.filter(
level_id__in=[
level_47.id,
]
).delete()

LevelDecor.objects.bulk_create(
[
LevelDecor(
x=570,
y=296,
decorName="pond",
level=level_39,
),
LevelDecor(
x=570,
y=408,
decorName="pond",
level=level_39,
),
LevelDecor(
x=570,
y=514,
decorName="pond",
level=level_39,
),
LevelDecor(
x=293,
y=300,
decorName="tree1",
level=level_39,
),
LevelDecor(
x=711,
y=101,
decorName="tree1",
level=level_39,
),
LevelDecor(
x=897,
y=604,
decorName="tree1",
level=level_39,
),
LevelDecor(
x=114,
y=315,
decorName="tree1",
level=level_39,
),
LevelDecor(
x=37,
y=502,
decorName="pond",
level=level_47,
),
LevelDecor(
x=39,
y=400,
decorName="pond",
level=level_47,
),
LevelDecor(
x=39,
y=296,
decorName="pond",
level=level_47,
),
LevelDecor(
x=720,
y=657,
decorName="bush",
level=level_47,
),
LevelDecor(
x=720,
y=556,
decorName="bush",
level=level_47,
),
LevelDecor(
x=720,
y=455,
decorName="bush",
level=level_47,
),
LevelDecor(
x=720,
y=343,
decorName="bush",
level=level_47,
),
LevelDecor(
x=720,
y=220,
decorName="bush",
level=level_47,
),
LevelDecor(
x=403,
y=378,
decorName="tree1",
level=level_47,
),
LevelDecor(
x=440,
y=471,
decorName="tree1",
level=level_47,
),
LevelDecor(
x=132,
y=649,
decorName="tree1",
level=level_47,
),
LevelDecor(
x=620,
y=689,
decorName="tree1",
level=level_47,
),
LevelDecor(
x=500,
y=149,
decorName="tree1",
level=level_47,
),
LevelDecor(
x=550,
y=483,
decorName="tree2",
level=level_47,
),
]
)


class Migration(migrations.Migration):
dependencies = [("game", "0082_level_43_solution")]
operations = [
migrations.RunPython(
add_cows_to_existing_levels,
reverse_code=migrations.RunPython.noop,
)
]
1 change: 0 additions & 1 deletion game/static/game/js/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ ocargo.Model.prototype.isCowCrossing = function(type) {
var thisNode = this.van.getPosition().currentNode;
this.observe('cow crossing');
var nodes = thisNode.connectedNodes;
nodes.push(thisNode);
for(var i = 0; i < nodes.length; i++){
var node = nodes[i];
var cow = this.getCowForNode(node, [ocargo.Cow.ACTIVE, ocargo.Cow.READY]);
Expand Down
Loading

0 comments on commit a57c0b3

Please sign in to comment.