ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

RUNNING LAVA(DFS)

2022-06-12 16:36:37  阅读:156  来源: 互联网

标签:map int void LAVA RUNNING maxn DFS include clr



#include <iostream> #include <ctime> #include <cstdlib> #include <algorithm> #include <string> #include <cstring> #include <conio.h> #include <windows.h> #define BLOCK "■" #define maxn 52 using namespace std; char map[maxn][maxn]; int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}}; enum color{ BLACK , DARKBLUE , GREEN , BLUE , RED , PURPLE , YELLOW , WHITE , GREY , LIGHTBLUE , LIGHTGREEN , GREENBLUE , LIGHTRED , LIGHTPURPLE , LIGHTYELLOW , LIGHTWHITE }; int clr_rand[9] = {RED , PURPLE , DARKBLUE , LIGHTRED , YELLOW , GREENBLUE , GREEN , BLUE , LIGHTPURPLE}; int _clr; void Handle(int , int); void print(int , int); void set_color(int ); int random(int ); void develop(char map[maxn][maxn]); bool check(int , int); int dfs(int , int); int main(){ srand((int)time(NULL)); cout << "PLEASE DISPLAY IN A FULL SCREEN\n (press the key to continue)" ; char c = getch(); for(int i = 0 ; i < maxn ; ++i){ for(int j = 0 ; j < maxn ; ++j){ if(i == 0 || j == 0 || i == maxn - 1 || j == maxn - 1){ map[i][j] = 's'; } else map[i][j] = ' '; } } int block_num = random(maxn * maxn / 2); while(block_num--){ int x = random(maxn - 2) + 1; int y = random(maxn - 2) + 1; map[x][y] = 'b'; } for(int i = 0 ; i < maxn ; ++i){ for(int j = 0 ; j < maxn ; ++j){ print(i , j); } cout << endl; } bool flag = true; develop(map); system("pause"); return 0; } void Handle(int screen_x , int screen_y){ HANDLE hOut; COORD pos = {short(screen_x * 2),short(screen_y)}; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOut, pos); } void print(int i , int j){ Handle(i , j); if(map[i][j] == ' ') cout << " "; else if(map[i][j] == 's') cout << BLOCK; else if(map[i][j] == 'l'){ set_color(clr_rand[_clr]); cout << BLOCK; set_color(WHITE); } else { // set_color(BLUE); cout << BLOCK; set_color(WHITE); } set_color(WHITE); } int random(int mod){ return rand() % mod ; } void set_color(int clr){ if(clr >= BLACK && clr <= LIGHTWHITE) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), clr); else SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), WHITE); } bool check(int x , int y){ if(x >= 1 && x < maxn - 1 && y >= 1 && y < maxn - 1 && map[x][y] == ' ') return true; else return false; } int dfs(int x , int y){ if(check(x , y)){ map[x][y] = 'l'; print(x , y); Sleep(50); for(int i = 0 ; i < 4 ; ++i){ dfs(x + dir[i][0] , y + dir[i][1]); } } return 0; } void develop(char map[maxn][maxn]){ for(int i = 1 ; i < maxn - 1 ; ++i) for(int j = 1 ; j < maxn - 1 ; ++j) if(map[i][j] == ' ') _clr = (_clr + 1) % 9 , dfs(i , j); Handle(0 , maxn + 1); }

Display:

 

标签:map,int,void,LAVA,RUNNING,maxn,DFS,include,clr
来源: https://www.cnblogs.com/RadiumGalaxy/p/running_lava.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有