my java world project

Hello,

I’m not very articulate but I will try my best to describe what I’m trying to do.

I’m trying to build a world in java, a world where I can work on pieces/objects (by coding on underlying attributes and/or behaviour) and plug them in (at any time) and watch their interactions which each other.

I intend for my movable “objects” to need only the most basic underlying properties like position / speed / health & temperment.
(temperment being the thing I would adjust differently with different object types)

Once created, I don’t want to ‘stop’ the world (ie: recompile etc), but I want the ability to work on new objects at a later date and introduce them when I want. I want to leave my world on always (24/7) and in the meantime, when I code up new ‘things’ I can introduce them somehow to the world and let them roam free…

I don’t want fancy graphics.
No intention for any network stuff or anything like that. (actual intention is more of a personal petri-dish. :wink: )
The ‘world’ can be a simple black jframe/jpanel.
Object will be a represented graphicly by a single moving pixel. (different object types to be different colours)
I want it to be turn-based, so an engine/heartbeart simply lets each ‘object’ take it’s turn.
I also need some type of textfield or flat-file that logs events… (for when interactions occur when I’m asleep)
Other than the ‘world’ panel, I need some open-file dialog? or some component as a facility to 'introduce new objects… (or maybe just use a menuitem to a dialog?)

Anyway… that above isn’t too hard to figure out…

…which brings me to the crux of my problem:

What I don’t understand is how I would design the infrastructure to ‘load’ new obejcts into my ‘world’ once the world is running… I don’t know how, or even if I can do this??

If I get you right, you want to dynamicly load java-code / classes at runtime? I’m not into that, but I think I can give you some pointers: The java ClassLoader provides methods for loading classes at runtime. After loading a class you use a concept called reflection to access members and methods of the loaded class. I’d suggest to write an interface that all objects implement, so you can load them, cast them to that interface and call the interface-methods to move / place / whatever the object.

If I got you wrong and you just want to load objects with different properties (not behaviour), then you should just write conifg-files for those objects and load these.

What you also could do is to make a regular backup of the complete world state. To introduce new objects you would just save the world-state, recompile and restart your project, and reload the world-state again. Even if you don’t want to introduce objects this way, a regular backup is important, as you don’t want to loose the evolution of your 24/7 world just because of a bug in the code or something :slight_smile:

Ok, thanks for the tip Noya.
I will look into some examples on ‘Reflection’ and try to code something up.