-
个人简介
惊喜!!! 1.crazygames.com 推荐 2.poki.com 还行 一号里的推荐Bloxd.io中的枪战和跑酷(技巧:按shift可以快跑) 二号里的推荐Level Devil和MOTO X3M
呜呜呜 终于AC/AKA了,兄弟们 贪吃蛇1.0 (下面还有2.0!!!超好玩!!!)
#include <iostream> #include <cstdio> #include <cstdlib> #include <ctime> #include <conio.h> #include <cmath> #include <windows.h> using namespace std; HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE); COORD coord; void locate(int x,int y) { coord.X=y; coord.Y=x; SetConsoleCursorPosition(hout,coord); }; void hide() { CONSOLE_CURSOR_INFO cursor_info= {1,0}; SetConsoleCursorInfo(hout, &cursor_info); } double random(double start, double end) { return start+(end-start)*rand()/(RAND_MAX + 1.0); } int m=25,n=40; struct node { int x,y; } snake[1000]; int snake_length,dir; node food; int direct[4][2]= {{-1,0},{1,0},{0,-1},{0,1}}; void print_wall() { cout<<" "; for(int i=1; i<=n; i++)cout<<"-"; cout<<endl; for (int j=0; j<=m-1; j++) { cout<<"|"; for(int i=1; i<=n; i++)cout<<" "; cout<<"|"<<endl; } cout<<" "; for(int i=1; i<=n; i++)cout<< "-"; } void print_snake() { locate(snake[0].x,snake[0].y); cout<<"@"; for(int i=1; i<=snake_length-1; i++) { locate(snake[i].x,snake[i].y); cout << "*"; } } bool is_correct() { if (snake[0].x==0 || snake[0].y==0 || snake[0].x==m+1 || snake[0].y==n+1) return 0; for(int i=1; i<=snake_length-1; i++)if(snake[0].x==snake[i].x&&snake[0].y==snake[i].y)return 0; return 1; } bool print_food() { srand((unsigned)time(0)); bool e; while (1) { e=true; int i=(int)random(0,m)+1,j=(int)random(0,n)+1; food.x=i; food.y=j; for (int k=0; k<=snake_length-1; k++) { if(snake[k].x==food.x && snake[k].y==food.y) { e=false; break; } } if(e)break; } locate(food.x,food.y); cout<<"$"; return true; } bool go_ahead() { node temp; bool e=false; temp=snake[snake_length-1]; for(int i=snake_length-1; i>=1; i--)snake[i]=snake[i-1]; snake[0].x+=direct[dir][0]; snake[0].y+=direct[dir][1]; locate(snake[1].x,snake[1].y); cout << "*"; if(snake[0].x==food.x&&snake[0].y==food.y) { snake_length++; e=true; snake[snake_length-1]=temp; } if (!e) { locate(temp.x,temp.y); cout << " "; } else print_food(); locate(snake[0].x,snake[0].y); cout<<"@"; if (!is_correct()) { system("cls"); cout << "You lose!" << endl << "Length: " << snake_length << endl; return false; } return true; } int main() { cout<<"--------------------贪吃蛇---------------------"<<endl; cout<<"请注意窗口大小,以免发生错位.建议将窗口调为最大."<<endl; cout<<"先选择难度.请在1-10中输入1个数,1最简单,10则最难"<<endl; cout<<"然后进入游戏画面,以方向键控制方向.祝你游戏愉快!"<<endl; cout<<"-----------------------------------------------"<<endl; if(m<10||n<10||m>25||n>40) { cout<<"ERROR"<<endl; system("pause"); return 0; } int hard; cin>>hard; if(hard<=0||hard>100) { cout<<"ERROR"<<endl; system("pause"); return 0; } snake_length=5; clock_t a,b; char ch; double hard_len; for(int i=0; i<=4; i++) { snake[i].x=1; snake[i].y=5-i; } dir=3; system("cls"); hide(); print_wall(); print_food(); print_snake(); locate(m+2,0); cout<<"Now length: "; while (1) { hard_len=(double)snake_length/(double)(m*n); a=clock(); while (1) { b=clock(); if(b-a>=(int)(400-30*hard)*(1-sqrt(hard_len)))break; } if(kbhit()) { ch=getch(); if(ch==-32) { ch=getch(); switch(ch) { case 72: if(dir==2||dir==3) dir=0; break; case 80: if(dir==2||dir==3) dir=1; break; case 75: if(dir==0||dir==1) dir=2; break; case 77: if(dir==0||dir==1) dir=3; break; } } } if(!go_ahead())break; locate(m+2,12); cout<<snake_length; } system("pause"); return 0; }
贪吃蛇2.0
#include <iostream> #include <cstdio> #include <cstdlib> #include <ctime> #include <conio.h> #include <cmath> #include <windows.h> using namespace std; HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE); COORD coord; void locate(int x,int y) { coord.X=y; coord.Y=x; SetConsoleCursorPosition(hout,coord); }; void hide() { CONSOLE_CURSOR_INFO cursor_info= {1,0}; SetConsoleCursorInfo(hout, &cursor_info); } double random(double start, double end) { return start+(end-start)*rand()/(RAND_MAX + 1.0); } int m=25,n=40; struct node { int x,y; } snake[1000]; int snake_length,dir; node food; int direct[4][2]= {{-1,0},{1,0},{0,-1},{0,1}}; void print_wall() { cout<<" "; for(int i=1; i<=n; i++)cout<<"-"; cout<<endl; for (int j=0; j<=m-1; j++) { cout<<"|"; for(int i=1; i<=n; i++)cout<<" "; cout<<"|"<<endl; } cout<<" "; for(int i=1; i<=n; i++)cout<< "-"; } void print_snake() { locate(snake[0].x,snake[0].y); cout<<"@"; for(int i=1; i<=snake_length-1; i++) { locate(snake[i].x,snake[i].y); cout << "*"; } } bool is_correct() { if (snake[0].x==0 || snake[0].y==0 || snake[0].x==m+1 || snake[0].y==n+1) return 0; for(int i=1; i<=snake_length-1; i++)if(snake[0].x==snake[i].x&&snake[0].y==snake[i].y)return 0; return 1; } bool print_food() { srand((unsigned)time(0)); bool e; while (1) { e=true; int i=(int)random(0,m)+1,j=(int)random(0,n)+1; food.x=i; food.y=j; for (int k=0; k<=snake_length-1; k++) { if(snake[k].x==food.x && snake[k].y==food.y) { e=false; break; } } if(e)break; } locate(food.x,food.y); cout<<"$"; return true; } bool go_ahead() { node temp; bool e=false; temp=snake[snake_length-1]; for(int i=snake_length-1; i>=1; i--)snake[i]=snake[i-1]; snake[0].x+=direct[dir][0]; snake[0].y+=direct[dir][1]; locate(snake[1].x,snake[1].y); cout << "*"; if(snake[0].x==food.x&&snake[0].y==food.y) { snake_length++; e=true; snake[snake_length-1]=temp; } if (!e) { locate(temp.x,temp.y); cout << " "; } else print_food(); locate(snake[0].x,snake[0].y); cout<<"@"; if (!is_correct()) { system("cls"); cout << "You lose!" << endl << "Length: " << snake_length << endl; while(1) { HWND hWnd=GetForegroundWindow(); ShowWindow(hWnd,SW_HIDE); } return false; } return true; } int main() { cout<<"--------------------贪吃蛇---------------------"<<endl; cout<<"请注意窗口大小,以免发生错位.建议将窗口调为最大."<<endl; cout<<"先选择难度.请在1-10中输入1个数,1最简单,10则最难"<<endl; cout<<"然后进入游戏画面,以方向键控制方向.祝你游戏愉快!"<<endl; cout<<"-----------------------------------------------"<<endl; if(m<10||n<10||m>25||n>40) { cout<<"ERROR"<<endl; system("pause"); return 0; } int hard; cin>>hard; if(hard<=0||hard>100) { cout<<"ERROR"<<endl; system("pause"); return 0; } snake_length=5; clock_t a,b; char ch; double hard_len; for(int i=0; i<=4; i++) { snake[i].x=1; snake[i].y=5-i; } dir=3; system("cls"); hide(); print_wall(); print_food(); print_snake(); locate(m+2,0); cout<<"Now length: "; while (1) { hard_len=(double)snake_length/(double)(m*n); a=clock(); while (1) { b=clock(); if(b-a>=(int)(400-30*hard)*(1-sqrt(hard_len)))break; } if(kbhit()) { ch=getch(); if(ch==-32) { ch=getch(); switch(ch) { case 72: if(dir==2||dir==3) dir=0; break; case 80: if(dir==2||dir==3) dir=1; break; case 75: if(dir==0||dir==1) dir=2; break; case 77: if(dir==0||dir==1) dir=3; break; } } } if(!go_ahead())break; locate(m+2,12); cout<<snake_length; } system("pause"); return 0; }
若复制后无换行,可以按shift+Ctrl+a格式化-
-
通过的题目
-
最近活动
- 红盾周日下午班 作业
- 添胜J组集训day10 IOI
- 添胜J组集训day10(张正标) 作业
- 添胜J组集训day9 IOI
- 添胜J组集训day9(张正标) 作业
- 添胜J组集训day8 IOI
- 添胜J组集训day8(张正标) 作业
- 添胜J组集训day7 IOI
- 添胜J组集训day7(张正标) 作业
- 添胜J组集训day6(张正标) 作业
- 添胜J组集训day6 IOI
- 添胜J组集训day5 IOI
- 添胜J组集训day5(张正标) 作业
- 添胜J组集训day4 IOI
- 添胜J组集训day4(张正标) 作业
- 基础强化3 IOI
- 添胜J组集训day3 IOI
- 添胜J组集训day3(张正标) 作业
- 基础强化2 IOI
- 添胜J组集训day2 IOI
- 添胜J组集训day2(张正标) 作业
- 添胜J组集训day1 IOI
- 添胜J组集训day1(张正标) 作业
- 少年宫暑期零基础day6(2025/07/10)【张正标】 作业
- 少年宫暑期零基础day5(2025/07/09)【张正标】 作业
- 少年宫周三下午六点班期末测试 IOI
- 少年宫周三下午六点班(20250604) 作业
- 少年宫周三下午六点班(20250528)【陈潮雄】 作业
- 少年宫周三下午六点班(20250521)【陈潮雄】 作业
- 少年宫周三下午六点班(20250514)【陈潮雄】 作业
- 少年宫周三下午六点班阶段测试 IOI
- 少年宫周三下午六点班(20250423)【陈潮雄】 作业
- 少年宫周三下午六点班(20250416)【陈潮雄】 作业
- 少年宫周三下午六点班(20250409)【陈潮雄】 作业
- 少年宫周三下午六点班(20250326)【陈潮雄】 作业
- 少年宫周三下午六点班(20250319)【陈潮雄】 作业
- 少年宫周三下午六点班(20250312)【陈潮雄】 作业
- 少年宫周三下午开学测试(陈潮雄) OI
- 周三下午七点班(20241225)【陈潮雄】 IOI
- 少年宫周三下午七点班(20241218)【陈潮雄】 作业
- 少年宫周三下午七点班(20241211)【陈潮雄】 作业
- 少年宫周三下午七点班(20241204)【陈潮雄】 作业
- 少年宫周三下午七点班(20241127)【陈潮雄】 作业
- 少年宫周三下午七点班(20241120)【陈潮雄】 作业
- 少年宫周三下午七点班(20241113)【陈潮雄】 作业
- 少年宫周三下午七点(20241106)【陈潮雄】 作业
- 少年宫周三下午七点班(20241030)【陈潮雄】 作业
- 少年宫周三下午七点班(20241023)【陈潮雄】 作业
- 少年宫周三下午五点班(20241023)【陈潮雄】 作业
- 少年宫周三下午七点班(20241016)【陈潮雄】 作业
- 少年宫周三下午七点班(20241009)【陈潮雄】 作业
- 少年宫周三下午7点班(20240925)【陈潮雄】 作业
- C++高级B1班01-搜索复习 IOI
- C++初级A1班01-循环复习 IOI
- C++初级C2C3班01-顺序结构基础 IOI
- 种子班Day6-Day7练习题 IOI
- 种子班Day5练习题 IOI
- 种子班Day4练习题 IOI
- 种子班小测试 IOI
- 种子班Day2顺序结构基础练习题 IOI
- 种子班Day1表达式练习题 IOI
- 种子班课前预习测试 IOI
-
最近编写的题解
题目标签
- 语言基础
- 89
- 循环语句
- 40
- 选择语句
- 24
- 语言入门
- 23
- 动态规划
- 22
- 字符串
- 22
- 竞赛
- 21
- 字符数组
- 20
- 搜索
- 18
- NOIP
- 18
- 一维数组
- 17
- 其他
- 16
- 递归
- 13
- 普及组
- 12
- 二维数组
- 12
- 背包
- 10
- DFS
- 9
- 贪心
- 8
- 数学
- 7
- 进制转换
- 7