Results 1 to 6 of 6
Thread: In-game console
- 08-17-2009, 03:43 AM #1
In-game console
I'm creating a game, and I want to have an in-game console. I have the gui for it done, however, I'm usure as how to do the interpreting part.
I want to set it up so I can easily change in-game settings and instantiate classes.
For example, I would have something like
The way I have come up with doesn't sound like it would be the best way.Java Code:full_screen OFF // sets full_screen to off load ./res/pick.bmp 10 10 // Load a picture at the coordinates 10 10
I would have a dictionary of runnables which would have something like "load" as a key to look it up.
Is there a better way to do this?
Any links, ideas, suggestions, feedback would be greatly appreciated.
Thank you for your time and effort,
Mr. Beans
- 08-17-2009, 05:00 AM #2
You'll have to create methods for each type of action to be performed. A method could interpret the input to figure out what type of command is being issued, then call the appropriate method passing any relevant parameters. i.e.:
This is over simplified, but you get the idea. You could also use java's REGEX if you want to get fancy.Java Code:private void read(){ input = in.readLine(); if(input.startsWith("full_screen")) fullScreen(input.split(' ')[1]); ... } private void fullScreen(String command){ if(command.equals("OFF")) //make windowed else if(command.equals("ON") //make full screen else //error }
You could create a hashTable or something to map key values -- but if you simply need to do what's typed, then a simple large method might be the easiestLast edited by quad64bit; 08-17-2009 at 05:04 AM.
- 08-17-2009, 06:18 PM #3
I'm planning on having lots of commands, is there a better way to go about it than having a ton of ifs to check what the command is then call the corresponding method that is needed to deal with the command?
Thank you for your response,
Mr. Beans
- 08-17-2009, 09:45 PM #4
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
hmm... I have something for that somewhere, I used it for commands being sent through sockets. I'll try to dig it out, it had an abstract Command class that used keys for validation, and an abstract method execute(), and I created anonymous classes... I'll see if I can find it, and post if for you.
If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
-
I'm not exactly sure what you're looking for (more my problem than yours, I'm sure), but should you be looking at the Command or Strategy design pattern? Just a random thought.
- 08-17-2009, 10:22 PM #6
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
Commands Package
Found my package for commands. Remember when you look through it that I used it for Serialized commands sent through Sockets, so the Socket parsed commands etc, then sent them to something else to be dealt with. I've attached a zip file with the package source code, have a look, most of the files also have Javadoc comments.
You'll definitely have to change some things, but it should help you start out.If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
Similar Threads
-
How to get input from Console
By karma in forum New To JavaReplies: 8Last Post: 08-13-2010, 09:32 PM -
Implementing "Game Over" in Minesweeper game based on Gridworld framework.
By JFlash in forum New To JavaReplies: 2Last Post: 08-05-2010, 04:49 AM -
2D strategy game or 2D war game
By led1433 in forum Java 2DReplies: 5Last Post: 02-10-2009, 06:00 AM -
Console doesn't appear!
By PeteMarsh in forum New To JavaReplies: 2Last Post: 12-17-2007, 05:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks