Skip to content

Commit

Permalink
Challenge gelopfalcon#4
Browse files Browse the repository at this point in the history
Challenge gelopfalcon#4 - Pokemon Weaknesses and types
  • Loading branch information
jejimenez committed Jul 27, 2022
1 parent 7c65b39 commit 4a567bd
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions PokemonFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ contract PokemonFactory {
string name;
}

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

event eventNewPokemon(Pokemon pokemon);

Expand All @@ -22,15 +23,30 @@ contract PokemonFactory {
mapping (uint => Skill[]) public pokemonToSkills;
mapping (uint => address) public pokemonToOwner;
mapping (address => uint) ownerPokemonCount;
mapping (uint => Type[]) pokemonToTypes;
mapping (uint => Type[]) pokemonToWeaknesses;

function createPokemon (string memory _name, uint _id, Skill[] memory _skills) public {

function createPokemon (string memory _name, uint _id, Skill[] memory _skills, Type[] memory _types, Type[] memory _weaknesses) public {
require(_id > 0, "Id should be more than 0.");
require(bytes(_name).length >= 2, "Name needs at least two letters");
uint256 length = _skills.length;
for (uint256 i = 0; i < length; i+=1) {
pokemons.push(Pokemon(_id, _name));
// loop skills to push in storage variable
uint256 skillsLength = _skills.length;
for (uint i = 0; i < skillsLength; i+=1) {
pokemonToSkills[_id].push(Skill(_skills[i].name,_skills[i].description));
}
pokemons.push(Pokemon(_id, _name));
//loop types to push in storage variable
uint256 typesLength = _types.length;
for (uint j = 0; j < typesLength; j+=1) {
pokemonToTypes[_id].push(_types[j]);
}
//loop types to push in storage variable
uint256 weaknessesLength = _weaknesses.length;
for (uint k = 0; k < weaknessesLength; k+=1) {
pokemonToWeaknesses[_id].push(_weaknesses[k]);
}

pokemonToOwner[_id] = msg.sender;
ownerPokemonCount[msg.sender]++;
emit eventNewPokemon(Pokemon(_id, _name));
Expand All @@ -45,6 +61,14 @@ contract PokemonFactory {
return pokemonToSkills[_id];
}

function getPokemonTypes(uint256 _id) public view returns (Type[] memory) {
return pokemonToTypes[_id];
}

function getPokemonWeaknesses(uint256 _id) public view returns (Type[] memory) {
return pokemonToWeaknesses[_id];
}

function getResult() public pure returns(uint product, uint sum, uint d){
uint a = 1;
uint b = 2;
Expand Down

0 comments on commit 4a567bd

Please sign in to comment.