欢迎游玩 飞翔的 John Lee!
目前已更新至 1.2 版本,正在持续更新中……
下面给出其源代码,请在 Windows 环境下编译运行,编译选项为 -std=c++14
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#define setcolor(x) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x)
using namespace std;
int dx[]={-1,1,0,0,-1,-1,1,1};
int dy[]={0,0,-1,1,-1,1,1,-1};
void test();
void srand(){int*_=new int;srand(time(0)+*_);delete _;_=0;}
inline int bigrand(){return rand()*32768+rand();}
inline long long hugerand(){return 1ll*rand()*32768*32768*32768+rand()*32768*32768+rand()*32768+rand();}
inline int randrange(int l,int r){return bigrand()%(r-l+1)+l;}
inline bool randpercentage(int p){return bigrand()%100<p;}
inline double rand01(){return bigrand()/32768.0/32768.0;}
inline void printcol(const char* s,int col=0x0f){setcolor(col);printf(s);setcolor(0x0f);}
inline int system(string a){return system(a.c_str());}
inline void printf(string a){printf(a.c_str());}
HWND curhandle;
inline void resethandle(){curhandle=GetForegroundWindow();}
inline bool istopwindow(){return GetForegroundWindow()==curhandle;}
inline bool keydown(int x,bool hist=true)
{
return (hist ? GetAsyncKeyState(x) : (GetAsyncKeyState(x)&(1<<15))) && istopwindow();
}
void setcursorsize(int x)
{
CONSOLE_CURSOR_INFO cursor;
HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleCursorInfo(handle,&cursor);
cursor.dwSize=x;
SetConsoleCursorInfo(handle,&cursor);
}
void hidecursor()
{
CONSOLE_CURSOR_INFO cursor;
HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleCursorInfo(handle,&cursor);
cursor.bVisible=FALSE;
SetConsoleCursorInfo(handle,&cursor);
}
void showcursor()
{
CONSOLE_CURSOR_INFO cursor;
HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleCursorInfo(handle,&cursor);
cursor.bVisible=TRUE;
SetConsoleCursorInfo(handle,&cursor);
}
void disableselect()
{
HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hStdin,&mode);
mode&=~ENABLE_QUICK_EDIT_MODE;
SetConsoleMode(hStdin,mode);
}
int getmousex(bool x=1,bool n=1)
{
HANDLE hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFO consoleCurrentFont;
POINT p;
if(x)
{
GetCursorPos(&p);
ScreenToClient(curhandle,&p);
}
else
{
GetCursorPos(&p);
}
if(n)
{
GetCurrentConsoleFont(hOutput,FALSE,&consoleCurrentFont);
p.x/=consoleCurrentFont.dwFontSize.X;
p.y/=consoleCurrentFont.dwFontSize.Y;
}
return p.y+1;
}
int getmousey(bool x=1,bool n=1)
{
HANDLE hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFO consoleCurrentFont;
POINT p;
if(x)
{
GetCursorPos(&p);
ScreenToClient(curhandle,&p);
}
else
{
GetCursorPos(&p);
}
if(n)
{
GetCurrentConsoleFont(hOutput,FALSE,&consoleCurrentFont);
p.x/=consoleCurrentFont.dwFontSize.X;
p.y/=consoleCurrentFont.dwFontSize.Y;
}
return p.x+1;
}
//void setfontsize(int x)
//{
// HANDLE hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
// CONSOLE_FONT_INFOEX cfi;
// GetCurrentConsoleFontEx(hConsole,FALSE,&cfi);
// cout<<cfi.dwFontSize.X<<" "<<cfi.dwFontSize.Y<<endl;
// cfi.dwFontSize.X=0;
// cfi.dwFontSize.Y=x;
// SetCurrentConsoleFontEx(hConsole,FALSE,&cfi);
//}
int stringtoint(string a)
{
static int ret;
ret=0;
for(int i=0;i<a.size();i++) ret=ret*10+a[i]-'0';
return ret;
}
string inttostring(int a)
{
static string ret;
ret="";
if(!a) return "0";
while(a)
{
ret+=char(a%10+'0');
a/=10;
}
reverse(ret.begin(),ret.end());
return ret;
}
void gotoxy(int x,int y)
{
COORD coord;
coord.X=y;coord.Y=x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
inline void cls(int x=0,int y=0){system("cls");gotoxy(x,y);}
int getkey()//↑921 ↓923 ←925 →926
{
static int ch;
if(_kbhit())
{
ch=_getch();
fflush(stdin);
if(ch==0 || ch==224)
{
ch=_getch();
if(ch==72) return 921;
if(ch==80) return 923;
if(ch==75) return 925;
if(ch==77) return 926;
}
else return ch;
}
return -1;
}
string getinputstring(int x,int y,string init="",bool hidden=false)
{
static int ch;
string ret=init;
while(1)
{
gotoxy(x,y);
for(int i=0;i<ret.size()+2;i++) printf(" ");
gotoxy(x,y);
if(hidden) for(int i=0;i<ret.size();i++) printf("*");
else cout<<ret;
while(1)
{
ch=getkey();
if(ch!=-1) break;
}
if(ch==8 && ret.size()) ret.pop_back();
if(string("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*").find(ch)!=string::npos) ret.push_back(ch);
if(ch==10 || ch==13)
{
return ret;
}
}
}
struct _button
{
int up,left,down,right;
vector<string> text;
int col0,col1,col2;//0=untouched 1=touched 2=pressing
void initialize(int u,int l,int d,int r,vector<string> txt,int c0=0x0f,int c1=0x0e,int c2=0x06)
{
left=l;up=u;right=r;down=d;text=txt;col0=c0;col1=c1;col2=c2;
}
bool check(int x,int y){return up<=x && x<=down && left<=y && y<=right;}
void print(int sta)
{
if(sta==0) setcolor(col0);
if(sta==1) setcolor(col1);
if(sta==2) setcolor(col2);
for(int i=0;i<text.size();i++)
{
gotoxy(up+i-1,left-1);
printf("%s",text[i].c_str());
}
if(sta) setcolor(0x0f);
}
};
struct _buttonscreen
{
vector<_button> buttons;
vector<int> status;
vector<string> background;
void clear()
{
buttons.clear();
status.clear();
}
void initialize(vector<string> bck)
{
clear();
background=bck;
}
void add_button(_button a)
{
buttons.push_back(a);
status.push_back(0);
}
void reprint()
{
cls();
for(int i=0;i<status.size();i++) status[i]=0;
for(int i=0;i<background.size();i++) printf("%s\n",background[i].c_str());
for(int i=0;i<buttons.size();i++) buttons[i].print(0);
keydown(VK_LBUTTON);
}
int update_button_status()
{
static int x,y,cur;cur=-1;
x=getmousex();y=getmousey();
for(int i=0;i<buttons.size();i++)
{
if(buttons[i].check(x,y))
{
cur=i;
if(status[i]!=1) buttons[i].print(1),status[i]=1;
}
if(!buttons[i].check(x,y) && status[i]!=0) buttons[i].print(0),status[i]=0;
}
if(keydown(VK_LBUTTON))
{
if(cur!=-1)
{
buttons[cur].print(2);
status[cur]=2;
}
while(keydown(VK_LBUTTON)) Sleep(100);
if(cur!=-1) if(buttons[cur].check(getmousex(),getmousey())) return cur;
}
return -1;
}
};
_buttonscreen loginbutton,overviewbutton;
struct _statistics
{
int games_played;
int distance_total;
int distance_max;
int score_end_total;
int score_end_max;
int score_gained_total;
int score_gained_max;
int score_used_total;
int score_used_max;
int move_count;
int jump_count;
int dive_count;
int bounce_up_count;
int bounce_down_count;
int bonus_total;
int bouns_collected;
int bonus_collected_max;
int bouns_collected_score;
int bouns_collected_score_max;
int pause_count;
int obstacles_passed;
int obstacles_passed_max;
void initialize()
{
memset(this,0,sizeof(*this));
}
void update(_statistics a)
{
bonus_collected_max=max(bonus_collected_max,a.bonus_collected_max);
bonus_total+=a.bonus_total;
bounce_down_count+=a.bounce_down_count;
bounce_up_count+=a.bounce_up_count;
bouns_collected+=a.bouns_collected;
bouns_collected_score+=a.bouns_collected_score;
bouns_collected_score_max=max(bouns_collected_score_max,a.bouns_collected_score_max);
distance_max=max(distance_max,a.distance_max);
distance_total+=a.distance_total;
dive_count+=a.dive_count;
games_played+=a.games_played;
jump_count+=a.jump_count;
move_count+=a.move_count;
obstacles_passed+=a.obstacles_passed;
obstacles_passed_max=max(obstacles_passed_max,a.obstacles_passed_max);
pause_count+=a.pause_count;
score_end_max=max(score_end_max,a.score_end_max);
score_end_total+=a.score_end_total;
score_gained_max=max(score_gained_max,a.score_gained_max);
score_gained_total+=a.score_gained_total;
score_used_max=max(score_used_max,a.score_used_max);
score_used_total+=a.score_used_total;
}
};
_statistics stats;
bool _admin=false;
const int N=105;
char str[N][N];
char lst[N][N];
int lstx,lsty;
int n=30,m=60,dis,xx,yy,score=2160,pre;
int realx=xx*10000;
struct _difficulty
{
int obstacle_freqency;
int obs_distance;
int top_space;
int middle_space;
int down_space;
int top_limit;
int middle_limit;
int down_limit;
};
_difficulty diffi[6]=
{
(_difficulty){0,0,0,0,0,0,0,0},
(_difficulty){40,20,6,10,6,30,30,30},//简单
(_difficulty){30,15,4, 8,4,30,30,30},//普通
(_difficulty){25,10,3, 6,3,15,20,15},//困难
(_difficulty){21, 8,3, 4,3,10,15,10},//不可能
(_difficulty){18, 6,2, 3,2, 8,12, 8},//真·不可能
};
struct _settings
{
int difficulty;
bool update_stats;
};
int gravity=925;
double tickspeed=0.03;
int vx=0;
bool used[1020];
bool _debug=_admin;
int lstdebug;
ifstream inf;
ofstream outf;
string username;
string abspth="C:\\ProgramData\\SilvefishGames\\FlyingJL\\";
void program_initialize()
{
loginbutton.initialize({
"",
"",
" 欢迎使用 飞翔的John Lee v1.2",
"",
" 单击此处进入游戏"
});
loginbutton.add_button((_button){5,11,5,26,{"单击此处进入游戏"},0x0f,0x02,0x0a});
overviewbutton.initialize({
"",
" 退出游戏",
"",
" 飞翔的John Lee v1.2",
"",
" +----------+ +----------+ +----------+",
" | 游戏设置 | | 开始游戏 | | 统计信息 |",
" +----------+ +----------+ +----------+",
});
overviewbutton.add_button((_button){6,17,8,28,{"+----------+","| 开始游戏 |","+----------+"},0x0f,0x02,0x0a});
overviewbutton.add_button((_button){6,3,8,14,{"+----------+","| 游戏设置 |","+----------+"},0x0f,0x02,0x0a});
overviewbutton.add_button((_button){6,31,8,42,{"+----------+","| 统计信息 |","+----------+"},0x0f,0x02,0x0a});
overviewbutton.add_button((_button){2,3,2,10,{"退出游戏"},0x0f,0x02,0x0a});
}
int TIME;
void printscreen()
{
gotoxy(0,0);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(str[i][j]==lst[i][j] && !(lstx==i && lsty==j) && !(xx==i && yy==j)) continue;
gotoxy(i-1,(j-1)*2);
if(i==xx&&j==yy) printcol("02",0x4f);
else if(str[i][j]=='#') printcol(" ",0xf0);
else if(str[i][j]=='+') printcol("16",0x20);
else printcol(" ",0x0f);
}
}
gotoxy(n+1,0);
printf("移动距离 : %d \n分数 : %05d \n",TIME,score);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
lst[i][j]=str[i][j];
}
}
lstx=xx,lsty=yy;
printf("\n");
printf("本局统计信息:\n");
printf("移动了 %d 次, 跳跃了 %d 次, 俯冲了 %d 次\n",stats.move_count,stats.jump_count,stats.dive_count);
printf("获得了 %d 分, 消耗了 %d 分\n",stats.score_gained_total,stats.score_used_total);
printf("遇到了 %d 个奖励, 其中收集了 %d 个, 准度为 %.2lf% \n",stats.bonus_total,stats.bouns_collected,100.0*stats.bouns_collected/stats.bonus_total);
printf("通过奖励获得了 %d 分, 平均每个奖励 %.2lf 分 \n",stats.bouns_collected_score,1.0*stats.bouns_collected_score/stats.bouns_collected);
printf("撞到了 %d 次天花板, 碰到了 %d 次地板\n",stats.bounce_up_count,stats.bounce_down_count);
printf("越过了 %d 个障碍物\n",stats.obstacles_passed);
printf("暂停了 %d 次\n",stats.pause_count);
if(_debug)
{
printf("\n");
printf("DebugInfo:\n");
printf("xx = %2d yy = %2d\n",xx,yy);
printf("rx = %6d vx = %6d\n",realx,vx);
printf("gravity = %6d\n",gravity);
}
else
{
printf("\n");
printf(" \n");
printf(" \n",xx,yy);
printf(" \n",realx,vx);
printf(" \n",gravity);
}
}
struct userdata
{
string username;
_statistics stats[6];
_settings settings;
void updatestats(_statistics a,int difficulty)
{
stats[difficulty].update(a);
}
};
userdata user;
void statistics(int difficulty)
{
cls();
printf(user.username+"的统计信息:\n\n");
printf(" 游玩次数 : %8d\n",user.stats[difficulty].games_played);
printf(" 暂停次数 : %8d\n",user.stats[difficulty].pause_count);
printf(" 移动次数 : %8d\n",user.stats[difficulty].move_count);
printf(" 跳跃次数 : %8d\n",user.stats[difficulty].jump_count);
printf(" 俯冲次数 : %8d\n",user.stats[difficulty].dive_count);
printf("\n");
printf(" 行走距离 : %8d (单局最大 %d)\n",user.stats[difficulty].distance_total,user.stats[difficulty].distance_max);
printf("越过障碍个数 : %8d (单局最大 %d)\n",user.stats[difficulty].obstacles_passed,user.stats[difficulty].obstacles_passed_max);
printf("撞天花板次数 : %8d\n",user.stats[difficulty].bounce_up_count);
printf("撞到地板次数 : %8d\n",user.stats[difficulty].bounce_down_count);
printf("\n");
printf(" 获得分数 : %8d (单局最大 %d)\n",user.stats[difficulty].score_gained_total,user.stats[difficulty].score_gained_max);
printf(" 消耗分数 : %8d (单局最大 %d)\n",user.stats[difficulty].score_used_total,user.stats[difficulty].score_used_max);
printf(" 最高分 : %8d\n",user.stats[difficulty].score_end_max);
printf("奖励收集个数 : %8d (单局最大 %d)\n",user.stats[difficulty].bouns_collected,user.stats[difficulty].bonus_collected_max);
printf("奖励收集分数 : %8d (单局最大 %d)\n",user.stats[difficulty].bouns_collected_score,user.stats[difficulty].bouns_collected_score_max);
if(100.0*user.stats[difficulty].bouns_collected/user.stats[difficulty].bonus_total>=10.0) printf("奖励收集准度 : %.2lf%\n",100.0*user.stats[difficulty].bouns_collected/user.stats[difficulty].bonus_total);
else printf("奖励收集准度 : %.2lf%\n",100.0*user.stats[difficulty].bouns_collected/user.stats[difficulty].bonus_total);
printf("平均奖励得分 : %8d\n",int(round(1.0*user.stats[difficulty].bouns_collected_score/user.stats[difficulty].bouns_collected)+0.5));
printf("\n当前难度 : ");
switch(difficulty)
{
case 1 : printf("简单");break;
case 2 : printf("普通");break;
case 3 : printf("困难");break;
case 4 : printf("不可能");break;
case 5 : printf("真·不可能");break;
}
printf("\n");
printf("\n按下 Q 键切换难度\n");
printf("\n按下 Esc 或 S 键退出\n");
}
void settings()
{
cls();
printf("游戏设置\n\n");
printf("难度 : ");
switch(user.settings.difficulty)
{
case 1 : printf("简单");break;
case 2 : printf("普通");break;
case 3 : printf("困难");break;
case 4 : printf("不可能");break;
case 5 : printf("真·不可能");break;
}
printf(" (按下 Q 键更改)\n\n");
if(user.settings.update_stats) printf("游戏结束时计入统计信息 : 开启 (按下 W 键更改)\n\n");
else printf("游戏结束时计入统计信息 : 关闭 (按下 W 键更改)\n\n");
printf("按下 Esc 或 A 键退出");
}
void overview()
{
cls();
// printf("Flying John Lee v1.2\n\n");
// printf("按下空格键开始游戏\n\n");
// printf("按下 A 键进行游戏设置\n\n");
// printf("按下 S 键查看统计信息\n\n");
gotoxy(3,10);printf("飞翔的 John Lee v1.2");
}
void readuserinfo(string file)
{
if(file=="stats")
{
inf.open(("C:\\ProgramData\\SilvefishGames\\FlyingJL\\users\\"+user.username+"\\stats.txt").c_str());
for(int i=1;i<=5;i++)
inf>>user.stats[i].bonus_collected_max
>>user.stats[i].bonus_total
>>user.stats[i].bounce_down_count
>>user.stats[i].bounce_up_count
>>user.stats[i].bouns_collected
>>user.stats[i].bouns_collected_score
>>user.stats[i].bouns_collected_score_max
>>user.stats[i].distance_max
>>user.stats[i].distance_total
>>user.stats[i].dive_count
>>user.stats[i].games_played
>>user.stats[i].jump_count
>>user.stats[i].move_count
>>user.stats[i].obstacles_passed
>>user.stats[i].pause_count
>>user.stats[i].score_end_max
>>user.stats[i].score_end_total
>>user.stats[i].score_gained_max
>>user.stats[i].score_gained_total
>>user.stats[i].score_used_max
>>user.stats[i].score_used_total
>>user.stats[i].obstacles_passed_max;
inf.close();
}
if(file=="settings")
{
inf.open(("C:\\ProgramData\\SilvefishGames\\FlyingJL\\users\\"+user.username+"\\settings.txt").c_str());
inf>>user.settings.difficulty
>>user.settings.update_stats;
inf.close();
}
}
void updateuserinfo(string file)
{
if(file=="stats")
{
outf.open(("C:\\ProgramData\\SilvefishGames\\FlyingJL\\users\\"+user.username+"\\stats.txt").c_str());
for(int i=1;i<=5;i++)
outf<<user.stats[i].bonus_collected_max<<"\n"
<<user.stats[i].bonus_total<<"\n"
<<user.stats[i].bounce_down_count<<"\n"
<<user.stats[i].bounce_up_count<<"\n"
<<user.stats[i].bouns_collected<<"\n"
<<user.stats[i].bouns_collected_score<<"\n"
<<user.stats[i].bouns_collected_score_max<<"\n"
<<user.stats[i].distance_max<<"\n"
<<user.stats[i].distance_total<<"\n"
<<user.stats[i].dive_count<<"\n"
<<user.stats[i].games_played<<"\n"
<<user.stats[i].jump_count<<"\n"
<<user.stats[i].move_count<<"\n"
<<user.stats[i].obstacles_passed<<"\n"
<<user.stats[i].pause_count<<"\n"
<<user.stats[i].score_end_max<<"\n"
<<user.stats[i].score_end_total<<"\n"
<<user.stats[i].score_gained_max<<"\n"
<<user.stats[i].score_gained_total<<"\n"
<<user.stats[i].score_used_max<<"\n"
<<user.stats[i].score_used_total<<"\n"
<<user.stats[i].obstacles_passed_max<<"\n";
outf.close();
}
if(file=="settings")
{
outf.open(("C:\\ProgramData\\SilvefishGames\\FlyingJL\\users\\"+user.username+"\\settings.txt").c_str());
outf<<user.settings.difficulty<<"\n";
outf<<user.settings.update_stats<<"\n";
outf.close();
}
}
void login()
{
loginbutton.reprint();
int res;
while(1)
{
while((res=loginbutton.update_button_status())==-1) Sleep(100);
if(res==0) break;
}
user.username="Silvefish";
system("mkdir C:\\ProgramData\\SilvefishGames\\FlyingJL\\users\\"+user.username);
readuserinfo("stats");
readuserinfo("settings");
}
void playgame()
{
hidecursor();
cls();
stats.initialize();
srand(time(NULL));
score=2160;xx=n/2,yy=1;realx=xx*10000;vx=0;
gotoxy(n,0);
int difficulty=user.settings.difficulty;
for(int i=1;i<=m;i++) printcol(" ",0xf0);
for(int i=1;i<=n;i++) for(int j=1;j<=m+1;j++) str[i][j]='.';
keydown(VK_LEFT);
keydown(VK_RIGHT);
keydown(VK_UP);
keydown(VK_DOWN);
keydown(VK_SPACE);
keydown(VK_ESCAPE);
keydown('1');
for(TIME=1;;TIME++,score+=2,stats.score_gained_total+=2,stats.distance_total++)
{
int tmp=clock();
realx+=vx;
vx+=gravity;
xx=realx/10000.0+0.5;
if(xx<=1)
{
xx=1;
vx=abs(vx*0.8)+5000;
realx=10000;
stats.bounce_up_count++;
}
if(xx>=n)
{
xx=n;
vx=-abs(vx*0.8);
realx=n*10000;
stats.bounce_down_count++;
}
if((keydown(VK_UP) || keydown('W')))
{
if(!used[921] && xx>1)
{
vx=-10000;
score-=15;
stats.score_used_total+=15;
used[921]=true;
stats.jump_count++;
}
}
else used[921]=false;
if((keydown(VK_DOWN) || keydown('S')))
{
if(!used[923] && xx<n)
{
vx=20000;
score-=15;
stats.score_used_total+=15;
used[923]=true;
stats.dive_count++;
}
}
else used[923]=false;
if((keydown(VK_LEFT) || keydown('A')) && yy>1) yy--,score--,stats.move_count++,stats.score_used_total++;
if((keydown(VK_RIGHT) || keydown('D')) && yy<m) yy++,score--,stats.move_count++,stats.score_used_total++;
if(str[xx][yy]=='#' && !_admin)
{
printscreen();
break;
}
if(TIME>10 && randrange(1,diffi[difficulty].obstacle_freqency)==1 && pre>=diffi[difficulty].obs_distance)
{
int up,down;
if(rand()%3)
{
do
{
down=randrange(1,n),up=randrange(1,n);
if(up>down) swap(up,down);
}
while(!(up>=4 && down<=n-3 && down-up-1>=diffi[difficulty].middle_space && down-up-1<=diffi[difficulty].middle_limit));
for(int i=1;i<=n;i++) str[i][m+1]='.';
for(int i=1;i<=up;i++) str[i][m+1]='#';
for(int i=down;i<=n;i++) str[i][m+1]='#';
}
else
{
do
{
down=randrange(1,n),up=randrange(1,n);
if(up>down) swap(up,down);
}
while(!(down-up+1>=6 && up-1>=diffi[difficulty].top_space && up-1<=diffi[difficulty].top_limit && n-down>=diffi[difficulty].down_space && n-down<=diffi[difficulty].down_limit));
for(int i=1;i<=n;i++) str[i][m+1]='.';
for(int i=up;i<=down;i++) str[i][m+1]='#';
}
pre=0;
}
else
{
for(int i=1;i<=n;i++){
int r=rand()%(n*n);
if(r==0) str[i][m+1]='+';
else str[i][m+1]='.';
}
pre++;
}
for(int i=1;i<=n;i++) for(int j=0;j<=m;j++) str[i][j]=str[i][j+1];
bool f=false;
for(int i=1;i<=n;i++)
{
if(str[i][0]=='+') stats.bonus_total++;
if(str[i][0]=='#') f=true;
}
if(f) stats.obstacles_passed++;
if(str[xx][yy]=='#' && !_admin)
{
printscreen();
break;
}
if(keydown('1') && clock()-lstdebug>=0.3*CLOCKS_PER_SEC) _debug=!_debug,lstdebug=clock();
if(keydown(VK_SPACE))
{
while(keydown(VK_SPACE));
while(!keydown(VK_SPACE))
{
if(keydown(VK_ESCAPE))
{
int ans=MessageBox(curhandle,"您确定要退出当前游戏吗?","警告",MB_YESNO|MB_DEFBUTTON2);
if(ans==6) return;
}
Sleep(100);
}
while(keydown(VK_SPACE));
stats.pause_count++;
}
printscreen();
if(str[xx][yy]=='+')
{
int r=rand()%216+1;
score+=r;
stats.bouns_collected_score+=r;
stats.score_gained_total+=r;
str[xx][yy]='.';
stats.bonus_total++;
stats.bouns_collected++;
}
for(int i=0;i<8;i++)
{
if(str[xx+dx[i]][yy+dy[i]]=='+')
{
int r=rand()%216+1;
score+=r;
stats.bouns_collected_score+=r;
stats.score_gained_total+=r;
str[xx+dx[i]][yy+dy[i]]='.';
stats.bonus_total++;
stats.bouns_collected++;
}
}
if(score<0 && !_admin)
{
printscreen();
puts("Game Over!!!");
break;
}
if(keydown(VK_ESCAPE))
{
int ans=MessageBox(curhandle,"您确定要退出当前游戏吗?","警告",MB_YESNO|MB_DEFBUTTON2);
if(ans==6) return;
}
while(clock()-tmp<=tickspeed*CLOCKS_PER_SEC);
// system("pause > nul");
}
for(int j=1;j<yy;j++)
{
bool f=false;
for(int i=1;i<=n;i++)
{
if(str[i][j]=='+') stats.bonus_total++;
if(str[i][j]=='#') f=true;
}
if(f) stats.obstacles_passed++;
}
printscreen();
if(!_admin && user.settings.update_stats)
{
stats.bonus_collected_max=stats.bouns_collected;
stats.bouns_collected_score_max=stats.bouns_collected_score;
stats.distance_max=stats.distance_total;
stats.score_end_max=stats.score_end_total=score;
stats.score_gained_max=stats.score_gained_total;
stats.score_used_max=stats.score_used_total;
stats.obstacles_passed_max=stats.obstacles_passed;
stats.games_played=1;
user.updatestats(stats,difficulty);
updateuserinfo("stats");
}
printf("\n\nDistance : %d\n\nScore : %d\n\n",TIME,score);
printf("Press spacebar to continue...");
keydown(' ');
while(!keydown(' ')) Sleep(100);
while(keydown(' '));
}
void run_statistics()
{
int difficulty=1;
hidecursor();
bool quit=false;
keydown('Q');
keydown('S');
keydown(VK_ESCAPE);
while(1)
{
if(quit) break;
statistics(difficulty);
while(1)
{
if(keydown('Q'))
{
while(keydown('Q'));
difficulty++;
if(difficulty==6) difficulty=1;
break;
}
if(keydown(VK_ESCAPE))
{
while(keydown(VK_ESCAPE));
quit=true;
break;
}
if(keydown('S'))
{
while(keydown('S'));
quit=true;
break;
}
Sleep(100);
}
}
}
void run_settings()
{
bool quit=false;
keydown('Q');
keydown('W');
keydown('A');
keydown(VK_ESCAPE);
while(1)
{
if(quit) break;
settings();
while(1)
{
if(keydown('Q'))
{
while(keydown('Q'));
user.settings.difficulty++;
if(user.settings.difficulty==6) user.settings.difficulty=1;
break;
}
if(keydown('W'))
{
while(keydown('W'));
user.settings.update_stats=!user.settings.update_stats;
break;
}
if(keydown(VK_ESCAPE))
{
while(keydown(VK_ESCAPE));
quit=true;
break;
}
if(keydown('A'))
{
while(keydown('A'));
quit=true;
break;
}
Sleep(100);
}
updateuserinfo("settings");
}
}
void run_overview()
{
hidecursor();
overviewbutton.reprint();
int res;
while(1)
{
while((res=overviewbutton.update_button_status())==-1) Sleep(100);
if(res==0)
{
playgame();
break;
}
if(res==1)
{
run_settings();
break;
}
if(res==2)
{
run_statistics();
break;
}
if(res==3)
{
int ans=MessageBox(curhandle,"您确定要退出游戏吗?","警告",MB_YESNO|MB_DEFBUTTON2);
if(ans==6) exit(0);
}
}
}
int main()
{
// test();
setcolor(0x0f);
hidecursor();
disableselect();
program_initialize();
system("title 飞翔的John Lee");
system("mode con lines=60 cols=120");
system("mkdir C:\\ProgramData\\SilvefishGames\\FlyingJL");
resethandle();
login();
while(1)
{
run_overview();
}
return 0;
}
void test()
{
setcolor(0x0f);
system("mode con lines=60 cols=120");
resethandle();
hidecursor();
disableselect();
system("pause > nul");
_buttonscreen a;
a.initialize({
"Hello ",
" Button1",
" Button2 ",
" 3 ",
" 3 Button4 ",
" 3 Button4 "
});
a.add_button((_button){2,8,2,14,{"Button1"},0x0f,0x02,0x0a});
a.add_button((_button){3,5,3,11,{"Button2"},0x0f,0x02,0x0a});
a.add_button((_button){4,3,6,3,{"3","3","3"},0x0f,0x02,0x0a});
a.add_button((_button){5,7,6,13,{"Button4","Button4"},0x0f,0x02,0x0a});
a.reprint();
int res;
while(1)
{
while((res=a.update_button_status())==-1) Sleep(100);
MessageBox(curhandle,inttostring(res).c_str(),"",MB_OK);
}
exit(0);
}
/**/