Archived

This topic is now archived and is closed to further replies.

lupine

[java] Say-Ving-the -game

Recommended Posts

OK Ive been working on an RPG for a few years now i have an issue. Saving the game. I am working in Java 1.1 how to , just in general, read a files values into ints and and how to write out ints to a file ? Now for the more tricker part, People will be playing this in their browser and will need to save the game on the server. any Ideas? as always thanks for your meaningful advice.

Share this post


Link to post
Share on other sites
quote:
Original post by lupine
I am working in Java 1.1
how to , just in general, read a files values into ints and and how to write out ints to a file ?


I like to use java.io.DataInputStream / OutputStream. Makes reading and writing basic datatypes simple (int i = instream.readInt(); outstream.writeInt(i); )

quote:

People will be playing this in their browser and
will need to save the game on the server. any Ideas?



As you probably know, you can't write to a file from an applet. So you need to set up a script, Servlet, JSP, ASP, PHP, CGI, or whatever on the server that can receive the data from the applet.

"So crucify the ego, before it's far too late. To leave behind this place so negative and blind and cynical, and you will come to find that we are all one mind. Capable of all that's imagined and all conceivable."
- Tool
------------------------------


Edited by - wayfarerx on January 15, 2002 4:33:24 PM

Share this post


Link to post
Share on other sites
You could write some load and save methods using DataInputStream and DataOutputStreams. But that is quite slow.

The fastest way is to place all of the data into a data Object and implement serializable. Then just us an ObjectInputStream / ObjectOutputStream to read and write the object in one method call.

The reason it is faster is I suspect that the java object stream class use's native calls.

:-)

Edited by - Chaoslab on January 15, 2002 5:09:03 PM

Share this post


Link to post
Share on other sites
I have started several RPG''s myself but never completely finished them. I seem to like the aproach of using a database. By doing so you can use the JDBC to not necessarily save a character, but update his or her profile if you get my meaning.

I am assuming it is a multi-player game, and if it is not using a db would seem the easiest way to make it so.

I''ve also noticed that game balancing is much easier as you can make back end tools out of just about anything as long as you are using an ODBC compliant database. The only concern you might have is security, but depending on your database it might not be.

But this is my $0.02 I have never made an RPG or even started work on one in Java, but have gotten pretty far on them in several other languages.


The cowboys have a way of trussing up a steer or a pugnacious bronco
which fixes the brute so that it can neither move nor think. This is the
hog-tie, and it is what Euclid did to geometry.


War doesn''t determine who is right, war determines who is left.

Share this post


Link to post
Share on other sites
Hmm, I like chaoslab''s idea of one data object. You could make a PersistantGameState class and have some static methods in there, load/save. The class should be able to collect all the relevant info about the game and store it inside itself, maybe in a hash. Here''s the tricky part, if you write a servlet on your server, you can just use streams to write the object to the network, read it in and save it on the servlet side. If you don''t use servlet, say you use php, then you will need to write data that php can read. Best bet is to use XML-RPC if you have two different languages, object serialization if it''s all java. Once the data is on the server you can save it anyway you want.

Share this post


Link to post
Share on other sites
wow! thank you all for your concise answers

Let me see if I understand the solution.

the applet will act as the "client side" of the conversation

and send a stream (ObjectInputStream / ObjectOutputStream)

via tcp/ip

to the servlet which is the "server side" of the conversation

the data coming in will be a stream and the servlet will need

to format the data to a file (like .txt) ?????

With these assumptions I will go to the black book and see if

I can map out the process. Im sure I will come back with

some questions on formating.

Please correct me on the above if I am wrong.


I owe you all for this one. thanks

Share this post


Link to post
Share on other sites
quote:
Original post by lupine
the applet will act as the "client side" of the conversation



Yes.

quote:

and send a stream (ObjectInputStream / ObjectOutputStream)

via tcp/ip

to the servlet which is the "server side" of the conversation



This one''s a little fishy, and it really depends on how you can set up your server.

Case #1: you have the ability to run a Java application on the server. In this case you should write a server app that listens for connections and accepts data via the object streams.

Case #2: you can only run things like servlets/ASP/PHP on your server. In this case you can''t use object streams because you have to send data in the http protocall (the protocall your web browser uses).

So let us know what the situation with your server is.

quote:

the data coming in will be a stream and the servlet will need

to format the data to a file (like .txt) ?????



Here I''m going to go with Wrathnut. Using a databse on the back end to store your data is going to be much easier to code. With a flat file (like .txt), you could have 2 users trying to save at the same time, and not both are going to be able to write to the file at once. A database will take care of that for you.


"So crucify the ego, before it''s far too late. To leave behind this place so negative and blind and cynical, and you will come to find that we are all one mind. Capable of all that''s imagined and all conceivable."
- Tool
------------------------------

Share this post


Link to post
Share on other sites
Here is the information:

It will be a linux box under my ownership and control

so I think either 1 or 2 is an option.

1 sounds good to me but I really don''t know

the pro''s and Cons.

I hear you on the Database approach I will read up on that

as well.

Thanks again for your conssideration.

Share this post


Link to post
Share on other sites
If you have your own box then I would definately go with #1.

"So crucify the ego, before it''s far too late. To leave behind this place so negative and blind and cynical, and you will come to find that we are all one mind. Capable of all that''s imagined and all conceivable."
- Tool
------------------------------

Share this post


Link to post
Share on other sites
Actually, option two is very possible and you can send ObjectStreams over http from applets to servlets. This site - http://j-nine.com/pubs/applet2servlet/Applet2Servlet.html - shows all the steps needed to do this. There are also many examples found by searching the forums on Sun''s site.

Hope this helps!

Share this post


Link to post
Share on other sites
Yes you can write ObjectStreams over http, I have done it and like I said it is much faster than writing a DataStream over http because it is one method call opposed to lots, and that''s one native method call!

Trust me, in the first cut of Eldian I wrote load methods that used DataStreams and you have to make sure that the load & save are the same and etc....

It''s a pain in the arse! ObjectStreams are so easy to use and they are really fast, plus you can write to what ever you want http, files what ever!

In The Chaoslab2 I will be used XML for every thing, but for fast performance based data transmission and storage I will be using ObjectStreams as they rock and I wished I had known how to use them when I started Eldian all those years ago.

Share this post


Link to post
Share on other sites
quote:
Original post by Chaoslab
Yes you can write ObjectStreams over http, I have done it and like I said it is much faster than writing a DataStream over http because it is one method call opposed to lots, and that''s one native method call!

Trust me, in the first cut of Eldian I wrote load methods that used DataStreams and you have to make sure that the load & save are the same and etc....

It''s a pain in the arse! ObjectStreams are so easy to use and they are really fast, plus you can write to what ever you want http, files what ever!

In The Chaoslab2 I will be used XML for every thing, but for fast performance based data transmission and storage I will be using ObjectStreams as they rock and I wished I had known how to use them when I started Eldian all those years ago.




I didn''t see it, but is the Source for those games available??

Share this post


Link to post
Share on other sites
No the source is not available for the games....

I will probably place some graphics based source code onto the Chaoslab2 site some time after the new lab has been finished.

Object Streaming is easy and I am quite happy to post some source here if ya need it.

:-)

Share this post


Link to post
Share on other sites