Solidity进阶之路:搭建僵尸工厂 - 完整代码
作者:互联网
Solidity Path: Beginner to Intermediate Smart Contracts
课程链接:https://cryptozombies.io/zh/lesson/1
你认为你可以当一个合格的 CryptoZombie, 嗯?
这个教程会教你如何搭建一个以太网的游戏。
此课程为 Solidity 初学者设计,需要你对其他的程序语言有所了解(如 JavaScript)。
课程完整代码如下:
pragma solidity ^0.4.19;
contract ZombieFactory {
event NewZombie(uint zombieId, string name, uint dna);
uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;
struct Zombie {
string name;
uint dna;
}
Zombie[] public zombies;
function _createZombie(string _name, uint _dna) private {
uint id = zombies.push(Zombie(_name, _dna)) - 1;
NewZombie(id,_name,_dna);
}
function _generateRandomDna(string _str) private view returns (uint) {
uint rand = uint(keccak256(_str));
return rand % dnaModulus;
}
function createRandomZombie(string _name) public {
uint randDna = _generateRandomDna(_name);
_createZombie(_name, randDna);
}
}
标签:dna,string,Solidity,name,Zombie,uint,搭建,进阶 来源: https://blog.csdn.net/m0_52650517/article/details/113837693