好吧..。我有一个问题,开始写聪明的合同,我不知道哪一部分应该先写。例如,我们有一个游戏。它有一个英雄,它具有战斗等功能。合同有记账、英雄和战斗合同等。它应该是这样写的:帐户,->,英雄,->,战斗或战斗->英雄->帐户?
发布于 2021-07-27 23:31:10
你的问题非常笼统,因此很难回答。我说这完全取决于你和你的项目。我知道,写多个彼此交互的智能合同可能会很痛苦(我目前正在与少数人做斗争)。在你的例子中,我先写战斗,然后写英雄,然后说明,因为战斗应该有更少的呼叫给另外两个人。如果您被迫从未编写的函数中调用函数,请使用占位符或注释,类似于这样(这是伪ofc)
contract Fighting {
function attack (address attacker, address defender, uint256 attackerStat, uint256 defenderStat) public {
uint256 damageDealt = attackerStat - defenderStat // (or whatever math you want to perform to get the damage dealt. btw using solidity's native - operator is unsafe, use SafeMath's sub() function instead
// HeroContract defender = HeroContract(defender)
// defender.looseHP(damageDealt)
// The 2 last lines are commented out because you didnt write the hero contract yet, and you're not sure you'll use that exact syntax.
}}
https://ethereum.stackexchange.com/questions/104075
复制相似问题