Repository navigation
Expand file tree
/
Copy pathMapChain.sol
More file actions
executable file
·161 lines (127 loc) · 4.07 KB
/
Copy pathMapChain.sol
File metadata and controls
executable file
·161 lines (127 loc) · 4.07 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
pragma solidity ^0.4.0;
contract MapChain {
address player;
address owner;
bool game_status; //true - now leasing; false - now not leasing
uint256 price; //price for 1 step
uint256 balance; //now available
uint256 amountForOwner;
uint256 steps;
uint256 current_steps;
uint256 rating;
uint start;
uint end;
struct Leaser {
uint256 depositToReturn;
//address leaser;
}
mapping(uint256 => string) task; //number_task => task
mapping(address => Leaser) leasers;
function MapChain (uint256 _price, string _task1, string _task2, string _task3) public {
balance=0;
amountForOwner=0;
game_status=false;
owner = msg.sender;
price = _price;
steps = 3;
task[0] = _task1;
task[1] = _task2;
task[2] = _task3;
current_steps = 0;
rating=0;
}
function AddTask (string _task) public {
require(msg.sender==owner);
require(!game_status);
task[steps]=_task;
steps += 1;
}
function joinGame () public payable {
require(msg.value > price);
require(!game_status);
player = msg.sender;
game_status = true;
balance = msg.value;
current_steps = 0;
rating += 1;
start = now;
end = 0;
//add deposit to return of current leaser to balance
balance += releasDeposit(player);
}
function releasDeposit(address _player) private returns (uint256 _deposit) {
Leaser storage _l = leasers[_player];
_deposit = 0;
if (_l.depositToReturn > 0) {
_deposit = _l.depositToReturn;
_l.depositToReturn = 0;
}
}
function stopGame() public {
require(msg.sender==player);
require(game_status);
//increase deposit to return of leaser on unused balance
if (balance > 0) {
Leaser storage _l = leasers[player];
_l.depositToReturn += balance;
balance=0;
}
end = now;
current_steps = 0;
game_status = false;
}
function update_step () public {
require(msg.sender==player);
require(game_status);
require(current_steps<steps);
require(balance>price);
amountForOwner = amountForOwner+price;
balance = balance-price;
current_steps = current_steps+1;
}
function take_amount_owner () public {
require(msg.sender==owner);
require(amountForOwner>0);
owner.transfer(amountForOwner);
amountForOwner=0;
}
function take_deposit_player() public {
uint256 _d = releasDeposit(msg.sender);
if (_d > 0) {
msg.sender.transfer(_d);
balance=0;
}
}
function status_game() public view returns (bool) {
return game_status;
}
function current_balance_player() public view returns (uint256) {
return balance;
}
function current_amount_owner() public view returns (uint256) {
return amountForOwner;
}
function current_step() public view returns (uint256) {
return current_steps;
}
function Rating_game() public view returns (uint256) {
return rating;
}
function Game_time() public view returns (uint) {
if (game_status==true) {
end=now;
}
return end-start;
}
function Task() public view returns (string) {
require (game_status==true);
return task[current_steps];
}
function add_balance () public payable {
require(msg.sender==player);
require(game_status==true);
require(msg.value > 0);
player = msg.sender;
balance += msg.value;
}
}