From b42b7dff9cadf248e11114f2827d4a6ce82aa579 Mon Sep 17 00:00:00 2001 From: IvySaskia Date: Tue, 2 Aug 2022 09:58:31 -0400 Subject: [PATCH] [gelopfalcon/solidity-eth-challenge#3] Add: Reto 3 --- PokemonFactory.sol | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/PokemonFactory.sol b/PokemonFactory.sol index c6f3d7d6..ecfeeee4 100644 --- a/PokemonFactory.sol +++ b/PokemonFactory.sol @@ -4,10 +4,16 @@ pragma solidity >=0.7.0 <0.9.0; contract PokemonFactory { - struct Pokemon { - uint id; - string name; - } + struct Pokemon { + uint id; + string name; + Ability[] abilities; + } + + struct Ability { + string name; + string description; + } Pokemon[] private pokemons; @@ -16,14 +22,19 @@ contract PokemonFactory { event eventNewPokemon (Pokemon pokemon); - 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 memory p = Pokemon(_id, _name); - pokemons.push(p); - pokemonToOwner[_id] = msg.sender; - ownerPokemonCount[msg.sender]++; - emit eventNewPokemon (p); + 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]); + } + + pokemonToOwner[_id] = msg.sender; + ownerPokemonCount[msg.sender]++; + emit eventNewPokemon (pokemon); } function getAllPokemons() public view returns (Pokemon[] memory) {