Daily Lucky Numbers:
3
7
12
24
40
41

Game Block

Started by Chen Zhen, July 06, 2013, 03:02:51 PM

Previous topic - Next topic

Chen Zhen

July 06, 2013, 03:02:51 PM Last Edit: November 21, 2021, 12:05:43 AM by Chen Zhen Reason: updated
Play a game in a PHP portal block

PHP Block Code -
$gameid: represents the game ID (elect a game id number or 0 for random)
$minimum_height: represents a minimum value if a game height is not found in the db
$container_class: css class background (around the game)
$randomReplay: boolean ~ play button selects random game (true) or same game (false)
               
global $scripturl, $boardurl, $txt, $smcFunc;

/* Change $gameid to a specific game id (0 for random) ~ other options are available  */
$included_game_types = array('html5', 'html52', 'html53');
$minimum_height = '700';
$container_class = 'windowbg';
$gameid = 0;
$randomReplay = true;

list($countz, $gameData) = array(array(), array());
$request = $smcFunc['db_query']('', '
SELECT id_game, extra_data, submit_system
FROM {db_prefix}arcade_games
WHERE id_game > {int:idgame} AND enabled = {int:enabled}
ORDER BY id_game ASC',
array(
'idgame' => 0,
'enabled' => 1,
)
);

while ($row = $smcFunc['db_fetch_assoc']($request)) {
if (!in_array($row['submit_system'], $included_game_types))
continue;

$countz[] = $row['id_game'];
$extraData = unserialize($row['extra_data']);
$extraData['height'] = !empty($extraData['height']) ? preg_replace('/[^0-9]/', '', $extraData['height']) : $minimum_height;
$gameData[$row['id_game']] = array('width' => preg_replace('/[^0-9]/', '', $extraData['width']), 'height' => $extraData['height']);
}
$smcFunc['db_free_result']($request);

$arcadeAllGamesArray = json_encode($countz);
$arcadeAllGamesDimsArray = json_encode($gameData);
$randGameId = array_rand($countz);
$requestGameId = isset($_REQUEST['game']) ? abs((int)$_REQUEST['game']) : abs($gameid);
$ranum = !empty($requestGameId) && in_array($requestGameId, $countz) ? $requestGameId : $countz[$randGameId];
$id = 'x_gameblock' . $gameid . $ranum . '_x';
echo  '
<script type="text/javascript">
var arcadeAllGamesArray = ' . $arcadeAllGamesArray . ';
var arcadeAllGamesDimsArray = ' . $arcadeAllGamesDimsArray . ';
function arcadeResizeIframeBlock(idgamex) {
var arcadeIframBlockId = document.getElementById("' . $id . '");
var arcadeIframBlockContId = document.getElementById("arcCont' . $id . '");
arcadeIframBlockContId.style.overflow = "hidden";
arcadeIframBlockContId.style.height = parseInt(arcadeAllGamesDimsArray[idgamex]["height"]) + "px";
arcadeIframBlockContId.style.minHeight = parseInt(arcadeAllGamesDimsArray[idgamex]["height"]) + "px";
arcadeIframBlockContId.style.maxHeight = parseInt(arcadeAllGamesDimsArray[idgamex]["height"]) + "px";
arcadeIframBlockId.style.overflow = "hidden";
arcadeIframBlockId.style.overflow = "hidden";
arcadeIframBlockId.contentDocument.getElementsByTagName("BODY")[0].style = "overflow: hidden;border: 0px;background: npne;";
arcadeIframBlockId.style.visibility = "visible";
}
function arcadeBlockReloadIframeGame() {
var arcadeBlockScrollHeight = document.getElementsByTagName("BODY")[0].scrollHeight;
document.getElementsByTagName("BODY")[0].style.display = "flex";
document.getElementsByTagName("BODY")[0].style.justifyContent = "flex-start";
document.getElementsByTagName("BODY")[0].style.minHeight = arcadeBlockScrollHeight + "px";
document.getElementsByTagName("BODY")[0].style.overflowY = "auto";
document.getElementsByTagName("BODY")[0].style.flex = "1";
document.getElementsByTagName("BODY")[0].style.flexFlow = "column nowrap";
var arcadeIframBlockId = document.getElementById("' . $id . '");
var newRandomArcadeGame = Math.floor(Math.random() * arcadeAllGamesArray.length);
var arcadeBlockRandomReplay = ' . (!empty($randomReplay) ? '1' : '0') . ' == 1 ? arcadeAllGamesArray[newRandomArcadeGame] : ' . $ranum . ';
arcadeIframBlockId.style.visibility = "hidden";
arcadeIframBlockId.src = "' . $scripturl . '?action=arcade;sa=play;pop=1;full=1;game=" + arcadeBlockRandomReplay;
arcadeResizeIframeBlock(arcadeAllGamesArray[newRandomArcadeGame]);
}
if(window.attachEvent)
window.attachEvent("onload", arcadeBlockReloadIframeGame);
else if (window.addEventListener)
window.addEventListener("load", arcadeBlockReloadIframeGame, false);
else
window.onload = arcadeBlockReloadIframeGame();
</script>
<div style="clear: both;margin: 0 auto;width: 100%;overflow: hidden;">
<div style="margin: 0 auto;text-align: center;">
<img onclick="arcadeBlockReloadIframeGame()" src="' . $boardurl . '/Themes/default/images/arc_icons/popup_play_btn.gif" alt="" />
</div>
</div>
<div class="' . $container_class . '" id="arcCont' . $id . '" style="clear: both;margin: 0 auto;display: flex;flex-wrap: wrap;flex-direction: column;height: ' . $gameData[$ranum]['height'] . 'px;min-height: ' . $gameData[$ranum]['height'] . 'px;overflow: hidden;">
<iframe allowtransparency="true" id="' . $id . '" name="' . $id . '" src="#" style="clear: both;border: 0px;flex-grow: 1;overflow: hidden;visibility: hidden;"></iframe>
</div>';
       

showzamani

when can I solve this game job

Chen Zhen


This block has been updated for the latest arcade version.
I took out the option for playing a game by name although I may add that at a later date.
For now it goes by game id# or random.

The game id can also be in the URL using "game" as a parameter which might be useful for a portal page.