I am trying to follow a snake tutorial game using C++. However, it seems they were using some windows libraries and in my case I am compiling it on Linux. The problem is in my Input() method, I tried changing it with a recommended code I found on here, but that did not quite worked for me. Is there a way to go around this or any recommendation? Thanks.
#include <iostream>
#include <stdio.h>
#include <ncurses.h>
#include <unistd.h>
.....
//Get the key input inorder to move the snake around
void Input() {
//Tried this from the stackoverlow recommendations, did not work for my situation
if (getch() == '\033') {
getch();
switch(getch()) { // the real value
case 'A':
// code for arrow up
direction = UP;
break;
case 'B':
// code for arrow down
direction = DOWN;
break;
case 'C':
// code for arrow right
direction = RIGHT;
break;
case 'D':
// code for arrow left
direction = LEFT;
break;
case 'Q':
gameOver = true;
break;
default:
break;
}
}
}
.....
The issue I am having with is that linux does not accept the kbhit() which what the snake game tutorial was using, so I tried to modify it with what I have above, however it does not move the snake.