TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

March 28, 2024, 08:16:07 AM

Login with username, password and session length
Members
Stats
  • Total Posts: 195,104
  • Total Topics: 21,212
  • Online today: 151
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 153
  • Total: 154
  • tino

Arcade Games Block

Started by eeek, September 09, 2006, 07:51:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

eeek

Heres some code for a block to display some games from the arcade.

Copy/paste the code in to a phpblock and uncomment the query you want to use, or add 5 blocks, or chop it up to display them all in one block :)

Includes queries for -
Latest games
Most played games (one score versions only)
Least played games (one score versions only)
Best rated games
Longest champ games

global $scripturl,$db_prefix,$modSettings;

//number of games to show
$no=10;

echo '<div align="center">
<table cellpadding="2" cellspacing="5">
<tr>';

//uncomment the query you want to use below

//show the latest games
/*
$sql = "SELECT * "
. "FROM {$db_prefix}games "
. "ORDER BY id DESC , name ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);
*/

//show most played games (one score version only)
/*
$sql = "SELECT * "
. "FROM {$db_prefix}games "
. "ORDER BY plays DESC , name ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);
*/

//show least played games (one score version only)
/*
$sql = "SELECT * "
. "FROM {$db_prefix}games "
. "ORDER BY plays ASC , name ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);
*/

//show best rated games
/*
$sql = "SELECT * "
. "FROM {$db_prefix}games "
. "ORDER BY rating DESC , name ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);
*/

//games with longest champs

$sql = "SELECT * "
. "FROM {$db_prefix}games "
. "ORDER BY champion_time ASC , name ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);





while($game = mysql_fetch_array($result))
{
echo'
<td>
<a href="'.$scripturl.'?action=arcade;sa=play;game='.$game['id'].'">
<img src="'.$modSettings['arcade_games_url'].'/'.$game['game'].'.gif" border="0" alt="'.$game['name'].'" width="60" height="60" title="'.$game['name'].'"/></a>
</td>';
}
mysql_free_result($result);

echo '
</tr>
</table></div>';

G6Cad

AH, saw this on a site yesterday, was about to ask how the did that, but i guess this is the answer :)
Thank you eeek :)

Max


IchBin

Very cool! I don't use the arcade myself, but I sure know a lot of others do. Thanks for sharing. I'll go add this to the list in the sticky.

whoesa

Wow cool, thank you very much!  ;)

akulion

very very cool

is there a way to display the names of the people for "longest held titles" ?

Nokonium

Thanks eeek, I like the idea,Ã,  just been having a fiddle with it.

A couple of problems .....

It only displays gif's, some game icons are jpg's.

In a side block the icons don't wrap.

See attached screenshot from IE, in FF & Opera the overflow doesn't move the centre across.

1.3.0RC1+Mods+1Score+2in1, TP 0.95 beta & 1.1 RC3

eeek

#7
Quoteis there a way to display the names of the people for "longest held titles" ?

Theres always a way :) and it aint that difficult but thats the one that costs the most overhead, the way it is just now its 1 query.  If you want usernames then for 10 games it costs at least 10 more queries every time the page loads and gives you info that is in the statistics page if anyone really wanted to see it. Without going off on a tangent here..this info like champ name, thumbnail and anything else that requires processing should be added to the table when the info is created -process once instead of everytime its needed - the table would be bigger but the arcade would be more efficient.

Its easy to add anything thats in the "Games" table at no extra cost though like Highest Score or in the one score version Number of Plays. To have it display on mouse over modify the title tag in the code like
title="'.$game['name'].' played'.$game['plays'].' times'"
title="'.$game['name'].' - score to beat'.$game['champion_score'].' are you up to it? '"


QuoteIt only displays gif's, some game icons are jpg's.

All mine are gifs :) the easy answer rename them to gif Im sure it will work.

QuoteIn a side block the icons don't wrap.

I have it in a center block :) You want them to stack one wide move the <tr> and </tr> inside the while loop, html aint my strong point :)

The next plan is to make it random, using all the choices so each time you get something different, like latest games, champs, rated etc.

Nokonium

I think for a sideblock the best compromise is to limit the number to 2. Don't know if that was the intention, but the icons didn't have the game name displaying, so I had a fiddle.

This is the code I have for a side block and attached is the screenshot.

global $scripturl,$db_prefix,$modSettings;

//number of games to show
$no=2;

echo '<div class="smalltext" align="center" valign="top">
<table cellpadding="2" cellspacing="5">
<tr>';

//uncomment the query you want to use below

//show the latest games
/*
$sql = "SELECT * "
. "FROM {$db_prefix}games "
. "ORDER BY id DESC , name ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);
*/

//show most played games (one score version only)

$sql = "SELECT * "
. "FROM {$db_prefix}games "
. "ORDER BY plays DESC , name ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);


//show least played games (one score version only)
/*
$sql = "SELECT * "
. "FROM {$db_prefix}games "
. "ORDER BY plays ASC , name ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);
*/

//show best rated games
/*
$sql = "SELECT * "
. "FROM {$db_prefix}games "
. "ORDER BY rating DESC , name ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);
*/

//games with longest champs
/*
$sql = "SELECT * "
. "FROM {$db_prefix}games "
. "ORDER BY champion_time ASC , name ASC LIMIT 0,{$no}";
$result = db_query($sql,__FILE__,__LINE__);
*/




while($game = mysql_fetch_array($result))
{
echo'
<td>
<a href="'.$scripturl.'?action=arcade;sa=play;game='.$game['id'].'">
<img src="'.$modSettings['arcade_games_url'].'/'.$game['game'].'.gif" border="0" alt="'.$game['name'].'" width="60" height="60" /></a><br />
<a href="'.$scripturl.'?action=arcade;sa=play;game='.$game['id'].'">'.$game['name'].'</a>
</td>';
}
mysql_free_result($result);

echo '
</tr>
</table></div>';

eeek

#9
Ok fiddlers heres Version 2 :)

All the choices in one block. it will pick a random choice of which one to display. <- its random so you might get the same one twice in a row!!

copy all the code below to one phpblock

---------------------------
see next post :)