Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (113)
games submitted by our members
Games in WIP (562)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Creating a command line similar to MS-DOS.  (Read 2733 times)
0 Members and 1 Guest are viewing this topic.
Offline kpars

JGO Wizard


Medals: 79
Projects: 4
Exp: 3 years


Extreme Typist.


« Posted 2013-06-23 18:27:39 »

Hello all, I'm in the middle of working on a game, 'Pixel-Space: The Next Adventure' as you know it, and I'm attempting to implement computers into the game. Does anyone have any good advice or shared code that might be helpful?

I attempted it a while back and was stunned at how many different things you would need to think about. All help is appreciated.
Basically, I'm referring to the blank command line that you can perform commands on. Think of it like trying to create a console from scratch, mainly using java.awt.graphics.

Thanks in advance.  Smiley

Offline BurntPizza
« Reply #1 - Posted 2013-06-23 18:35:54 »

Maybe you have already done this, but first you should always google everything you can about the problem at hand. There is actually a lot about this sort of thing out there.

making a command line java
Offline Sammidysam
« Reply #2 - Posted 2013-06-23 21:35:57 »

I have a project that is very similar to what you are looking for here.  It is currently getting documented with Javadoc, and you can compile it by running the command "ant" in the project directory, or you can just run ./launch.sh (if not on Windows) and it will call ant and them launch the jar.  If you are on Windows, after compiling you can launch it with the command "java -jar bin\FakeJavaOS.jar -textmode".  It will help a ton to get command interpreting done.  Good classes are the Matchers for Arguments and Commands and Argument and Command classes.

You need to run it with the argument --init the first time running.  This is kind of annoying, and after documentation is done that will be fixed.

It doesn't use Java2D graphics yet, but once I finish the actual command line I am going to go that.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline deepthought
« Reply #3 - Posted 2013-06-24 00:12:04 »

here's a very simple method. I just implemented cd and cat (cat's linux, but it's simple to implement).

http://pastebin.java-gaming.org/337f81d276c

just create a file c:\hello.txt and put some stuff in it for a demout you could easily use a virtual . this uses the filesystem of the computer you're running on, but you could use some sort of fake file system too.

the main thing to look at is the commandline.java file. It just splits the command name from parameters and executes the appropriate command class the same way java does with main(String[] args)

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline BurntPizza
« Reply #4 - Posted 2013-06-24 00:55:15 »

Also, if you play minecraft, you can check out the computercraft mod, implements computer terminals with Lua inside minecraft, as well as other goodies. Might give you an idea of how advanced you want to go with your project, i.e. whether or not to have a full-blown file system with stored programs or just some static commands.
Offline kpars

JGO Wizard


Medals: 79
Projects: 4
Exp: 3 years


Extreme Typist.


« Reply #5 - Posted 2013-06-24 01:05:04 »

That is EXACTLY what I was thinking of diving into.

I might look into that. I thought however instead of using LUA, I would try to make my own little language called Ke-script, or something like that. So much work in that though...  Emo

Offline BurntPizza
« Reply #6 - Posted 2013-06-24 01:11:44 »

The separate scripting language is only necessary because of the existence of stored programs in a virtual file system. If you don't go that far, then you don't need it at all. If you do want that, then you could write your own DSL, or you could use one of these, or another language with a pre-made interpreter in Java.

 Example procedure from JUEL
Seems pretty plug-and-play. Never used it before, though.
Offline wessles

JGO Wizard


Medals: 66
Projects: 4
Exp: 3 years


Profile picture isn't relevant.


« Reply #7 - Posted 2013-06-25 20:36:48 »

Well, If you are not afraid of tedious work, here is how I would approach it...
So you have a console class, with this basic layout (WARNING: Very rough, but you should get the basic idea):

I hope this helps!

Offline Fsig

Senior Newbie





« Reply #8 - Posted 2013-06-25 23:48:37 »

Hello all, I'm in the middle of working on a game, 'Pixel-Space: The Next Adventure' as you know it, and I'm attempting to implement computers into the game. Does anyone have any good advice or shared code that might be helpful?

I attempted it a while back and was stunned at how many different things you would need to think about. All help is appreciated.
Basically, I'm referring to the blank command line that you can perform commands on. Think of it like trying to create a console from scratch, mainly using java.awt.graphics.

Thanks in advance.  Smiley

If it's just a simple command line, write down a list of commands you need.
Then when the user enters anything into the command prompt check the entered string against a array for stored commands, if the command is valid proceed to doing what ever it is the command is supposed to do.

Is there anything in particular that you need help with?
Offline Sammidysam
« Reply #9 - Posted 2013-06-28 00:53:22 »

Well, If you are not afraid of tedious work, here is how I would approach it...
So you have a console class, with this basic layout (WARNING: Very rough, but you should get the basic idea):

I hope this helps!

Ugh, listing all the commands in a huge array is quite inefficient to me.  Why not just create a Command class and then use reflection to dynamically load all commands (in classes starting with Command, such as CommandStop, CommandChangeDirectory, etc.) which extend the Command class?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wessles

JGO Wizard


Medals: 66
Projects: 4
Exp: 3 years


Profile picture isn't relevant.


« Reply #10 - Posted 2013-06-28 19:43:56 »

Yes, your way is more efficient, no doubt. I would suggest your way. I just don't like using up all that memory with classes. It works, and takes up less space. Depends on what you are going for.

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #11 - Posted 2013-06-28 20:23:19 »

Well you can always just generate simple Java and run that straight from your code. I did that for an RPG and it worked pretty well. Because Java uses a JIT, you can do this with no issues.

See my work:
OTC Software
Offline Sammidysam
« Reply #12 - Posted 2013-06-29 02:42:30 »

Yes, your way is more efficient, no doubt. I would suggest your way. I just don't like using up all that memory with classes. It works, and takes up less space. Depends on what you are going for.

Well, your console method only uses one class, right?  I feel like a little extra RAM consumption is better than a 20,000 line class when you have tons of commands.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (15 views)
2014-09-12 09:08:26

Norakomi (45 views)
2014-09-10 13:57:51

TehJavaDev (57 views)
2014-09-10 06:39:09

Tekkerue (26 views)
2014-09-09 02:24:56

mitcheeb (49 views)
2014-09-08 06:06:29

BurntPizza (33 views)
2014-09-07 01:13:42

Longarmx (19 views)
2014-09-07 01:12:14

Longarmx (21 views)
2014-09-07 01:11:22

Longarmx (20 views)
2014-09-07 01:10:19

mitcheeb (30 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!