Created
February 9, 2023 23:04
-
-
Save pom421/2b185b8d4ac629382044e1de32ca0428 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.18+commit.87f61d96.js&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity 0.8.18; | |
import "@openzeppelin/contracts/access/Ownable.sol"; | |
contract epargne is Ownable { | |
string private mot; | |
string public indice; | |
address public gagnant; | |
mapping(address=>bool) played; | |
address[] public players; | |
function setMot(string memory _mot, string memory _indice) public onlyOwner{ | |
mot=_mot; | |
indice=_indice; | |
} | |
function getWinner() view public returns (string memory){ | |
if(gagnant==address(0)){ | |
return "Pas encore de gagnant!"; | |
} | |
else { | |
return "Il y a un gagnant!"; | |
} | |
} | |
function playWord(string memory _try) public returns (bool) { | |
require(played[msg.sender]==false, "t'as deja joue"); | |
if ( | |
keccak256(abi.encodePacked(_try)) == keccak256(abi.encodePacked(mot)) | |
){ | |
gagnant=msg.sender; | |
played[msg.sender]=true; | |
players.push(msg.sender); | |
return true; | |
} | |
else { | |
played[msg.sender]=true; | |
players.push(msg.sender); | |
return false; | |
} | |
} | |
function reset(string memory _mot, string memory _indice) public onlyOwner{ | |
uint tailleTableau=players.length; | |
address tempPlayers; | |
for (uint i=tailleTableau-1; i>0; i--){ | |
tempPlayers=players[i]; | |
played[tempPlayers]=false; | |
players.pop(); | |
} | |
gagnant = address(0); | |
setMot(_mot, _indice); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment