I wrote my first game this summer in java and I decided to call it Ultimate Pong - you will see why if you play it :). You can check it out at http://www.ultimatepong.net and I would love any feedback you guys might have. Right now I have run into a big problem that has me stumped. My goal is to create a score database that is fed with data from the applet that runs the game. All I need to do is pull 4 instance variable values out and into another object (I was thinking a record object) to be inserted into the database. Each person who comes to the site would be given the option to register and log in with a username/password and their top score would be kept in the database so they can see how they rank with everyone else who has played. After each game is over their data would be exported and checked versus the current value in the database and if the new score is higher than the old, then it would be updated and the database resorted. My problem right now is that whenever I try to stream data out of the applet a data access exception is thrown and the program terminates. I have done some research and it looks like this can be accomplished with a custom policy file, but that would only be for writing to each individual player’s disk and it would have to be updated for each person. I just want it to stream out an ObjectStream to my webserver and then import the data back into another applet which runs the database. Anyone have any input on how I might accomplish this? From my research it looks like it may also be possible through a CGI script but I have no experience with CGI programming and would need some major help. Please let me know if you know of any way I can get this done!
Applets and webstarted applications are allowed to connect to the server they came from (connecting to other servers or read/writing local files needs a permission [signing]).
The server can’t run an applet. Applets are small things embedded into html pages, which are loaded and executed by clients, passing by.
However, you can run other things on the server. Java server pages for example (but most likely that won’t be an option for you). So… what left? CGI - duh… asp - hmm… and ok php. Php is almost everywere available (as long as you’ve paid for the webspace). Together with some mySQL it’s pretty easy to implement some kind of highscore upload (you can also use flat files, but it’s really much easier with some kind of data base).
So… long story short: once you’ve got the data you need you send a http 1.0 or 1.1 request to a serversided script file eg something like: http://www.youdomain.tld/games/pong/hi.php?name=bla&score=234
That’s it basically.
Thanks for the help! I am still trying to figure out how to get the data I need, and how exactly would I use mySQL to do this request to a serversided script file? The biggest problem right now is extracting the data from the applet in any usable form. Unfortunately I have no experience with mySQL, CGI, or script files so I am not sure exactly what you are talking about. If you could elaborate that would be great or point me to a website that has some info I can read up on.
how exactly would I use mySQL to do this request to a serversided script file?
Uhm… well ok I’ll try to explain that better.
-
You get the data you want to insert. That is running the game, calculating the score and ask the user for his name. (So one int and a String for example).
-
You etablish a tcp connection and send some stuff over the line (http request - port 80). You basically request a specific file from the server and the data you want to submit is just a part of the so called query string (everything after the questionmark).
-
Now on the server side you have a php file (eg hi.php), which is the file which has been requested by your application (or applet) from the server. The funny thing with php is that it gets parsed (serversided) each time it’s requested (so whenever you upload a highscore). So basically you run a small programm now on the server.
-
In that php file you collect the data from the query string (and encapsulate it with addslashes() for security reasons) and then you do some sql stuff with that stuff you’ve just fished out of the query string. Just an insert actually.
-
The highscore table for example (on your page) can be just another php file, which takes the info out of the data base each time it’s requested by a browser.
-
And of course you can do some kind of plaintext highscore table, which gets requested by your application (or applet). That’s basically the same thing as #2, but you’ll need to listen to the stuff you get back from the server (in the first case [2] it wasn’t really necessary, but it’s bad style if you just ignore eventual problems).
I hope it’s now somewhat clear (on a conceptual level). However, you’ll need webspace with supports php and mysql (if possible). And a local server (in your local network) helps alot doing/testing that kind of stuff.
An excellent (free) package of all stuff you’ll need (apache, php, mysql etc) can be found here:
http://www.apachefriends.org/en/xampp.html
With that package it’s a matter of 5 minutes to setup a fully functional webserver
Fortunately my server is fully functional and it has mySQL and php capabilities. The thing I am still kind of fuzzy on is how exactly I will get the data out of the applet, what medium will I use. Are there classes in the standard library that I can use in my applet that can setup the tcp connection to send the data out to the webserver? http://www.ultimatepong.net/pong.php?name=bla&score=234 using this as a hypothetical example how do I setup the applet to request pong.php once it is created? Thanks again for your help!
This should do it.
getAppletContext().showDocument(new URL(getCodeBase() + "pong.php?name="+ nameVar +"&score=" + pointsVar));
The game is nice, some years ago we made a similar project for a client (only in C++) for a 4-player multiplayer pong/arkanoid clone (Noid Arena was called).
Was really nice.
Yours is just nicer because you have to to control 4 paddles at once! Cool.
A great example of a simple concept made new by adding spatial complexity.
Thank you everyone for your help! I got the database working last night, if you would like to check it out just visit the site http://www.ultimatepong.net
Damn that’s a hard game to control
[quote]Damn that’s a hard game to control
[/quote]
naaaahh. just follow the ball with the cursor and react fast…