[java] Say-Ving-the -game

Started by
13 comments, last by lupine 22 years, 2 months ago
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.
"do you like my helmut?"-yoghurt
Advertisement
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
"There is no reason good should not triumph at least as often as evil. The triumph of anything is a matter of organization. If there are such things as angels, I hope that they're organized along the lines of the mafia." -Kurt Vonnegut
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
ujhkfkfk
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.
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.
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
"do you like my helmut?"-yoghurt
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
------------------------------
"There is no reason good should not triumph at least as often as evil. The triumph of anything is a matter of organization. If there are such things as angels, I hope that they're organized along the lines of the mafia." -Kurt Vonnegut
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.

"do you like my helmut?"-yoghurt
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
------------------------------
"There is no reason good should not triumph at least as often as evil. The triumph of anything is a matter of organization. If there are such things as angels, I hope that they're organized along the lines of the mafia." -Kurt Vonnegut
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!

This topic is closed to new replies.

Advertisement