-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoodleJump.sol
54 lines (43 loc) · 1.74 KB
/
doodleJump.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
pragma solidity ^0.8.7;
contract doodleJump{
mapping (address => uint) highscore;
mapping (address => bool) dead;
mapping (address => bool) inGame;
function setHighScore(uint hs) public {
require( !dead[msg.sender], "the account of this character is dead");
require( inGame[msg.sender], "this account is not in a game");
if(highscore[msg.sender] < hs){
highscore[msg.sender] = hs;
}
inGame[msg.sender] = false;
}
function getHighScore() public view returns (uint){
return (highscore[msg.sender]);
}
function die() public {
require( inGame[msg.sender], "this account is not in a game");
require( !dead[msg.sender], "the character of this account is already dead");
dead[msg.sender] = true;
}
function startGame() public {
require( !dead[msg.sender], "the character of this account is dead");
require( !inGame[msg.sender], "this account is already in a game");
inGame[msg.sender] = true;
}
function getValue() public view returns (uint, uint, uint){
require( !dead[msg.sender], "the account of this character is dead");
return (random(255), random1(255), random2(255));
}
function isDead() public view returns(bool){
return dead[msg.sender];
}
function random(uint number) public view returns(uint){
return (uint(keccak256(abi.encodePacked(msg.sender)))%10000)*3 % number;
}
function random1(uint number) public view returns(uint){
return (uint(keccak256(abi.encodePacked(msg.sender)))%10000)*2 % number;
}
function random2(uint number) public view returns(uint){
return uint(keccak256(abi.encodePacked(msg.sender))) % number;
}
}