Created
February 9, 2023 23:05
-
-
Save pom421/5ed228c4dcbb551ebb46bec83c270a26 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 devinez is Ownable { | |
string private mot; | |
string public indice; | |
address public gagnant; | |
mapping(address => bool) played; | |
function setMot(string calldata _mot, string calldata _indice) | |
public | |
onlyOwner | |
{ | |
mot = _mot; | |
indice = _indice; | |
} | |
function getWinner() public view returns (string memory) { | |
if (gagnant == address(0)) { | |
return "Pas encore de gagnant!"; | |
} else { | |
return "Il y a un gagnant!"; | |
} | |
} | |
function playWord(string calldata _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; | |
return true; | |
} else { | |
played[msg.sender] = true; | |
return false; | |
} | |
} | |
} |
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); | |
} | |
} |
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 Notes is Ownable { | |
struct Student { | |
string name; | |
uint256 noteBiology; | |
uint256 noteMaths; | |
uint256 noteFr; | |
} | |
Student[] private students; | |
// mapping(string => Student) studentsmap; | |
// string[] names; | |
// class => course => addre | |
// cours => | |
mapping(string => address) teachers; | |
event studentAdded(string _name, address _addr); | |
event teacherAdded(string _course, address _addr); | |
function addStudent(string memory _name, address _addr) public onlyOwner { | |
students.push(Student(_name, 0, 0, 0)); | |
emit studentAdded(_name, _addr); | |
} | |
function setTeacher(string memory _course, address _addr) public onlyOwner { | |
teachers[_course] = _addr; | |
emit teacherAdded(_course, _addr); | |
} | |
function getStudentFromName(string memory _name) | |
private | |
view | |
returns (uint256) | |
{ | |
for (uint256 i = 0; i < students.length; i++) { | |
if ( | |
keccak256(abi.encodePacked(students[i].name)) == | |
keccak256(abi.encodePacked(_name)) | |
) { | |
return i; | |
} | |
} | |
return 0; | |
} | |
function stringsEquals(string memory _string1, string memory _string2) | |
private | |
pure | |
returns (bool) | |
{ | |
bool test; | |
if ( | |
keccak256(abi.encodePacked(_string1)) == | |
keccak256(abi.encodePacked(_string2)) | |
) { | |
test = true; | |
} | |
return test; | |
} | |
function setNote( | |
string memory _course, | |
string memory _nameStudent, | |
uint256 _note | |
) public { | |
uint256 idStudent = getStudentFromName(_nameStudent); | |
require( | |
msg.sender == teachers[_course], | |
"you re not the teacher of this student course" | |
); | |
if (stringsEquals(_course, "biology")) { | |
students[idStudent].noteBiology = _note; | |
} else if (stringsEquals(_course, "maths")) { | |
students[idStudent].noteMaths = _note; | |
} else if (stringsEquals(_course, "french")) { | |
students[idStudent].noteFr = _note; | |
} else { | |
revert("type a real course"); | |
} | |
} | |
function calculateMoyennePerCourse(string memory _course) | |
public | |
view | |
returns (uint256) | |
{ | |
require( | |
msg.sender == teachers[_course], | |
"you're not the teacher of this class course" | |
); | |
uint256 totalNote; | |
uint256 totalStudent; | |
switch () | |
for (uint256 i = 0; i < students.length; i++) { | |
if (stringsEquals(_course, "biology")) { | |
totalNote += students[i].noteBiology; | |
totalStudent += 1; | |
} | |
if (stringsEquals(_course, "maths")) { | |
totalNote += students[i].noteMaths; | |
totalStudent += 1; | |
} | |
if (stringsEquals(_course, "french")) { | |
totalNote += students[i].noteFr; | |
totalStudent += 1; | |
} | |
} | |
uint256 moyenne = (totalNote * 100) / totalStudent; | |
return moyenne; | |
} | |
function calculateMoyenneStudent(string memory _name) | |
public | |
view | |
onlyOwner | |
returns (uint256) | |
{ | |
uint256 idStudent = getStudentFromName(_name); | |
return | |
((students[idStudent].noteBiology + | |
students[idStudent].noteMaths + | |
students[idStudent].noteFr) * 100) / 3; | |
} | |
function isPassing(string memory _name) | |
public | |
view | |
onlyOwner | |
returns (bool) | |
{ | |
return calculateMoyenneStudent(_name) >= 10; | |
} | |
function calculateMoyenneGenerale() | |
public | |
view | |
onlyOwner | |
returns (uint256) | |
{ | |
uint256 totalNote; | |
uint256 totalStudent; | |
for (uint256 i = 0; i < students.length; i++) { | |
totalNote += | |
students[i].noteBiology + | |
students[i].noteMaths + | |
students[i].noteFr; | |
totalStudent += 3; | |
} | |
return totalNote / totalStudent; | |
} | |
} |
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 Notes is Ownable { | |
struct Student { | |
string name; | |
string class; | |
address addr; | |
uint256 noteBiology; | |
uint256 noteMaths; | |
uint256 noteFr; | |
} | |
Student[] private students; | |
// class => course => address | |
mapping(string => mapping(string => address)) teachers; | |
event studentAdded(string _name, string _class, address _addr); | |
event teacherAdded(string _class, string _course, address _addr); | |
function addStudent( | |
string memory _name, | |
string memory _class, | |
address _addr | |
) public onlyOwner { | |
students.push(Student(_name, _class, _addr, 0, 0, 0)); | |
emit studentAdded(_name, _class, _addr); | |
} | |
function setTeacher( | |
string memory _class, | |
string memory _course, | |
address _addr | |
) public onlyOwner { | |
teachers[_class][_course] = _addr; | |
emit teacherAdded(_class, _course, _addr); | |
} | |
function getStudentFromName(string memory _name) | |
private | |
view | |
returns (uint256) | |
{ | |
for (uint256 i = 0; i < students.length; i++) { | |
if ( | |
keccak256(abi.encodePacked(students[i].name)) == | |
keccak256(abi.encodePacked(_name)) | |
) { | |
return i; | |
} | |
} | |
return 0; | |
} | |
function stringsEquals(string memory _string1, string memory _string2) | |
private | |
pure | |
returns (bool) | |
{ | |
bool test; | |
if ( | |
keccak256(abi.encodePacked(_string1)) == | |
keccak256(abi.encodePacked(_string2)) | |
) { | |
test = true; | |
} | |
return test; | |
} | |
function setNote( | |
string memory _course, | |
string memory _nameStudent, | |
uint256 _note | |
) public { | |
uint256 idStudent = getStudentFromName(_nameStudent); | |
require( | |
msg.sender == teachers[students[idStudent].class][_course], | |
"you re not the teacher of this student course" | |
); | |
if (stringsEquals(_course, "biology")) { | |
students[idStudent].noteBiology = _note; | |
} else if (stringsEquals(_course, "maths")) { | |
students[idStudent].noteMaths = _note; | |
} else if (stringsEquals(_course, "french")) { | |
students[idStudent].noteFr = _note; | |
} else { | |
revert("type a real course"); | |
} | |
} | |
function calculateMoyennePerCourse( | |
string memory _class, | |
string memory _course | |
) public view returns (uint256) { | |
require( | |
msg.sender == teachers[_class][_course], | |
"you're not the teacher of this class course" | |
); | |
uint256 totalNote; | |
uint256 totalStudent; | |
for (uint256 i = 0; i < students.length; i++) { | |
if (stringsEquals(_class, students[i].class)) { | |
if (stringsEquals(_course, "biology")) { | |
totalNote += students[i].noteBiology; | |
totalStudent += 1; | |
} | |
if (stringsEquals(_course, "maths")) { | |
totalNote += students[i].noteMaths; | |
totalStudent += 1; | |
} | |
if (stringsEquals(_course, "french")) { | |
totalNote += students[i].noteFr; | |
totalStudent += 1; | |
} | |
} | |
} | |
uint256 moyenne = (totalNote * 100) / totalStudent; | |
return moyenne; | |
} | |
function calculateMoyenneStudent(string memory _name) | |
public | |
view | |
onlyOwner | |
returns (uint256) | |
{ | |
uint256 idStudent = getStudentFromName(_name); | |
return | |
(students[idStudent].noteBiology + | |
students[idStudent].noteMaths + | |
students[idStudent].noteFr) / 3; | |
} | |
function isPassing(string memory _name) | |
public | |
view | |
onlyOwner | |
returns (bool) | |
{ | |
if (calculateMoyenneStudent(_name) >= 10) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function calculateMoyenneGenerale(string memory _class) | |
public | |
view | |
onlyOwner | |
returns (uint256) | |
{ | |
uint256 totalNote; | |
uint256 totalStudent; | |
for (uint256 i = 0; i < students.length; i++) { | |
if (stringsEquals(_class, students[i].class)) { | |
totalNote += | |
students[i].noteBiology + | |
students[i].noteMaths + | |
students[i].noteFr; | |
totalStudent += 3; | |
} | |
} | |
return totalNote / totalStudent; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment