Exploring Decomposition
Decomposition is the idea of breaking a big problem into smaller, easier parts. Instead of writing one long block of code, we divide the work into multiple functions. Each function handles one clear task, making our code easier to read, reuse, and maintain.
In the Ninja Game, decomposition helps us build complex behavior from simple building blocks. By calling functions inside other functions, you create a chain of actions that the ninja performs step by step.
ninja.js
ninjaControllerorganizes the mission. Instead of writing all movements here, it simply callslootTunnelthree times;lootTunnelcontains the detailed steps for entering a tunnel, grabbing sushi, and exiting;- At the end of each tunnel,
lootTunnelcallsmoveToNextTunnel, which prepares the ninja for the next run.
This layered approach makes the code much clearer. Each function has one job, and together they form a complete solution.
Swipe to start coding
Solution
Explore other courses in Catalog
Thanks for your feedback!
ninja.js
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.57
Exploring Decomposition
Swipe to show menu
Decomposition is the idea of breaking a big problem into smaller, easier parts. Instead of writing one long block of code, we divide the work into multiple functions. Each function handles one clear task, making our code easier to read, reuse, and maintain.
In the Ninja Game, decomposition helps us build complex behavior from simple building blocks. By calling functions inside other functions, you create a chain of actions that the ninja performs step by step.
ninja.js
ninjaControllerorganizes the mission. Instead of writing all movements here, it simply callslootTunnelthree times;lootTunnelcontains the detailed steps for entering a tunnel, grabbing sushi, and exiting;- At the end of each tunnel,
lootTunnelcallsmoveToNextTunnel, which prepares the ninja for the next run.
This layered approach makes the code much clearer. Each function has one job, and together they form a complete solution.
Swipe to start coding
Solution
Explore other courses in Catalog
Thanks for your feedback!
ninja.js