tags:

views:

262

answers:

2

Well i decided to make something like a mud and the practices i may use in other places too, but i have one problem.. i don't know how to make it to where a user can type in the actual box instead of a Textfield

i'd like to explain better but i can't really think how

A: 

If you're talking about a MUD client and entering the text in the same window as the output, sounds like you'd run into the same problem as when you play a MUD via bare telnet in a terminal - which is that the text you're entering scrolls away as you're typing it so you can't see to edit, etc. I think having a separate field where you can edit if necessary before entering it is a good thing.

You could just focus on the server instead and let users (admins too) connect via one of the MUD clients out there like zMUD. I may be interpreting your question wrong, though. There's a ton of stuff involved in making a MUD, so most people don't get a viable game up and running when starting from scratch - but you can still learn a lot from the effort, regardless. I did that myself but just the server - never did anything with a client program or GUI interface.

Editing to add, after the OP's comment response:

Take a look at this Sun tutorial to see if it helps:

http://java.sun.com/docs/books/tutorial/uiswing/components/textarea.html

The first example uses a separate field for input, but scroll down to the "TextAreaDemo" example which may show what you need.

Anon
oh no you got my question right, i was also kindof wanting to use in making my own command prompt type thing for another program i am making, i am aware of the text scrolling away problem but i'd still like to know how to do it.
Lonnie Ribordy
i don't understand their example code all that well, but if what i get from it is correct, all there is to it is making the document read backwards from the caret position to the end of the word??
Lonnie Ribordy
No - in the part I believe you are looking at, the program is checking for words to autocomplete. Basically, you work with a zero-based index into the text in the field. In the example, for insert events from the user that the program is detecting, that index is obtained with ev.getOffset(), and when the program is itself inserting text into the field, it does so with textArea.insert. In one place, they're calling it an offset and in another a position, but in both cases its a zero based index where the action happens.
Anon
(Note too that getOffset() is returning the start of the input, not the end. The ev.getLength() method is how they get the length of the input.)
Anon
+1  A: 

Muds aren't that complicated to make. I think the answer to what you are asking is that you need to use the TCP/IP telnet port.

Telnet is pretty easy, you just open a port and start reading data--there is lots of info on it and even a few libraries that can help you. (Telnet is just a standard port, but there is this one little exception, a "Negotiation" that goes on in the beginning, it's just sending a few bytes back and forth, but if you don't do it then nothing ever happens).

So you write your code and start listening to a port (4444 was a common MUD port iirc). Then you run your telnet client and connect to that port. It will create a new port connection for each person calling in. You probably have a thread listening to each port that watches what you are typing, handles backspaces and can send completed commands to your main mud system (To a synchronized method because many ports may send commands at once).

It's actually pretty easy. Look for a telnet library for Java to start out.

A quick search found JavaSSH which also handles telnet.

Edit: I should point out that they are not EASY to make either! Making the maps, equipment and monsters all data driven so that you don't have to rebuild for every monster takes some forethought... It's one of those things where you'll probably write your first one and use it for a month before deciding it needs to be re-written from scratch.

I'm just pointing out that you may want to examine the mud source that's already out there. I found diku pretty small and easy to understand.

Bill K