PDA

View Full Version : Saving Scores From Java Games



keith10456
04-09-2006, 12:27 AM
I'm a member of the Activity Mod forum (http://phpbb-amod.com). More or less, its a php open source community that allows individuals to have an arcade on their website - in which their members can play online games for free.

Just about all of the games are flash. The problem is, I came across some java games that their php script can use, but none of the members know how to decompile the java games (and/or know what programs to use).

Basically, the php script saves the game's data (username, score, etc.) to an SQL database.

An example of the the games we're trying to use is:

http://morrisania.com/test/SolitaireGames/calculation.html

(from http://www.idiotsdelight.net/)

If you need me to provide you with the files, etc. from the Java game let me know.

Below are instructions that were given a while back, but like I said, we're still at a lost - (where to put it, etc). Any and all help will be greatly appreciated - you will be contributing to an wonderful project.

-------------------------------


<FORM NAME="game" ACTION="{S_GAME_ACTION}" METHOD="post">
<INPUT TYPE="hidden" NAME="name" VALUE="{USERNAME}">
<INPUT TYPE="hidden" NAME="score" VALUE=0>
</FORM>
This should go in your template file, it's a small form that will hold the info needed for the username and score to be submitted into the newscore.php file. You then include this function in the java source. Code:
function updatescore()
{
document.game.name.value = user_name;
document.game.score.value = score;
document.game.submit();
}

and include it with your game over routine. Replace score with what ever your game is using for the score variable. Example :: MyGamescore = 3777; so I would change Code:
document.game.score.value = score;

toCode:
document.game.score.value = MyGamescore;

Twey
04-09-2006, 07:51 AM
To access the Java variable containing the score, a) you must know the name of the variable, and b) it must be a public property of the main Applet or JApplet (or similar) class. Then, if you want to access it from Javascript, you could use, where "gameApplet" is the ID of the game <applet>/<object>/<embed> and "score" is the name of the score property:
document.getElementById("gameApplet").scoreHere we see that the applet extends jsolitaire.shared.Solitaire:
public class Calculation extends SolitaireThen comes the bad news. In jsolitaire.shared.Solitaire we find the line:
protected int gamesPlayed = 0, gamesWon = 0; You can't access these variables, because they aren't public. You must make them public before you can access them from Javascript.

keith10456
04-11-2006, 05:59 PM
This may come-off as a stupid question but, how exactly did you look inside of the game to see the code?

Twey
04-11-2006, 07:15 PM
Well, if you will leave the source in the same directory as the applet, and give it the same filename with a .java extension... :)
There are Java decompilers available, however. The code they generate isn't always the easiest to read, though, as some cosmetic data tends to be lost (such as the names of private members, for example).

Oh, I forgot to mention in my last post that anything that gets processed by Javascript can easily be edited, even by a user of the lowest class. The best idea would be to have the applet request the server-side page directly (which it can do without requesting permission, so long as the page is on the same server the applet was served from), although that's still not totally secure. In the same vein, I wouldn't actually recommend making the property public at all, now I come to think of it. Rather, a public getter method would be better recommended.

keith10456
04-11-2006, 07:49 PM
Thanks Twey... More questions to come - I'm sure.



In case anyone is interested, here is a free Java Decompiler I found:

http://www.download.com/DJ-Java-Decompiler/3000-2417-10046809.html?part=dl-DJJavaDec&subj=dl&tag=button

(from site: http://members.fortunecity.com/neshkov/dj.html#)

keith10456
04-11-2006, 08:16 PM
I have to admit... I'm in over my head here :(

If anyone would like to help us (http://phpbb-amod.com/main.html) (specific topic on Forum (http://phpbb-amod.com/topics.html-t-2380)) by doing this - or doing one so we can duplicate it - it would be greatly appreciated.

This link (http://morrisania.com/test/JSolitaireGames.zip) will give you the complete download of the games. Unfortunately, a link to my website is still on some of the HTML pages... I just copied the whole thing from a 2002 version of my site - that's when I used to have these games on there. Sorry for the laziness...

In any event... The IdiotsDelight (http://www.idiotsdelight.net/) website contains an updated version of the games.

Thanks in advance...