Module pokelab::pokemon::charmander

source ·
Expand description

This module contains the Charmander type, as well as its method implementations.

The Charmander struct will model the pokemon of the same name. We want to design the struct in such a way that we can easily create a Charmander and modify its attributes like health, level, and name.

Charmander should have the following attributes:

  • name: String
  • level: usize
  • health: usize
  • attack: usize
  • defense: usize

All of these fields should be private (not accessible outside of the struct).


Once you’ve added the fields to the struct, implement the following methods:

  • new: This method will take in a name and create a new Charmander struct with the following default values:
    • level: 0
    • health: 100
    • attack: 42
    • defense: 33
  • level_up: This method will increase the level of the Charmander struct by the input levels.
  • get_health: This method will return the health value of the Charmander struct.
  • get_attack: This method will return the attack value of the Charmander struct.
  • get_defense: This method will return the defense value of the Charmander struct.

For some of these methods, you may have to do some extra work to determine the value to return. Make sure to read the specification in either the comments in the code or on this writeup!


We also want Charmanders to battle with each other. We’ll implement the following methods attack and fight. Click on these hyperlinks or read the doc comments to see the specification for these methods!

Note that this pokemon is completely different from the Eevee pokemon that you will implement in the next part, so make sure not to mix them up!

Structs