0

I'm making a Batch text-based game, and I'd like to have the color values changed. For example, rather than have a mustard yellow, I'd like a pale tan. I know you can do this through the CMD properties, but I'd like to do it when the game starts, that way the player won't have to configure these settings themselves.

2 Answers2

0

In a cmd prompt type color /? and you will see how you can change the screen colours in your batch script.

To change the RGB values then you will need to edit the registry with reg.exe assuming your users have permission to edit the registry.

foxidrive
  • 37,659
  • 8
  • 47
  • 67
0

CMD can work with "inline" ANSI-control-codes

ANSI control codes make use of an "ANSI-Escape-Sequence" to indicate to the interpret, there is something special that follows, that is meant to be "obeyed" as an instruction.

ANSI-Escape-sequences start with the character ESC ( ASCII decimal 27, HEX 0x1B ).

You may already know, that ANSI-Escape-sequences have various syntax ( length ) and meaning -- set colour, brightness, move cursor.

However, most of the sequences are more than two characters, and start with the characters ESC and [ (left bracket).

<ESC>+"[42m"   // set Green  background
<ESC>+"[41m"   // set Red    background
<ESC>+"[43m"   // set Yellow background

<ESC>+"[20;40H // mov Cursor position to ROW = 20, COL = 40

<ESC>+"[5m"    // set Blink-slow

<ESC>+"[25m"   // set Blink-off

History re-born

Using ANSI-control-codes was quite popular, starting from using them inside environment settings -- alike changing a boring prompt $p$g into something with colour-full <hostname>, with gray <current_path> and a dark green YYYY-MM-DD HH:MM:SS on a second row, was quite a comfortable setting.

As there were ( and still there are ) many helpfull functions directly available via ANSI-control-sequences, historically there were implementations, that have used this console features to create an independent char-based GUI on a standard console screen that worked as menu-systems, cursor-navigated turtle graphics, simple games, syntax-highlighting and other position/colour navigation and many other smart utilities.

The same can your game text-based-output use and do today.

How it can look about?

CLI text

text-stream generated GUI

ANSI escape code syntax overview

user3666197
  • 1
  • 6
  • 43
  • 77
  • 1
    Modern Windows doesn't support ANSI codes natively. It would help if you provide the name and download location of an ANSI program that works for modern windows. – foxidrive Oct 05 '14 at 00:30
  • Here you are: https://www.liferay.com/web/igor.spasic/blog/-/blogs/enable-ansi-colors-in-windows-command-prompt and http://softkube.com/blog/ansi-command-line-colors-under-windows – user3666197 Oct 05 '14 at 00:32
  • I looks like it could work - but the github site does not have binaries and the http://adoxa.110mb.com/ansicon/index.html link doesn't respond atm from here. It requires an installation and the program directory being added to the path, so is for dedicated users and not a portable batch file. `Aacini` has created a single binary to create colour in a cmd window called `colorshow.exe` and a stunning example of it's use is in the thread at http://www.dostips.com/forum/viewtopic.php?f=3&t=4125 (plain text is possible as well). A batch script to create the colorshow.exe binary is linked there. – foxidrive Oct 05 '14 at 01:52