JAVASCRIPT FOR LEVEL 1.
More...
|
| function | speedup () |
| | This function is bind to the increase button it decreases the value of var speed so that animation time is less and hence speed increases finally. More...
|
| |
| function | speeddown () |
| | This function is bind to the decrease button it increases the value of var speed so that animation time is more and hence speed decreases finally. More...
|
| |
| function | create_arena () |
| | This function creates the whole arena dynamically, and restores all values of the global variable when the site is reloaded. More...
|
| |
| function | walk (r) |
| | This function controls the movement of warrior based on the input given. More...
|
| |
| function | check_success (gems_collected) |
| | The function checks if the players code is correct or not. More...
|
| |
| function | print_stat () |
| | This function is used to show print statement in the logger. More...
|
| |
JAVASCRIPT FOR LEVEL 1.
- Author
- Prolific Pythonists
- Date
- 24-11-2022
◆ check_success()
| function check_success |
( |
|
gems_collected | ) |
|
The function checks if the players code is correct or not.
If it is correct then it prints the message and if it is not, it will reload page after 5 second.
- Parameters
-
| {int} | gems_collected number of gems collected and assigned by player. |
◆ create_arena()
| function create_arena |
( |
| ) |
|
This function creates the whole arena dynamically, and restores all values of the global variable when the site is reloaded.
◆ print_stat()
This function is used to show print statement in the logger.
This function is implemented by overloading console.log function to show print statements on logger as well.
◆ speeddown()
This function is bind to the decrease button it increases the value of var speed so that animation time is more and hence speed decreases finally.
◆ speedup()
This function is bind to the increase button it decreases the value of var speed so that animation time is less and hence speed increases finally.
◆ walk()
This function controls the movement of warrior based on the input given.
Exception handling is also done in this function as while moving if warrior steps out of arena alert box is shown
- Parameters
-
| {int} | r integer determining direction of traversal. 1 => move_up, 2=>move_down() 3 => move_right() 4=> move_left
|
◆ innerHTML
◆ log
Initial value:= function (message) {
if(String(message).includes("level1/level1.html#__main__")){
logger.innerHTML +=
"error" +
'<br />';
}
else if (typeof message == 'object') {
logger.innerHTML += (JSON && JSON.stringify ? JSON.stringify(message) : message) +
'<br />';
}
else{
logger.innerHTML += message +
'<br />'
}
}
})()
◆ logger
| var logger = document.getElementById('log') |
◆ pos_x
stores the X-coordinate of warrior
◆ pos_y
stores the Y-coordinate of warrior
◆ reloaded
check if reloading was done before or not
◆ speed
For the animation speed of the player.
◆ speed_dict
| speed_dict = {250 : "fast", 500 : "medium", "750" : "slow"} |
maps speeds in milliseconds to the name corresponding to them.
◆ speed_show
| const speed_show = document.getElementById("speed_") |
The element in which we have to show speed.
◆ total_gems
stores the total number of gems in the path