Challenge: Building a Composed Warrior
Task
Swipe to start coding
Practice using composition by building a simple warrior game:
- Create a
Weaponclass with anameandattackvalue. - Create a
Warriorclass with anamethat can equip a weapon (store it as an attribute) and has a method to show its current weapon. - Equip the warrior with the weapon.
- Use composition. The warrior should have a weapon, not inherit from it.
Solution
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 18
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.85
Challenge: Building a Composed Warrior
Swipe to show menu
Task
Swipe to start coding
Practice using composition by building a simple warrior game:
- Create a
Weaponclass with anameandattackvalue. - Create a
Warriorclass with anamethat can equip a weapon (store it as an attribute) and has a method to show its current weapon. - Equip the warrior with the weapon.
- Use composition. The warrior should have a weapon, not inherit from it.
Solution
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 18
single