第83篇 笔记-猜拳游戏智能合约
Posted wonderBlock
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第83篇 笔记-猜拳游戏智能合约相关的知识,希望对你有一定的参考价值。
本合约实现经典的包袱剪刀锤子猜拳游戏;
源码:
pragma solidity 0.5.10;
contract rps {
address public owner;
uint256 public balance;
uint256 public gamesPlayed;
string public lastResult;
enum hand {ROCK, PAPER, SCISSORS}
enum result {WIN, LOSE, TIE}
event Outcome(string result);
constructor() public payable{
owner = msg.sender;
balance = msg.value;
gamesPlayed = 0;
lastResult = "";
}
// Give balance to bot
function giveBalance() public payable{
if (msg.sender == owner) {
balance += msg.value;
}
}
// Get games played
function getGamesPlayed() public view returns(uint256) {
return gamesPlayed;
}
// Get bot balance
function getBalance() public view returns(uint256){
return balance;
}
// Get last game result
function getLastResult() public view returns(string memory){
return lastResult;
}
// Withdraw from bot
function with
以上是关于第83篇 笔记-猜拳游戏智能合约的主要内容,如果未能解决你的问题,请参考以下文章