看到灌水区里一片windows小游戏,然而像我这种用linux的蒟蒻(嗯?)根本玩不了
** so , 就有了这个头文件: **
把windows.h和conio.h什么的换成下面这个就行了
#include <bits/stdc++.h>
#include <sys/time.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
int getch()
{
struct termios tm, tm_old;
int fd = 0, ch;
if (tcgetattr(fd, &tm) < 0) {//保存现在的终端设置
return -1;
}
tm_old = tm;
cfmakeraw(&tm);//更改终端设置为原始模式,该模式下所有的输入数据以字节为单位被处理
if (tcsetattr(fd, TCSANOW, &tm) < 0) {//设置上更改之后的设置
return -1;
}
ch = getchar();
if (tcsetattr(fd, TCSANOW, &tm_old) < 0) {//更改设置为最初的样子
return -1;
}
return ch;
}
int clock__()
{
struct timeval tv;
struct timezone tz;
gettimeofday(&tv,&tz);
return tv.tv_sec*1000 + tv.tv_usec/1000;
}
void gotonow(int x,int y)//X表示行,Y表示列
{
if(x>0) printf("\033[%dB",x);
else if(x<0) printf("\033[%dA",-x);
if(y>0) printf("\033[%dC",y);
else if(y<0) printf("\033[%dD",-y);
}
void gotoxy(int x,int y)//X表示行,Y表示列
{
}
int kbhit(void)
{
struct termios oldt, newt;
int ch;
int oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if(ch != EOF)
{
ungetc(ch, stdin);
return 1;
}
return 0;
}
int system__(const char *s)
{
std::string ifs = s;
if(ifs=="cls") return system("clear");
else if(ifs=="pause")
{
printf("按任意键继续\n");
getch();
return 0;
}
else if(s[0]=='d' && s[1]=='e' && s[2]=='l' && s[3]==' ')
{
std::string ss = (s+4);
return system(("rm "+ss).c_str());
}
else if(s[0]=='c' && s[1]=='o' && s[2]=='l' && s[3]=='o' && s[4]=='r')
{
int wc=30 , bc=40;
std::string ss = ifs;
if(ifs.size() != 8)
{
printf("\033[0m");
return 0;
}
for(int i=6;i<=7;i++)
{
int add , si = ss[i]-'0';
if(ss[i] >= 'a' && ss[i] <= 'f') si = ss[i] - 'a' + 10;
if(si%8 == 0) add = 0;
else if(si%8 == 1) add = 4;
else if(si%8 == 2) add = 2;
else if(si%8 == 3) add = 2;
else if(si%8 == 4) add = 1;
else if(si%8 == 5) add = 5;
else if(si%8 == 6) add = 3;
else if(si%8 == 7) add = 7;
else return -1;
if(i == 6) bc += add;
else if(i == 7) wc += add;
}
printf("\e[%d;%dm",wc,bc);
return 0;
}
else if(ifs.substr(0,4) == "copy")
return system(("cp" + ifs.substr(4,ifs.size())).c_str());
else return system(s);
}
int Sleep(int time)
{
return usleep(time*1000);
}
int MessageBox(int* x,const char* s,const char* title__,int y)
{
std::string empty_line = "\n ";
std::string text = s , title = title__;
if(y == 1)
return system__(("zenity --info --title=\"" + title + "\" --text=\"" + text + empty_line + "\" 2> /dev/null").c_str());
if(y == 2)
return system__(("zenity --question --title=\"" + title + "\" --text=\"" + text + empty_line + "\" 2> /dev/null").c_str());
return -1;
}
#define clock clock__