The eliminate() method

The game logic enables a player to eliminate another unlucky opponent by triggering the eliminate() method, which we define as follows:

function eliminate(address PlayerAddress) external  returns(bool) {
require(now > ping_time[PlayerAddress] + 1 days);
delete Tpension[PlayerAddress];
delete active_players[Tplayer.getplayer(PlayerAddress).id];
Lindex -= Tplayer.getplayer(PlayerAddress).id;
eliminated_players.push(Tplayer.getplayer(PlayerAddress));
Tplayer.EditPlayer(msg.sender, 0);
share_pension(PlayerAddress);
emit eliminatedPlayerEv(PlayerAddress);
return true;
}

Take a close look, and I’m sure you’ll make sense of this code.

The require(now > ping_time[PlayerAddress] + 1 days); line ensures that we can eliminate only players who didn’t ping the contract within the last 24 hours.

This function will remove the eliminated player from the active player list (active_players) and move it to the eliminated player list (eliminated_players.push). Then we set the player's ID to zero as it has been removed from the active player list. Afterward, we call share_pension(), which will share the balance of the eliminated player between the remaining active players. We end by firing an event, declaring the elimination of the player.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset