I have got a problem with my code c++ when i assay to compile it. ^
This is the complete code ,the error line is just down includes
#include <string>
#include <iostream>
#include <cstdlib>
#include <cstdio>
//#include <conio.h>
#include <ncurses.h>
#include <time.h>
using namespace std;
const char KEY_LEFT = 'a', KEY_RIGHT = 'd',KEY_UP = 'w', KEY_DOWN ='s';
const int HEIGHT = 25, WIDTH = 40;
bool hasntWon = true;
int hP = 100;
//unsigned char healthbar [10] = {'*','*','*','*','*','*','*','*','*','*'};
enum DirectionX {Right,Left};
enum DirectionY {Up,Down};
struct Player {
char sprite;
int x;
int y;
};
struct Enemy{
char sprite;
int x;
int y;
DirectionX pastDirX;
DirectionY pastDirY;
};
Per the comments you are including ncurses.h
, which contains
#define KEY_LEFT 0404 /* left-arrow key */
That is a macro, which will automatically be substituted by the preprocessor, turning your code into
const int 0404 = 'a' /* ... */;
0404
is not a valid variable name, so your code does not compile. In general, you could try to redefine these macros (via #define
). However, redefining them may cause havoc in other places.
If you are trying to treat a just like ← , I would recommand checking for the appropriate key instead of (or alongside to) KEY_LEFT
in whatever place you use that macro.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.