【发布时间】:2021-07-05 12:50:45
【问题描述】:
希望一切顺利
我想在下面的solidity代码中做以下活动,但不知道怎么做,请指教。 感谢问候 赛义德
查询:_
使用两个参数发出事件 ScoreChanged:int 数量(等于发送的值)和 bool 方向(向上函数为 true,向下函数为 false)
gameOver 切换为 true 后发出事件 GameEnded
代码:
pragma solidity ^0.4.17;
contract TugOfWar {
int public score = 0;
int constant endAt = 1 ether;
bool public gameOver = false;
function up() external payable {
require(msg.value > 0);
require(!gameOver);
int value = int(msg.value);
score += value;
checkIfGameOver();
}
function down() external payable {
require(msg.value > 0);
require(!gameOver);
int value = int(msg.value);
score -= value;
checkIfGameOver();
}
function checkIfGameOver() internal {
if(score >= endAt || score <= endAt * -1) {
gameOver = true;
}
}
}
【问题讨论】: