Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  First game, experienced Java programmer - design questions  (Read 2049 times)
0 Members and 1 Guest are viewing this topic.
Offline DrunkenLizard

Junior Newbie





« Posted 2009-07-03 21:06:13 »

Hi all, I've wanted to get into game development for as long as I have been programming, my first language is Java so I prefer to program in my native tongue, even though it probably isn't the best choice for game development in general. Aaaanyway to cut a long story short, I want to try and make a solid and robust game version of the card game Rummy (similar to Gin Rummy). I've been hammering away at the project for a few months now, and during that time I have learnt a few things - mostly how little I know about programming games - but I've become familiar with all the basics, and how to implement them in Java - writing a "game loop", double buffering, BufferedImages, etc.

My real problem is trying to settle on a broader design for the system. What I want is for it to be nice and flexible, so that I can play around with adding new features to it in the future (I'm thinking of writing several different types of AI, a replay feature, possibly a network multiplayer option and maybe eventually a multi-game server). This means that the design needs to treat each player in the game as abstractly as possible, and hence taking player input as abstractly as possible.

I've looked at a couple of tutorials from cokeandcode.com, namely the space invaders and asteroids 2D tutorials. I've also been studying the MVC design pattern and how this could work, and also the Entity System that is hailed by some as the saviour of game programming. I've attempted both of these but each time I try and refactor the code it seems to collapse in a muddy heap. It's getting to the point where I feel like giving up altogether as every time I try a new approach it seems to fail before I've even finished writing it!

Sorry for the longwinded post, please feel free to reply with a one line comment that I need to "go and buy this book", because I imagine this kind of question is asked so frequently that one might as well write a book on the subject.

A confuzzled newbie  Undecided
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 74
Projects: 15


★★★★★


« Reply #1 - Posted 2009-07-03 21:17:03 »

Best games related java book i've seen is Developing Games in Java by David Brackeen, although its a little old now its still a very nice intro to games development with java and covers a wide range of gaming topics.

If your considering creating a 2d game in Java, you might not want to miss the excellent 2d library Slick2d found at http://slick.cokeandcode.com IMO its one of the best things thats happened in a long time for 2d Java games.
Offline DrunkenLizard

Junior Newbie





« Reply #2 - Posted 2009-07-03 21:33:05 »

Thanks for the quick reply! I've downloaded the source related to the book and I'll check it out and see if the book looks worth buying too. I was also hoping for more help in the design area of game programming, for example how the overall system would look on a UML diagram and how the constituent parts could/should interact. Do you have any advice on that topic?

What might also be helpful is source code for some turn based games with more than one player, preferably written in Java, if anyone knows of such a game Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #3 - Posted 2009-07-03 21:34:36 »

If you are as much of a newbie as you say, then this may be to big for now. Or atleast cut out some of those features you listed.

not saying drop it, i am saying that maybe you should put it on hold.

GO SLICK!!
Offline DrunkenLizard

Junior Newbie





« Reply #4 - Posted 2009-07-04 00:30:44 »

Quote
If you are as much of a newbie as you say, then this may be to big for now. Or atleast cut out some of those features you listed.

Really? Because I have all the basics down, I think. For example, I tested myself and wrote a simple program that allows you to move a red ball around a screen, mostly from memory. Is there much of a gap to fill between that and a relatively simple card game? All I really need to learn from there is how to structure multi-player input and how to handle state changes. I don't actually want to implement all the features I listed straight away, I just want to write the program with a view to making my life easier somewhere down the line.

EDIT: included quote from previous post
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #5 - Posted 2009-07-04 10:44:26 »

well, all I need to ask, do you really know everything about the redball thing? I guess in a card game there isnt collision...

I siad first that you should cut out some stuff

for example: network play(maybe come back later and do it). AI(even Idont know how to do this, but if you are an experienced java programer, then this may not be hard).

Good luck Wink
Offline zoto

Senior Member


Medals: 4



« Reply #6 - Posted 2009-07-04 19:16:29 »

Quote
All I really need to learn from there is how to structure multi-player input and how to handle state changes.
I'm not very familiar with Rummy but I would imagine turns are taken one player at a time in a set order. if this is true, the user input should be easy to run over TCP, removing much of the headaches from networking. If you do want to network it there are several other issues to consider, like can you run a java program on a server somewhere or is it more for friends on a LAN.
Could you elaborate on what problems you are having with state changes? They are general int's or Enum's checked with a switch/case statement.

Quote
I don't actually want to implement all the features I listed straight away, I just want to write the program with a view to making my life easier somewhere down the line.
Abstraction and encapsulation should help a lot here. One area that comes to mind is to make an AbstractHandEvaluator that can be extended for various rule sets.

A book recommendation for game programming, including ULM charts. http://fivedots.coe.psu.ac.th/~ad/jg/
Offline DrunkenLizard

Junior Newbie





« Reply #7 - Posted 2009-07-05 12:22:45 »

I siad first that you should cut out some stuff

for example: network play

I take your point, I don't have any intention of doing any complicated stuff before the basics are down, all I wanted to do was somehow program everything along the way with it in mind, so that it isn't a headache to refactor all the code somewhere down the line!


A book recommendation for game programming, including ULM charts. http://fivedots.coe.psu.ac.th/~ad/jg/

Great book, thanks zoto! I've checked it out before and intend to buy it - only passed it up in this case because it seems to be biased away from games with a set turn order.


Could you elaborate on what problems you are having with state changes? They are general int's or Enum's checked with a switch/case statement.

I suppose I'm struggling to figure out what would be the best practice. I'm looking at the basic idea of switching over an Enum or int, but I guess I don't like it because that kind of code can get messy, is difficult to extend/adapt, and I guess would probably need to be repeated in a few different places, all making it that much more unmaintainble. I did toy with the idea of using a state system similar to states in MVC model 2, where the state holds all the information the game needs to both update it and render it, and it would be passed around the various facets of the game being updated and rendered as appropriate. Predictably this ended in a mess too! Is there a best practice here? Some guidelines I can follow?? Thanks all for your help so far Smiley
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11


Game Engineer


« Reply #8 - Posted 2009-07-06 16:52:49 »

Not to rag on h3ckboy at all, but he isn't so experienced himself so don't be discouraged by his advice. I personally think you have a very doable amount of work here, as long as you start small and build onto it (as it seems you're planning to do anyway). A card game is a great learning project, allowing you to go into most of the important realms of game programming without all of the problems associated with each.

I wouldn't even bother with Slick, as a card game doesn't need hardware acceleration. Just give it a go with Java2D, and if things start to chug for whatever reason, convert to Slick (which won't take very long).

As for AI, because I'm always looking for a place to apply them and because card games are one of the only realms where they really work well, I'd try a learning algorithm like a genetic algorithm or Q-learner. It's very easy to determine whether a specific "gene" or tendency should be rewarded or penalized (in the case of a win or a loss), and it's also pretty easy to come up with different genes (chance to discard with X hand, chance to draw another with Y hand, etc.). You can make an incredibly complicated state space or genetic code very simply, then you end up with a few kilobytes of gene data that you can save to the disk as a "brain." Then just load that up when you play. The best part is, if you run your AI for 6 hours to learn, you can make that your hard difficulty, 3 hours can be medium, and 1 can be easy. No work on your end, plus you'll have really really strong AIs that are difficult to predict.
http://www.ai-junkie.com/ga/intro/gat1.html

See my work:
OTC Software
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #9 - Posted 2009-07-06 18:54:21 »

I never said I was experienced, but my advice is sound. Leave AI and networking for later. Or atleast the netorking,o keep it in mind though.

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

Junior Newbie





« Reply #10 - Posted 2009-07-06 19:04:12 »

As for AI [...] I'd try a learning algorithm like a genetic algorithm or Q-learner.

Thanks for the encouragement Demonpants! You've hit the nail on the head with the genetic algorithm advice actually. I wrote a very messy version of this for my third year dissertation and a rudimentary AI based on genetic algorithms. At the time I was a lot less experienced (and possibly high on Red Bull and energy bars) and didn't do a very good job, so I suppose I'm looking to correct that with this project.

I think what would really help me the most is to be able to look at some source code, as that's the way I learn the best. Anyone know any good turn based games, or especially multiplayer card games, that I could look at?
Offline dishmoth
« Reply #11 - Posted 2009-07-06 21:17:46 »

Quote from: DrunkenLizard
Sorry for the longwinded post, please feel free to reply with a one line comment that I need to "go and buy this book", because I imagine this kind of question is asked so frequently that one might as well write a book on the subject.

A few thoughts:

1) I've never written a card game, but it would seem to me to split quite neatly into two parts: the game logic (in particular the AI), and the game interface.  The logic includes classes that represent cards, hands, packs, etc., and algorithms for choosing moves (AI), shuffling the pack, whatever.  (In other words, it's the "M" in "MVC".)  The user interface displays the cards and accepts user inputs (the "V" and "C" parts).

The point here is, you could build and test the "core" logic part of the game separately from writing any proper code for the game interface.  It might be enough initially to type in moves at the command prompt, or watch the text output from two AIs playing against each other.

The advantage to this is that, while you might end up making lots of significant changes to the user interface as time goes on (for example, if you add an online multiplayer option), you'll probably still be using the same game logic.

2) As for the game interface, you could either approach it like you're writing an action game (i.e., traditional game loop, double-buffering, updates at a certain number of frames per second) or a traditional Windows application (Swing, event-driven, limited animation).

The latter approach perhaps seems more appropriate for a card game (thinking of FreeCell or Solitaire on Windows) but it isn't something you'll find much about from game development books (or forums).

3) Since you're asking for book recommendations, and you seem interested in how game code can be structured, I'll put in a word for "Game Coding Complete" by Mike McShaffry.  It's heavy on C++, and focused on much larger projects than we're talking about (i.e., large teams, commerical products), but it's an entertaining read.

Just my opinions, and not necessarily good ones.  Wink

Simon

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11


Game Engineer


« Reply #12 - Posted 2009-07-06 23:49:06 »

I think what would really help me the most is to be able to look at some source code, as that's the way I learn the best. Anyone know any good turn based games, or especially multiplayer card games, that I could look at?
Hm, I had an example poker AI that used genetic algorithms a while back, but I can't find it on Google anymore. However, I know that it exists, so maybe some creative searching could find it.

See my work:
OTC Software
Offline zoto

Senior Member


Medals: 4



« Reply #13 - Posted 2009-07-08 05:04:16 »

Quote
I suppose I'm struggling to figure out what would be the best practice. I'm looking at the basic idea of switching over an Enum or int, but I guess I don't like it because that kind of code can get messy, is difficult to extend/adapt, and I guess would probably need to be repeated in a few different places, all making it that much more unmaintainble. I did toy with the idea of using a state system similar to states in MVC model 2, where the state holds all the information the game needs to both update it and render it, and it would be passed around the various facets of the game being updated and rendered as appropriate. Predictably this ended in a mess too! Is there a best practice here?

I'm not sure how best practice it is, but I am currently using something like this.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D;


public interface GameState {
   public void draw(Graphics2D g, Rectangle2D clip);
   public void update(long ticks);
   public void alwaysUpdate(long ticks);
   public GameState getNextState();
   public void handleKeyboardEvent(KeyEvent e);
   public void handleMouseEvent(MouseEvent e);
}


Then in the update/draw class I would create a GameState to hold the current state and add some code like this.

1  
2  
3  
4  
5  
   @Override
   void update(long time) {
      currentState.update(time);
      currentState = currentState.getNextState();
   }
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.

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

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

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

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

ctomni231 (50 views)
2014-07-18 06:55:21

Zero Volt (45 views)
2014-07-17 23:47:54

danieldean (36 views)
2014-07-17 23:41:23

MustardPeter (39 views)
2014-07-16 23:30:00

Cero (54 views)
2014-07-16 00:42:17

Riven (54 views)
2014-07-14 18:02:53
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!