I’m writing a very simple Java Game. Let me describe it briefly:
- There are 4 players in a Map.
- The map is a two-dimensional matrix with a value called “height”
- The height between 2 nodes is the cost of that edge.
- Use Dijkstra algorithm to help player navigate from a source to a destination.
- Four players take turn to make a move. The total move is 8( left top, top, right top…. )
- If they meets, fight for gold value, otherwise move to their target.
- As they move, their strength decrease by the height difference between two nodes.
- … etc
….
The problem that I’m encountering is that the source code is getting longer and complex day by day. And I think I’m using a wrong approach somehow, I feel so tired because of constantly changing the implementation. Here is my approach:
- Write out all requirements.
- Create all the object that I need with all getter and setter.
- Create a static class to test the logic
- Create unit test while putting the logic together
- Add some more code, then change to code to fit the test
- Write a big method that run, then break it down into smaller methods, then write unit test again.
- If everything work fine, add more requirements, add more code
- Then things are getting complicated because the more code I added, the complexity increases. No longer have time to write unit test because create a test case now requires too much work
- Re-design, then change the implementation, go to step 1 again.
I’m come from a C++ background, and I’m only comfortable with writing ‘static’ libraries such as: stack, queue, link-listed, tree… Game is really a big challenging to me, especially I have to use Java. I understand the core programming is the same, so picking up Java was not really that bad. However, the time of looking up Java’s API is not little. Further, the game logic is really hard to write. When this object moves, other object got affected…, so creating test for a method depends on many other methods…etc.
I really need an advice. Could anyone share some experience of how to write a game to me? I only have two weeks left for this assignment. I’m currently have 45 classes now, I feel so lost because the more I wrote the more it gets complex 🙁 !
Best regards,
Chan Nguyen
First start thinking like a java programmer. Think as every thing in your game as an object, like the board, think about the properties and methods it has, its interfaces, how it interacts with the other objects.
If you need help getting started here is a great tutorial that guides you step by step to do a simple java game, this might put you in the right frame of mind to start programming your own. I strongly recommend you to follow the tutorial.http://www.cokeandcode.com/asteroidstutorial and to use the libraries that they used for developing the interfaz there.