Skip to content

Commit f3e1985

Browse files
eren-terziogluxiaoxiang781216
authored andcommitted
games/snake: Change consolekey magic numbers with ASCII macros
Change consolekey magic numbers with ascii values to make it more understandable Signed-off-by: Eren Terzioglu <[email protected]>
1 parent 9ea3fc6 commit f3e1985

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

games/snake/snake_input_console.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
****************************************************************************/
2626

2727
#include <nuttx/config.h>
28+
#include <nuttx/ascii.h>
2829
#include <termios.h>
2930

3031
#include "snake_inputs.h"
@@ -188,24 +189,24 @@ int dev_read_input(FAR struct input_state_s *dev)
188189

189190
/* Arrows keys return three bytes: 27 91 [65-68] */
190191

191-
if ((ch = getch()) == 27)
192+
if ((ch = getch()) == ASCII_ESC)
192193
{
193-
if ((ch = getch()) == 91)
194+
if ((ch = getch()) == ASCII_LBRACKET)
194195
{
195196
ch = getch();
196-
if (ch == 65)
197+
if (ch == ASCII_A)
197198
{
198199
dev->dir = DIR_UP;
199200
}
200-
else if (ch == 66)
201+
else if (ch == ASCII_B)
201202
{
202203
dev->dir = DIR_DOWN;
203204
}
204-
else if (ch == 67)
205+
else if (ch == ASCII_C)
205206
{
206207
dev->dir = DIR_RIGHT;
207208
}
208-
else if (ch == 68)
209+
else if (ch == ASCII_D)
209210
{
210211
dev->dir = DIR_LEFT;
211212
}

0 commit comments

Comments
 (0)