Results 1 to 6 of 6

Thread: In-game console

  1. #1
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default 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

    Java Code:
    full_screen OFF // sets full_screen to off
    load ./res/pick.bmp 10 10 // Load a picture at the coordinates 10 10
    The way I have come up with doesn't sound like it would be the best way.
    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

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    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.:
    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
    }
    This is over simplified, but you get the idea. You could also use java's REGEX if you want to get fancy.

    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 easiest
    Last edited by quad64bit; 08-17-2009 at 05:04 AM.

  3. #3
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    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

  4. #4
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    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!

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  6. #6
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default 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.
    Attached Files Attached Files
    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

  1. How to get input from Console
    By karma in forum New To Java
    Replies: 8
    Last Post: 08-13-2010, 09:32 PM
  2. Replies: 2
    Last Post: 08-05-2010, 04:49 AM
  3. 2D strategy game or 2D war game
    By led1433 in forum Java 2D
    Replies: 5
    Last Post: 02-10-2009, 06:00 AM
  4. Console doesn't appear!
    By PeteMarsh in forum New To Java
    Replies: 2
    Last Post: 12-17-2007, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •