• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java/SWT Text Game Engine

 
Ranch Hand
Posts: 64
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Lance Colton
Ranch Hand
Posts: 64
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 140
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 64
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 140
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic