Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
YordayFigueroaSanchez authored Jul 24, 2022
1 parent 703c415 commit f6ea55d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions PokemonFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,34 @@ pragma solidity >=0.7.0 <0.9.0;

contract PokemonFactory {

struct Ability {
string name;
string description;
}
struct Pokemon {
uint id;
string name;
}

struct PokemonType {
uint8 id;
string name;
}

Pokemon[] private pokemons;
Ability[] private abilities;
PokemonType[] private pokemonTypes;

mapping (uint => address) public pokemonToOwner;
mapping (address => uint) ownerPokemonCount;

mapping (uint => Pokemon) idToPokemon;

mapping (string => Ability) nameToAbility;
mapping (uint => Ability[]) pokemonIdToAbility;

mapping (uint => PokemonType) idToPokemonTypes;

event eventNewPokemon(Pokemon);

function createPokemon (string memory _name, uint _id) public {
Expand All @@ -22,13 +40,31 @@ contract PokemonFactory {
pokemons.push(Pokemon(_id, _name));
pokemonToOwner[_id] = msg.sender;
ownerPokemonCount[msg.sender]++;
idToPokemon[_id] = Pokemon(_id, _name);
emit eventNewPokemon(Pokemon(_id, _name));
}
function createAbility (string memory _name, string memory _description) public {
require(bytes(_name).length > 1, "El nombre de la habilidad con al menos doscarateres.");
require(bytes(_description).length > 1, "Esfuerzo con la descripcion.");
abilities.push(Ability(_name,_description));
nameToAbility[_name] = Ability(_name,_description);

}

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

function getAllAbilities() public view returns (Ability[] memory) {
return abilities;
}

function getAbilitiesFromPokemon(uint pokemonid) public view returns (Ability[] memory) {
return pokemonIdToAbility[pokemonid];
}




function getResult() public pure returns(uint product, uint sum){
uint a = 1;
Expand All @@ -37,4 +73,8 @@ contract PokemonFactory {
sum = a + b;
}

function addAbilityToPokemon(uint _pokemonId, string memory _abiliteName) public {
pokemonIdToAbility[idToPokemon[_pokemonId].id].push( nameToAbility[_abiliteName]);
}

}

0 comments on commit f6ea55d

Please sign in to comment.