Archived

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

Ajatar

[java] Java RPG Question

Recommended Posts

I''m fairly new to Java (I''m working w/1.1) and I was wondering if there are any good (or even bad...) examples of Java RPGs with source code? My basic ''Player'' class is getting pretty stuffed. Right now it seems like it''s inheriting everything and it''s mom and I just wanted to see how others are doing it to make sure I''m messing up too badly. Another thing is deciding what to put in the various ''Entity'' classes (Player & Monster) and the Grafx GUI handling class. I''m going with the ''Actor'' & ''Stage'' setting I''ve played around with in Macromedia Director but programming that gets blurry. Thanks!

Share this post


Link to post
Share on other sites
You may wat to think about deligation if your classes are getting cluttered. Think about it this was each class should do 1 thing and do it well. Your main class would manage all of these items. Events would happen on your actor and thier items, they would also emmit events based on movement and actions.

I know kinda vauge... look up information on deligation class models, it''s like how swing and the new window classes do things ( no you don''t need 1.2+ although inner classes do help ).

Share this post


Link to post
Share on other sites
You might want to try and do some research on object orientated programming. There''s lots of stuff on the web (developer.com for instance). Design Patterns (Gamma/Helm/Johnson/Vissides) is a great book but a little tough for those new to OO. A little reading will give you a better clue on how to construct your object model. I would also suggest planning out, at least in some basic form, your model on paper. You can then see the demands one class might have and perhaps how you could break it up into a less dependent/easier to maintain layout. OO is very tough concept to grasp, but I would suggest taking the time to learn it - its incredibly powerful if you know it well. Also since Java is designed more with OO in mind knowledge of OO will give you a better grasp on the language.

Just a few thoughts. Hope it helps!

Sieggy

Share this post


Link to post
Share on other sites
Sieggy,

I''m kinda at the "shutup and work it" phase... I''ve read a good bit, so I need to work it out, either thru my own code or directly related code. I''m pretty sure I''m gonna make some serious mistakes, but it''s a good way to learn. Basic OOP stuff I understand all the way to polymorphism, but the multiple inheritance model is confusing, since from my understanding I don''t just grab all needed classes w/ included methods. I also don''t understand the need for abstract classes other then for typing. I''m sure about half-way thru it''ll hit me 100 lines too late.

snowmoon,

Actually, I''m using Visual J++ 6.0 which apparently has delegates. This is something I "almost" grasp but just have to work it out also to understand a personal application for it. But I''ve been pretty lucky so far since a game book I just picked up had almost the exact layout I did.

Thanks!

Share this post


Link to post
Share on other sites
Ajatar,

Been there! I worked on for a couple years in C++/MFC an isometric engine and editor. One of the things I discovered was initially when things were relatively simple it went well. Then after a bit the code started to get seriously nasty. I actually scraped the whole thing one time since the spaghetti factor had gotten too large. I basically was your position: new to OO and anxious to get some results.

Point being I see what you saying but do keep an eye out. At some point you may hit the brick wall I did. OO can help you out on that but it does some practice and a lot of planning up front on how you want to do things. You may say "geez why do I have to write all this extra interface code..." but when you do something big, like totally change you graphics engine - and don''t even have to touch your other code you realize how cool it can be.

Going off on a tangent, abstract classes are often used for defining an interface - a set of methods that are in theory constant for a specific task. Your client code references the child class holding the real implementation through its abstract parent.

BaseClass myclass = (BaseClass)ChildClass;

That way, as long as your interface is constant you can swap the child class for another real easily. Delegation is simply an alternative to inheritence since inheritence when not using fully abstract base classes can get messy. The base class the client references is real but it hides the implementation class as a member object:

private ChildClass delcomponent;

public void baseClassFoo()
{
//the client class using this method doesn''t see
//this internal class that holds the true method
delcomponent.realFoo();
}

Anyhow good look and let me know if you need any help or have any questions. Give some of these guys a thought - they can help you out!

Sieggy

Share this post


Link to post
Share on other sites
Sieggy,

Yeah, being able to bust up the graphics & rpg engine is one of the biggest things I''ve thought about. I''m going a really simple (I hope) route and just using the tiles from the old Warlords III game plus some others I found on the old rpgmaker.net site & some I made. They''re PCX so I roamed around and found a freeware PCX java decoder which ended up pretty fast. Also, other then using the lighting animation for background effects, the game will be a standard turned-based RPG.

The way I''m planning it is the whole graphics engine (including actual file names) will be internalized so the rpg engine just sends a string like this: (11 x 11 viewport default)



pic ="XXXXXXXXXXX"+
"X P XXXXX"+
"X M "+
"X E M XXXXX"+
"XXXXXXXXXXX"+
"XXXXXXXXXXX"+
"XXXXXXXXXXX"+
"XXXXXXXXXXX"+
"XXXXXXXXXXX"+
"XXXXXXXXXXX"+
"XXXXXXXXXXX"+
"02|03|ClosedChest"+
"05|02|Ogre"+
"04|03|Minotaur"



And the graphics engine figures the rest. Any non-''P'' or ''X'' will bring up the named graphic. I''m leaving the option open on lettering for debugging issues on that side. Also in case (when!) something comes up I didn''t think about.

The main application will make the two interact. If I don''t like one or the other (hopefully) things are gtg on any changes.

You''re right about hashing things out tho, so I''ve started work on the graphics part and let the other simmer while I re-read & consider more stuff.

Share this post


Link to post
Share on other sites
Hi Ajatar!

I have a couple of advises:

1. Learn OOP! You could save a lot of time and problems if you understand OOP good.
2. I would recomend that you don´t use Strings to store the pic. The implementation could be slow and you will be wasting a lot of memory. Yeah, I know that there is the garbage collector, but if you generate to much garbage you could get into trouble. I once made a class that received some data. Each time I received data (~1/sec) I created a lot of Strings. The garbage collector could not keep up with this! One common suggestion is to use StringBuffer instead of String, which could be a reasonable solution. Another solution is to use a two-dimensional array of for example chars (ex: char[][]).

Good luck with the game!

Regards
Johan

Share this post


Link to post
Share on other sites
Well, I finally decided to post a real *cough* *cough* RPG game on the net.

It was something that me and a couple friends worked on about... 2 years ago.
It''s definitely not fancy (since I did the graphics *ouch*) but you said you wanted something good or bad. Well I''m giving you the choice of bad or bad, take your pick

Anyways, you got the source (which for the game itself if you compile most likely won''t display properly) and you got the class files and possibly an EXE somewhere in there.

Enjoy it, throw it away. It''s just another piece of information that''s collecting virtual dust now.

Smoo

PS It helps if I give you the link to where you can get it:
http://www.angelfire.com/games3/dragonfantasy/
Enjoy.

Share this post


Link to post
Share on other sites