Slackwolf\Game\Formatter\RoleSummaryFormatter::format PHP Method

format() public static method

public static format ( array $players, array $originalPlayers ) : string
$players array
$originalPlayers array
return string
    public static function format(array $players, array $originalPlayers)
    {
        $roleSummary = "";
        foreach ($originalPlayers as $og) {
            $roleSummary .= "@{$og->getUsername()} ({$og->role->getName()}) - ";
            if (isset($players[$og->getId()])) {
                $roleSummary .= ":white_check_mark:\r\n";
            } else {
                $roleSummary .= ":x:\r\n";
            }
        }
        return $roleSummary;
    }

Usage Example

Beispiel #1
0
 public function endGame($id, $enderUserId = null)
 {
     $game = $this->getGame($id);
     if (!$game) {
         return;
     }
     $playerList = RoleSummaryFormatter::format($game->getPlayers(), $game->getOriginalPlayers());
     $client = $this->client;
     $winningTeam = $game->whoWon();
     if ($winningTeam !== null) {
         $winMsg = ":clipboard: Role Summary\r\n--------------------------------------------------------------\r\n{$playerList}\r\n\r\n:tada: The game is over. The ";
         if ($winningTeam == Role::VILLAGER) {
             $winMsg .= "Townsfolk ";
         } elseif ($winningTeam == Role::WEREWOLF) {
             $winMsg .= "Werewolves ";
         } else {
             $winMsg .= "UnknownTeam ";
         }
         $winMsg .= "are victorious!";
         $client->getChannelGroupOrDMByID($id)->then(function (Channel $channel) use($client, $playerList, $winMsg) {
             $client->send($winMsg, $channel);
         });
     }
     unset($this->games[$id]);
     if ($enderUserId !== null) {
         $client->getChannelGroupOrDMByID($id)->then(function (Channel $channel) use($client, $playerList, $enderUserId) {
             $client->getUserById($enderUserId)->then(function (\Slack\User $user) use($client, $playerList, $channel) {
                 $client->send(":triangular_flag_on_post: The game was ended by @{$user->getUsername()}.\r\n\r\nRole Summary:\r\n----------------\r\n{$playerList}", $channel);
             });
         });
     }
 }
All Usage Examples Of Slackwolf\Game\Formatter\RoleSummaryFormatter::format
RoleSummaryFormatter