Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Running several games based on the same code  (Read 1233 times)
0 Members and 1 Guest are viewing this topic.
Offline Mike

JGO Ninja


Medals: 71
Projects: 1
Exp: 5 years


Java guru wanabee


« Posted 2013-05-01 22:46:58 »

This is more of a code design than a game design question, but I didn't know where else to post it. Please feel free to move it somewhere if you see the need.

I posted a question in the State of Fortune thread, but a wise man pointed out that people don't look at the thread for generic questions, and therefore this thread is created.

What is the best way forward (from a time/code point of view as well as maintainability) when one has two versions of the same game running, where a lot of the code is shared, but many functions are different?

Should one:
Make a copy of the current projects (client and server) and build on top of that?
  • Positive: Easy to separate the projects, the jar for the sandbox will download quicker as it doesn't contain the game content
  • Negative: If one fixes something generic one will need to change both versions. Big refactorings needs to be done to both versions separately. Will need a launcher client where you can choose which version to start up

Extend the current classes where necessary and make a game version of them, only overwriting where necessary?
  • Positive: Cleaner code
  • Negative: I don't know if my programming skills are good enough to keep it organized Smiley

Split the game code completely away from the engine code and let the game know where it can inject code?
  • Positive: Cleanest code
  • Negative: I really don't know if my programming skills are good enough to keep it organized Smiley A lot of work to keep the game code separate

Add cases to the code based upon which game version one is playing?
  • Positive: Quick win
  • Negative: Messy code

Something obvious that I didn't think of? Smiley

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2013-05-01 23:17:24 »

We've got 4 games based off of the same framework. It's a pain maintaining it as a tweak for one game means having to be extra careful not to break the other 3, or more usually, having to do something to all 4 games. It sounds like a drag but it's not nearly as much of a drag as fixing a bug in one version of the framework and forgetting to do it in the other 3, and it subsequently surfacing again months later...

Cas Smiley

Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #2 - Posted 2013-05-01 23:17:41 »

Create 3 projects: Project A, Project B, and Commons.

Put all the common stuff in commons, and add it to the classpath of both the projects.


You just need to make sure that commons doesn't depend on any code in the other projects, and that commons doesn't actually run any part of the game, which may require some refactoring.

You don't neccessarily have to extend, but in some cases it may be a good idea.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mike

JGO Ninja


Medals: 71
Projects: 1
Exp: 5 years


Java guru wanabee


« Reply #3 - Posted 2013-05-01 23:41:08 »

Right, creating separate projects and adding the common one in the classpath sounds good (and is probably what Cas meant too, but with a twice of experience, which is very nice Smiley)

So, to put it in a simple example that I can comprehend with my limited OO knowledge Smiley
Say that I have a project "Common" with a method called "build" and now I want game A (in project "A") to have a couple of extra checks (not only can you not build where there is already a block, but you can only build on your own land). I would then extend the Block class in project Common and overwrite the method "build" and add another check (if (getOwner(p)==you) before calling the build method in the superclass which does the original tests. I'd then overwrite all of the block classes (each block type is one class) and make them extend the new version instead of the copied version, and overwrite the method that add blocks, so it adds the new block types instead of the original ones... starting to sound messy Wink

Does that sound about right? It sounds like a lot of maintenance, but I think that it will make it flexible enough and make fixing bugs in the common project automatically fix them in both versions.

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline cubemaster21
« Reply #4 - Posted 2013-05-01 23:51:31 »

I personally would only use shared/same code on methods that I know will be constant, like math. Anything with different methods like that I would code specifically for that project.

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline 65K
« Reply #5 - Posted 2013-05-02 08:26:55 »

The cleanest approach would be based on 3 layers:
1. foundation - independent of concrete games as well as of game types (like the fashionable block-builder here)
2. game type or domain layer - anything related to the world of blocks
3. the games

Be sure to set up seperate projects to avoid unwanted dependencies lingering in your code base.
Class extension and overriding methods is the obvious way, though not the most flexible. Instead, get familiar with object composition and interfaces.

Offline Mike

JGO Ninja


Medals: 71
Projects: 1
Exp: 5 years


Java guru wanabee


« Reply #6 - Posted 2013-05-02 22:08:34 »

Okay, that makes sense. Unless someone else has an idea there doesn't seem to be a correct answer so I think I'll play around a bit with the different options and try to come up with what fits me the best Smiley

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (15 views)
2014-07-29 18:09:19

Riven (10 views)
2014-07-29 18:08:52

Dwinin (10 views)
2014-07-29 10:59:34

E.R. Fleming (28 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (40 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!