Skip to content

Instantly share code, notes, and snippets.

@pom421
Created February 9, 2023 23:04
Show Gist options
  • Save pom421/0051dd88adba5bddc54b264420862527 to your computer and use it in GitHub Desktop.
Save pom421/0051dd88adba5bddc54b264420862527 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=
// 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