Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
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  
  Turned based game design/architecture  (Read 6184 times)
0 Members and 1 Guest are viewing this topic.
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Posted 2007-07-24 20:54:55 »

Hi,

I'm currently making a turned base game (risk style game) where there are 2-4 players (single/multi + computers).

I've been thinking about how to design the game so that:
a) Only one player makes his moves at a time
b) Screen only updated when something has happened, there is no animation going on (that is, it's not as a traditional game loop where it's updated as fast a possible)
c) When player is making his moves I want to display messages on the screen like "Player A attacks Player B".
d) I want there to be some user interaction even though it's not the users turn, like highlighting objects of interest, display help. If the user tries to do something when it's not his turn, he gets a message "wait for your turn".

I was thinking about having the "Screen", that is the graphics that are displayed, running as a seperate thread, and then the "Logic", doing all the players moves, running as a seperate thread. Logic would tell Screen to refresh itself when something has happened. But this only covers the logic in the game, not when the user has interaction with objects of interest (such as highlighting). So I've begun to wonder if there aren't some standard ways of doing this?

Thanks!


Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline 2playgames

Junior Member





« Reply #1 - Posted 2007-07-24 23:18:31 »

why can't you do the highlighting with the method you describe? just let the thread which determines if something should be highlighted tell the screen to refresh  Huh

Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #2 - Posted 2007-07-24 23:54:46 »

Maybe I'm asking for references to "Turn Based Game Architecture & Design" documents, sites. I need to learn how to make games change by events, not by time (delta). And I need to learn how turn based games are implemented, I haven't thought much of them since I became interested in game programming.

Although I could probably get my game to work (some of it's functionality works already), I just want to do it properly and in the "recommended" manner.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline keldon85

Senior Member


Medals: 1



« Reply #3 - Posted 2007-07-25 00:20:52 »

This is all (believe it or not) a very good Software Engineering exercise. I've spent a few minutes wondering how I could explain it to you but it's hard without giving you every step.

One thing I would say is that if you make your game event based and manage it with listeners (MVC), and do the right design of how it should be and worry about implementation later then you may have an easier task.

You could probably knock out the necessary architecture in a few hours that (a) would not need to be changed and (b) is sufficient to cater for not only network play, but a text console and a GUI. Take it in iterations:
 - Step 1: develop a text console version of the game, I can lend you a nice little text console using a TextField
 - Step 2: develop the game so that you are still inputting commands using the console but it is displaying a gui output
 - Step 3: add gui input

Start thinking about how you will be loading in data too. You don't want your data tied into your code, use input files whenever you can!

Offline SimonH
« Reply #4 - Posted 2007-07-25 05:35:41 »

(that is, it's not as a traditional game loop where it's updated as fast a possible)

Why not? It's the best way... How can you highlight things under the pointer without a framerate?

People make games and games make people
Offline bahuman

Junior Member





« Reply #5 - Posted 2007-07-25 09:42:04 »

b) Screen only updated when something has happened, there is no animation going on (that is, it's not as a traditional game loop where it's updated as fast a possible)

-1 on this  Wink
one day, you'll want animations even in your turn-based game. And then you'll curse yourself for not having a "classic" game loop.
As Keldon said above, the model-view-controller pattern should be able to help you out, here.

the model is your actual game. It has methods to assign players, change turns, make moves, create units, etc... This object will apply game logic and raise an error when someone tries to do something out of their turn. It also has a lot of getter methods to figure out the current state.

the view is your standard 60 fps game loop. it keeps track of a camera, and asks the model where all the units are, and which units are active (need highlighting), etc.

the controller is the object that will call methods on the model to create players, start the game, etc. It does this based on input. Like Keldon suggested, you can start with a really simple console, and later move your code to the game loop.
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #6 - Posted 2007-07-25 11:16:58 »

The reason I wanted to make my game re-render itself only when required to do so is:
To reduce CPU overhead, no need to render a static screen at 60fps. I often hear complaints from laptop users that their fans went into overdrive because of small games.

I mean, how would you feel like if Minesweeper in Windows caused 100% CPU load?

I can live without some nice highlight stuff.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline bahuman

Junior Member





« Reply #7 - Posted 2007-07-25 11:34:51 »

I see your point. Reducing the maximum frame rate may be enough to make the problem disappear, though. After all, you need barely enough fps to make your game somewhat responsive. I played a quick action game on my portable (the things I don't do for java-gaming.org!  Roll Eyes ) and my fan never kicked in.

Do you plan to use AWT/Swing, or any of the more gaming-oriented libs like JME/LWGL/JOGL?

In case of AWT/Swing, I guess the main question becomes: in the MVC pattern, how does the viewer object become aware that the screen needs an update because the model has changed?
- polling? You're back to 100% cpu usage if you're not careful.
- a callback? If your model would define an event "GameUpdateChangedEvent", and allowed for GameUpdateListeners to be registered, I think you're getting closer.
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #8 - Posted 2007-07-25 12:42:51 »

Yes, just AWT/Swing, and just Java2D.

I have KeyListener and MouseListener to make the game react to local user inputs, so whenever he clicks on the screen with his mouse I can check if that x,y actually hit a country, and if it did, then I can highlight that country, thus refreshing the screen. If he did not hit anything, I could still refresh the screen with a message "You must select a country!", or simply do nothing.

And then I have the computer AI doing it's move (probably skipping multiplayer in 1st version to get things going).

So, how I make the screen aware is not what I would do. I would simply tell the screen to update whenever my logic says, or user inputs says, I need to update it.

Not sure if reducing the framerate is really the solution. Even at whatever framerate I would still have to "animate" things that are happening. Let me explain: When it's the Computers move, it can finish it's logic in 1ms (or 1 game logic update loop), and in that time it could have invaded 4 countries, moved armies around etc, and the user watching the game just missed that, all he saw was the screen before all these changes and then the results of the computers move. I want the user to witness the computers move, although they would playback relatively faster than normal, the player would still see and realize what the computer was doing, just like the user was playing against another human opponent. I don't want the user to think "Wow, I lost half of my countries, what the heck happened?"

So, in that sense, it would probably be more difficult to simulate this in a 60fps-game-loop. While in a static screen, and it's the computers turn, I could simply refresh the screen when the computer made some action, let the thread sleep for 100ms, and then off to the next action.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline bahuman

Junior Member





« Reply #9 - Posted 2007-07-25 12:59:14 »

I have KeyListener and MouseListener to make the game react to local user inputs, so whenever he clicks on the screen with his mouse I can check if that x,y actually hit a country, and if it did, then I can highlight that country, thus refreshing the screen. If he did not hit anything, I could still refresh the screen with a message "You must select a country!", or simply do nothing.
er made some action, let the thread sleep for 100ms, and then off to the next action.

I'm going to focus on this part Wink
If your "game" class is listening to keys and mouse events directly, it sounds like you're not following the MVC pattern. I'm not sure if you're familiar with the pattern?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #10 - Posted 2007-07-25 13:16:40 »

I'm going to focus on this part Wink
If your "game" class is listening to keys and mouse events directly, it sounds like you're not following the MVC pattern. I'm not sure if you're familiar with the pattern?

Yes Smiley But mostly with web-MVC which is different than gui-MVC. Haven't done it for a while, I'll read some article to refresh my memory. Let you know if that's the solution Smiley

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline ferens

Junior Newbie





« Reply #11 - Posted 2007-12-18 08:49:16 »

I'm doing some similar stuff - it would be interesting to hear how your design ended up?
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #12 - Posted 2007-12-18 09:44:18 »

I'm doing some similar stuff - it would be interesting to hear how your design ended up?

Scrapped the project, so I ended up doing nothing but fancy graphics for the game  Undecided

I figured that the risk game was too different, e.g. event based MVC, from what I consider "normal" games. I'll probably try it again, but with something much simpler than what I originally had in mind.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline ferens

Junior Newbie





« Reply #13 - Posted 2007-12-18 09:54:41 »

then were in the same position, i also got carried away with something risk-like and it definietly looks like Im trying to swollow a little bit to much at once.

I hink I'll go back to something more "monopoly" like - moving a piece and buying a house .. or something... But this time I'll write me a model and will try to really stick to it, and hopefully get a good design from the beginning. I don't really get it with passing my actionevents around in a good way
Offline Mr_Light

Senior Member




shiny.


« Reply #14 - Posted 2007-12-19 01:48:34 »

have a look at http://filthyrichclients.org/

and note how animations can play nice with the edt.

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline ferens

Junior Newbie





« Reply #15 - Posted 2007-12-22 08:33:46 »


Bought!!  Wink
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.

CogWheelz (18 views)
2014-07-30 21:08:39

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

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

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

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

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

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

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

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

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

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
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!