-1

I have a Snake game in terminal, it works well with WASD control, but i want to add ЦФЫВ control(this is Cyrillic symbols). Here is example of code

int keyBoard;
switch (keyBoard = _getch()) {
  case 'ы':
            y = y + 1;
            Moves[movesCount] = Dir::DOWN;
            movesCount++;
            if (isTrail != Trail::FALSE) {
//                changeTrail();
            }
            break;
}

In this version it didn't work: i just push the buttons and nothing works. I tried to change my encoding to Cyrillic and UTF-8 with BOM, bit it wasn't help me. May be you can?

1 Answers1

0

The _getch() function returns the ASCII code of the key pressed, not the Unicode code point for the Cyrillic symbol. Therefore, your code is looking for the ASCII code for the Cyrillic symbol 'ы', which does not exist.

To handle Cyrillic symbols, you can try to use the _getwch() function instead, which returns the Unicode code point for the key pressed like this:

int keyBoard;
switch (keyBoard = _getwch()) 
{
  case L'ы':
    y = y + 1;
   Moves[movesCount] = 
Dir::DOWN;
    movesCount++;
    if (isTrail != Trail::FALSE) {
      // changeTrail();
    }
    break;
}

(The L prefix is necessary to ensure that the literal is interpreted as a wide character by the compiler, rather than as a narrow character represented by a single byte.)

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
CloudySh
  • 11
  • 2