Skip to content

Commit

Permalink
[gelopfalcon#3] Add: Reto 3 version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
IvySaskia committed Aug 3, 2022
1 parent b42b7df commit 8bd7a81
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions PokemonFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,26 @@ contract PokemonFactory {

event eventNewPokemon (Pokemon pokemon);

function createPokemon (string memory _name, uint _id, Ability[] memory _abilities) public {
require(_id > 0, "Pokemon's id should be greater than 0");
require(bytes(_name).length > 2, "Pokemon's name should have more that two characters.");
Pokemon storage pokemon = pokemons.push();
pokemon.id = _id;
pokemon.name = _name;
for (uint i = 0; i < _abilities.length; i++) {
pokemon.abilities.push(_abilities[i]);
function createPokemon (string memory _name, uint _id) public {
require(_id > 0, "Pokemon's id should be greater than 0");
require(bytes(_name).length > 2, "Pokemon's name should have more that two characters.");
Pokemon storage pokemon = pokemons.push();
pokemon.id = _id;
pokemon.name = _name;
pokemonToOwner[_id] = msg.sender;
ownerPokemonCount[msg.sender]++;
emit eventNewPokemon (pokemon);
}

function addAbilitiesToPokemon(uint _idPokemon, Ability[] memory _abilities) public {
for (uint256 i; i<pokemons.length; i++) {
if (pokemons[i].id == _idPokemon) {
for (uint j = 0; j < _abilities.length; j++) {
pokemons[i].abilities.push(_abilities[j]);
}
break;
}
}

pokemonToOwner[_id] = msg.sender;
ownerPokemonCount[msg.sender]++;
emit eventNewPokemon (pokemon);
}

function getAllPokemons() public view returns (Pokemon[] memory) {
Expand Down

0 comments on commit 8bd7a81

Please sign in to comment.