Skip to content

Commit

Permalink
[gelopfalcon#4] Add: Reto 4 (1)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvySaskia committed Aug 3, 2022
1 parent 8bd7a81 commit 6b3fe7d
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions PokemonFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,39 @@ contract PokemonFactory {
uint id;
string name;
Ability[] abilities;
PokemonType[] pokemonTypes;
}

struct Ability {
string name;
string description;
}

enum PokemonType {
BUG,
DARK,
DRAGON,
ELECTRIC,
FAIRY,
FIGHTING,
FIRE,
FLYING,
GHOST,
GRASS,
GROUND,
ICE,
NORMAL,
POISON,
PSYCHIC,
ROCK,
STEEL,
WATER
}

Pokemon[] private pokemons;

mapping (uint => address) public pokemonToOwner;
mapping (address => uint) ownerPokemonCount;
mapping (uint => address) public pokemonToOwner; //guarda el id del pokemon vs el address del que esta ejecutando el smart contract, el address viene del frontend
mapping (address => uint) ownerPokemonCount;// vamos a a tener un conteo de la cantidad de pokemones por address.

event eventNewPokemon (Pokemon pokemon);

Expand All @@ -27,7 +49,7 @@ contract PokemonFactory {
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;
pokemon.name = _name;
pokemonToOwner[_id] = msg.sender;
ownerPokemonCount[msg.sender]++;
emit eventNewPokemon (pokemon);
Expand All @@ -44,6 +66,17 @@ contract PokemonFactory {
}
}

function addTypesToPokemon(uint _idPokemon, PokemonType[] memory _pokemonTypes) public {
for (uint256 i; i<pokemons.length; i++) {
if (pokemons[i].id == _idPokemon) {
for (uint j = 0; j < _pokemonTypes.length; j++) {
pokemons[i].pokemonTypes.push(_pokemonTypes[j]);
}
break;
}
}
}

function getAllPokemons() public view returns (Pokemon[] memory) {
return pokemons;
}
Expand Down

0 comments on commit 6b3fe7d

Please sign in to comment.