#include <iostream>
#include <stdio.h>
#include <curses.h>
#include <sys/time.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
这些是用g++编译所需要的头文件,其实用c和c++都可以,我用g++编译的,其实也没用到什么c++的东西,如果用gcc,需要的头文件可能会有变化,反正试一下就好了。
编译命令:
g++ /home/parker/Desktop/double_snake/main.cpp -lcurses -o snake
执行:./snake
虽然我在我的Ubuntu上也装了codeblocks,但是Curses的相关内容,没法在IDE里直接编译运行,必须要到terminal里,执行这句话,用-lcurses来调用系统的编译库,如果还没装curses库就先去下一个。-o后面命名一下。如果是c文件了话,就用gcc,后面.cpp变成.c。
我的主函数:
int main(){
initscr();
initcolor();
cbreak();// keyboard event at once
noecho();
clear();
signal(SIGALRM, update);
init();
countrol();
endwin();
return 0;
}
initscr()是curses自带的,初始化。
initcolor()是我自己写的,后面说。