Skip to content

Commit

Permalink
Added character data
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMousy committed Nov 26, 2021
1 parent 327156c commit 9d7079a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
45 changes: 39 additions & 6 deletions contracts/MyEpicGame.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;

import "hardhat/console.sol";

contract MyEpicGame {
constructor() {
console.log("THIS IS MY GAME CONTRACT. NICE.");
// We'll hold our character's attributes in a struct. Feel free to add
// whatever you'd like as an attribute! (ex. defense, crit chance, etc).
struct CharacterAttributes {
uint characterIndex;
string name;
string imageURI;
uint hp;
uint maxHp;
uint attackDamage;
}
// A lil array to help us hold the default data for our characters.
// This will be helpful when we mint new characters and need to know
// things like their HP, AD, etc.
CharacterAttributes[] defaultCharacters;

// Data passed in to the contract when it's first created initializing the characters.
// We're going to actually pass these values in from from run.js.
constructor(
string[] memory characterNames,
string[] memory characterImageURIs,
uint[] memory characterHp,
uint[] memory characterAttackDmg
)
{
// Loop through all the characters, and save their values in our contract so
// we can use them later when we mint our NFTs.
for(uint i = 0; i < characterNames.length; i += 1) {
defaultCharacters.push(CharacterAttributes({
characterIndex: i,
name: characterNames[i],
imageURI: characterImageURIs[i],
hp: characterHp[i],
maxHp: characterHp[i],
attackDamage: characterAttackDmg[i]
}));

CharacterAttributes memory c = defaultCharacters[i];
console.log("Done initializing %s w/ HP %s, img %s", c.name, c.hp, c.imageURI);
}
}
}
9 changes: 8 additions & 1 deletion scripts/run.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
const main = async () => {
const gameContractFactory = await hre.ethers.getContractFactory('MyEpicGame');
const gameContract = await gameContractFactory.deploy();
const gameContract = await gameContractFactory.deploy(
["Goku", "Vegeta", "Gohan"], // Names
["https://i.imgur.com/ToBebz9b.jpg", // Images
"https://i.imgur.com/aRy02l9b.jpg",
"https://i.imgur.com/cmVNaT0b.jpg"],
[100, 500, 1337], // HP values
[1337, 100, 50] // Attack damage values
);
await gameContract.deployed();
console.log("Contract deployed to:", gameContract.address);
};
Expand Down

0 comments on commit 9d7079a

Please sign in to comment.