Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

challenge completed. Aitor Zaldua #27

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 54 additions & 17 deletions PokemonFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
} */
}
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h2>Reto #1</h2>
Agregado evento eventNewPokemon que se dispara en la funcion createPokemon con el emmit correspondiente.

<h2>Reto #2</h2>
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.

<h2>Reto #3</h2>
Agregado array con el nombre de las habilidades.
Agregado mapping para incluir descripción a las habilidades.


<h2>Reto #4 - Estudiante distinguido </h2>
Agregado array para incluir tipos de pokemons.
Agregado array para incluir debilidades.
2 changes: 0 additions & 2 deletions Retos.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.