aspose file tools*
The moose likes Game Development and the fly likes Java/SWT Text Game Engine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Java/SWT Text Game Engine" Watch "Java/SWT Text Game Engine" New topic
Author

Java/SWT Text Game Engine

Lance Colton
Ranch Hand

Joined: Nov 25, 2010
Posts: 64

I've been working on an engine for a text based game which will allow a user to interact with the engine is such a way that allows the user to play the game in a graphical area.



The problem I'm having is, when you add text to the List, I can't find a way to wait on the user input before continuing on.

ex. TextEngine te = new TextEngine();
te.interact("enter your name: ");
String responce = te.getResponce();
te.interact("Hello " + responce);

TextGame.java (engine




and the attempted implementation CanterburyTales.java:




any input at all would be helpful

thanks in advance,


~tak
irc.esper.net - tak, irc.freenode.com - tak11, irc.efnet.org - tak11
Lance Colton
Ranch Hand

Joined: Nov 25, 2010
Posts: 64

Disappointing no one could help me out with this one, I ended up pumping out the hackest solution ever. xD

Posted for educational purposes.


TextGame.java


Game.java


Basically when you implement the API you implement the Game interface, and then when creating a TextGame object, you also create a Game object and pass it to the TextGame constructor, like this



I wrote that on the fly in this forum, there may be errors, however thats the gist of it.
Phil Freihofner
Ranch Hand

Joined: Sep 01, 2010
Posts: 115
    
    1
The problem I'm having is, when you add text to the List, I can't find a way to wait on the user input before continuing on.




Hi - I'm not totally following your code or your solution, I have to admit, but I thought I'd throw out a couple ideas. First a simple possible typo check: if you are mixing up "response" and "responce". I guess either works, as long as you are consistent, and you aren't using "responce" thinking you are invoking a built-in Java method.

Second, in general, if you want to wait for a response, I think the proper thing would be to isolate the code that does the basic setup and presentation from the code that reacts to the User. Maybe you are already doing that? I'm assuming the SelectionListener is for selecting a choice in a dropdown, not for responding to text input, but as I said, my understanding of your code is superficial.

But for example, on general principles, let's say there is a listener that specifically reacts to keyed input to your TextEngine. I imagine it will either react to every key that is entered, or only when the <Enter> key is hit? If the former, I would test each key entered to see if it is an <Enter> key or not, and in either case, ONLY call the code which responds to the input via this listener. Placing responding code directly after the .interact() method won't work because, as you note, the next line immediately executes. The responding code should only be accessible via whatever listener is appropriate for your TextEngine.

Hope this helps!
Lance Colton
Ranch Hand

Joined: Nov 25, 2010
Posts: 64

Phil Freihofner wrote:




I have restructured the code, check the second post

Phil Freihofner wrote:
Second, in general, if you want to wait for a response, I think the proper thing would be to isolate the code that does the basic setup and presentation from the code that reacts to the User. Maybe you are already doing that? I'm assuming the SelectionListener is for selecting a choice in a dropdown, not for responding to text input, but as I said, my understanding of your code is superficial.

But for example, on general principles, let's say there is a listener that specifically reacts to keyed input to your TextEngine. I imagine it will either react to every key that is entered, or only when the <Enter> key is hit? If the former, I would test each key entered to see if it is an <Enter> key or not, and in either case, ONLY call the code which responds to the input via this listener. Placing responding code directly after the .interact() method won't work because, as you note, the next line immediately executes. The responding code should only be accessible via whatever listener is appropriate for your TextEngine.


I took a more event driven approach, I would look at the second implementation.

I'm thinking of making it easier on the programmer however by wrapping the "reciever" method into another class inside of the TextGame Engine and make it more like a listener
"ex"
Phil Freihofner
Ranch Hand

Joined: Sep 01, 2010
Posts: 115
    
    1
Yes, more event-driven -- that's a good thing.
Sorry if my suggestion was moot, due to not studying your solution closely enough. Good luck with your game!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java/SWT Text Game Engine