Skip to content

Commit

Permalink
[gelopfalcon#3] Add: Reto 3
Browse files Browse the repository at this point in the history
  • Loading branch information
IvySaskia committed Aug 3, 2022
1 parent 605efb6 commit b42b7df
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions PokemonFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down

0 comments on commit b42b7df

Please sign in to comment.