Skip to content

Commit

Permalink
Implemented extension logic
Browse files Browse the repository at this point in the history
  • Loading branch information
juliekol committed Feb 10, 2024
1 parent e14d963 commit c604351
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions levels.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
//% color=#20bf6b weight=100 icon="\uf0ae"
namespace levels {

let currentLevel: number = 1;
const levels: Array<() => void> = [];

/**
Change the current level that is playing
**/
//% block
//% l.defl=1
export function startLevel(l: number = 1) {
currentLevel = l;
const handler = levels[l];
if (handler) {
handler();
} else {
console.error("ERROR: No 'on start level' block found for level " + l);
}
}

/**
Restart the current level
**/
//% block
export function restartLevel() {
startLevel(currentLevel);
}

/**
Start the next level (increment level by one)
**/
//% block
export function startNextLevel() {
startLevel(currentLevel + 1);
}

/**
Expand All @@ -30,5 +42,6 @@ namespace levels {
//% block="on start level $l"
//% l.defl=1
export function onStartLevel(l: number = 1, handler: () => void): void {
levels[l] = handler;
}
}
2 changes: 1 addition & 1 deletion main.blocks
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<xml xmlns="https://developers.google.com/blockly/xml"><block type="pxt-on-start" id="@!{Ymfd?WLn82.Z50V$L" x="0" y="0"></block></xml>
<xml xmlns="https://developers.google.com/blockly/xml"><block type="pxt-on-start" id="i64~^za7|!w^;/Hc?nc6" x="0" y="0"></block></xml>

0 comments on commit c604351

Please sign in to comment.