diff --git a/PokemonFactory.sol b/PokemonFactory.sol index a3267da1..cd818f40 100644 --- a/PokemonFactory.sol +++ b/PokemonFactory.sol @@ -3,33 +3,70 @@ pragma solidity >=0.7.0 <0.9.0; contract PokemonFactory { - - struct Pokemon { - uint id; - string name; - } + struct Pokemon { + uint id; + string name; + string[] habilitiesName; + string[] pokemonTypes; + string[] weakness; + } Pokemon[] private pokemons; - mapping (uint => address) public pokemonToOwner; - mapping (address => uint) ownerPokemonCount; + //Events: + + event eventNewPokemon( + uint id, + string name, + string[] habilitiesName, + string[] pokemonTypes, + string[] weakness + ); + + mapping(uint => address) public pokemonToOwner; + mapping(address => uint) ownerPokemonCount; + mapping(string => string) habilitiesDescription; + + //INSERT Functions: + + function createPokemon(string memory _name, uint _id) public { + require(_id > 0, "The id should be greater than 0"); + require( + keccak256(abi.encodePacked(_name)) != + keccak256(abi.encodePacked(" ")), + "The name can not be a blank space" + ); + require( + bytes(_name).length > 2, + "The name length should be greater than 2" + ); + + pokemons.push(Pokemon(_id, _name, _habilitiesName, _pokemonTypes, _weakness)); - function createPokemon (string memory _name, uint _id) public { - pokemons.push(Pokemon(_id, _name)); pokemonToOwner[_id] = msg.sender; ownerPokemonCount[msg.sender]++; + + emit eventNewPokemon(_id, _name, _habilitiesName, _pokemonTypes, _weakness); } - function getAllPokemons() public view returns (Pokemon[] memory) { - return pokemons; + function insertDescription (string memory _name, string memory _habilityDescription) public { + habilitiesDescription[_name] = _habilityDescription; } + //GET Functions: + + function getAllPokemons() public view returns (Pokemon[] memory) { + return pokemons; + } - function getResult() public pure returns(uint product, uint sum){ - uint a = 1; - uint b = 2; - product = a * b; - sum = a + b; - } + function getHabilities(string memory _name) public view returns(string memory, string memory) { + return(_name, habilitiesDescription[_name]); + } + /* function getResult() public pure returns (uint product, uint sum) { + uint a = 1; + uint b = 2; + product = a * b; + sum = a + b; + } */ } diff --git a/README.md b/README.md new file mode 100644 index 00000000..4811ecf7 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +

Reto #1

+Agregado evento eventNewPokemon que se dispara en la funcion createPokemon con el emmit correspondiente. + +

Reto #2

+Agregado require => El id debe ser mayor que 0. +Agregado require => El nombre no puede ser espacios en blanco. +Agregado require => El nombre debe tener, al menos, 3 caracteres. + +

Reto #3

+Agregado array con el nombre de las habilidades. +Agregado mapping para incluir descripción a las habilidades. + + +

Reto #4 - Estudiante distinguido

+Agregado array para incluir tipos de pokemons. +Agregado array para incluir debilidades. \ No newline at end of file diff --git a/Retos.md b/Retos.md index bb8a8866..2a9d2c3b 100644 --- a/Retos.md +++ b/Retos.md @@ -17,5 +17,3 @@ Los Pokemons han evolucionado, ahora tienen una lista de habilidades (Habilities Los Pokemons pueden pertenecer a más de un tipo (Type), por ejemplo: Bulbasaur es de tipo Grass y Poison. Proponga una solución e impleméntela. Los Pokemons tienen debilidades (Weaknesses) las cuales pueden ser otros tipos de pokemones. Por ejemplo, Bulbasaur es débil contra pokemones de tipo Fire, Flying, Ice, Psychic. Proponga una solución e impleméntela. - -