user1803796
user1803796

Reputation: 11

How to create a command line simulator GUI for C++

I'm looking into developing a text based game about cyber security akin to hackRUN or uplink but I have no experience with GUI programming and I doubt anyone in my family would want to learn how to make and run a .cpp file. So I need to create a GUI featuring a custom command-line akin to Linux or windows "cmd". Is there any resources available in that area?

Upvotes: 0

Views: 2130

Answers (2)

Phil H
Phil H

Reputation: 20131

You can simulate a commandline by reading a line from the user and splitting on the first space (Python/pseudocode*):

for line in raw_input():
    command,arguments = line.split(' ',1)

For example read book is the command read with the argument book.

Then you can process the command they gave using your own logic. The advantage of this approach is that you can just run your game via a shortcut on the desktop (whether linux or windows) and the OS console will support the interaction.

There is a class of games called 'text adventure' games, which were popular back when graphics were limited or nonexistent, which you may find particularly relevant. Consider using an existing text adventure engine so that you can concentrate on the game itself rather than the mechanics of text entry and parsing.

* Consider writing this in Python or a similar scripting language, as they provide straightforward handling of strings etc. You are unlikely to need the raw power and complexity of C++ for a commandline-style family game.

Upvotes: 0

user1610015
user1610015

Reputation: 6668

You can create a textbox control that's the size of the entire window, and customize it to make it look like a console. For example, set the background to black, the color of the letters to white, etc.

How you create that textbox depends on what UI framework you're using. For C++ there's MFC or the managed WinForms, or you could create the UI part in C# using WPF and use C++/CLI as a bridge between C++ and C#. But if you want to make it work on both Windows and Linux you can use wxWidgets or Qt.

Upvotes: 1

Related Questions