Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/161.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;游戏颜色需要 我开始用C++制作一个PACMAN风格的游戏,我想做的是给每个东西一个不同的颜色,比如玩家(O)黄色,敌人的鬼(@)红色,水果(或)或者你称之为蓝色,障碍(α)棕色和加号(+)绿色。 希望你能帮助我 #include <iostream> #include <stdio.h> #include <windows.h> #include <string> #include <vector> #include <stdlib.h> #include <conio.h> using namespace std; char tmp_map[21][60]; char map[21][60] = { "+#########################################+", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "+#########################################+" }; void ShowMap() { for(int i = 0; i < 21; i++) { printf("%s\n",map[i] ); } } void gotoxy( short x, short y ) { HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE) ; COORD position = { x, y } ; SetConsoleCursorPosition( hStdout, position ) ; } class entity { public: entity( int x, int y ){ this ->x = x; this ->y = y; } void move_x( int p ){ if( map[y][x+p] == ' ' ) x += p; } void move_y( int p ){ if( map[y+p][x] == ' ' ) y += p; } void move( int p, int q ){ x += p; y += q; } int get_x(){ return x; } int get_y(){ return y; } void draw( char p ){ map[x][y] = p; gotoxy( x, y ); printf( "%c", p ); } private: int x; int y; }; struct walk { long walk_count; long x; long y; long back; }; struct target { long x; long y; }; vector<target> walk_queue; vector<walk> BFSArray; void AddArray( int x, int y, int wc , int back ){ if( tmp_map[y][x] == ' ' || tmp_map[y][x] == '.' ){ tmp_map[y][x] = '#'; walk tmp; tmp.x = x; tmp.y = y; tmp.walk_count = wc; tmp.back = back; BFSArray.push_back( tmp ); } } void FindPath( int sx, int sy, int x, int y ){ memcpy( tmp_map, map, sizeof(map) ); BFSArray.clear(); walk tmp; tmp.x = sx; tmp.y = sy; tmp.walk_count = 0; tmp.back = -1; BFSArray.push_back( tmp ); int i = 0; while( i < BFSArray.size() ){ if( BFSArray[i].x == x && BFSArray[i].y == y ){ walk_queue.clear(); target tmp2; while( BFSArray[i].walk_count != 0 ){ tmp2.x = BFSArray[i].x; tmp2.y = BFSArray[i].y; walk_queue.push_back( tmp2 ); i = BFSArray[i].back; } break; } AddArray( BFSArray[i].x+1, BFSArray[i].y, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); /* AddArray( BFSArray[i].x+1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x+1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x+1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x+1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); */ i++; } BFSArray.clear(); } int main() { bool running = true; int x = 14; // hero column int y = 16; // hero row int old_x; int old_y; int a = 1000000000; int ex = 4;//enemy column int ey = 3;//enemy row int pts = 0; system("COLOR 07"); printf("Hello World\n\n"); printf("H -> Hard\nN -> Normal\nE -> Easy\n\nInput : "); char diffi; int speedmod = 3; cin>>diffi; if( diffi=='N'){speedmod=2;}if(diffi=='H'){speedmod=1;}if( diffi=='n') {speedmod=2;}else if(diffi=='h'){speedmod=1;} system("cls"); ShowMap(); gotoxy(x,y);cout<<"s"; int frame=0; FindPath( ex,ey,x,y ); while( running ){ gotoxy( x, y );printf(" "); old_x = x; old_y = y; if ( GetAsyncKeyState( VK_UP ) ){ if( map[y-1][x] == '.' ){ y--; pts += 10; }else if( map[y-1][x] == ' ' ) y--; if( map[y-1][x] == '|' ) y--; if( map[y-1][x] == '_' ) y--; } if ( GetAsyncKeyState( VK_DOWN ) ){ if( map[y+1][x] == '.' ){ y++; pts += 10; }else if( map[y+1][x] == ' ' ) y++; if( map[y+1][x] == '|' ) y++; if( map[y+1][x] == '_' ) y++; } if ( GetAsyncKeyState( VK_LEFT ) ){ if( map[y][x-1] == '.' ){ x--; pts += 10; }else if( map[y][x-1] == ' ' ) x--; if( map[y][x-1] == '|' ) x--; if( map[y][x-1] == '_' ) x--; } if ( GetAsyncKeyState( VK_RIGHT ) ){ if( map[y][x+1] == '.' ){ x++; pts += 10; }else if( map[y][x+1] == ' ' ) x++; if( map[y][x+1] == '|' ) x++; if( map[y][x+1] == '_' ) x++; } if( old_x != x || old_y != y ){ FindPath( ex,ey,x,y ); } gotoxy( x,y );printf("o"); map[ey][ex] = '.'; gotoxy( ex, ey );printf("."); if( frame%speedmod == 0 && walk_queue.size() != 0 ){ ex = walk_queue.back().x; ey = walk_queue.back().y; walk_queue.pop_back(); } gotoxy( ex, ey ); printf("@"); if( ex == x && ey == y ){ break; } gotoxy( 32, 18 ); gotoxy( 45, 1 ); cout <<pts; Sleep( 100 ); frame++; } if(pts < 1000000) { system("cls"); printf("You Lose and your points: %i",pts ); cin.get(); cin.get(); cin.get(); cin.get(); cin.get(); return 0; } else if(pts > 1000000) { system("cls"); printf("You Won and your Points: %i",pts); cin.get(); cin.get(); cin.get(); cin.get(); cin.get(); return 0; } } #包括 #包括 #包括 #包括 #包括 #包括 #包括 使用名称空间std; chartmp_图[21][60]; 字符映射[21][60]={ "+#########################################+", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "+#########################################+" }; void ShowMap() { 对于(int i=0;ix=x; 这->y=y; } 无效移动x(整数p){ 如果(map[y][x+p]='')x+=p; } 无效移动(整数p){ 如果(map[y+p][x]='')y+=p; } 无效移动(整数p,整数q){ x+=p; y+=q; } int get_x(){return x;} int get_y(){return y;} 空图(字符p){ map[x][y]=p; gotoxy(x,y);printf(“%c”,p); } 私人: int x; int-y; }; 结构步行{ 长途跋涉; 长x; 长y; 长背; }; 结构目标{ 长x; 长y; }; 向量行走队列; 载体BFSArray; void AddArray(int x,int y,int wc,int back){ 如果(tmp|U图[y][x]=''tmp|U图[y][x]=''){ tmp#u图[y][x]='#'; 步行tmp; tmp.x=x; tmp.y=y; tmp.walk_count=wc; tmp.back=back; BFSArray.推回(tmp); } } void FindPath(intsx、intsy、intx、inty){ memcpy(tmp_图,图,尺寸(图)); BFSArray.clear(); 步行tmp; tmp.x=sx; tmp.y=sy; tmp.walk_计数=0; tmp.back=-1; BFSArray.推回(tmp); int i=0; 而(iHard\nN->Normal\nE->Easy\n\n输入:”); 炭扩散; int-speedmod=3; cin>>扩散; if(diffi=='N'){speedmod=2;}if(diffi=='H'){speedmod=1;}if(diffi=='N'){speedmod=2;}否则if(diffi=='H'){speedmod=1;} 系统(“cls”); ShowMap(); gotoxy(x,y);cout_C++_Colors_Pacman - Fatal编程技术网 y=y; } 无效移动x(整数p){ 如果(map[y][x+p]='')x+=p; } 无效移动(整数p){ 如果(map[y+p][x]='')y+=p; } 无效移动(整数p,整数q){ x+=p; y+=q; } int get_x(){return x;} int get_y(){return y;} 空图(字符p){ map[x][y]=p; gotoxy(x,y);printf(“%c”,p); } 私人: int x; int-y; }; 结构步行{ 长途跋涉; 长x; 长y; 长背; }; 结构目标{ 长x; 长y; }; 向量行走队列; 载体BFSArray; void AddArray(int x,int y,int wc,int back){ 如果(tmp|U图[y][x]=''tmp|U图[y][x]=''){ tmp#u图[y][x]='#'; 步行tmp; tmp.x=x; tmp.y=y; tmp.walk_count=wc; tmp.back=back; BFSArray.推回(tmp); } } void FindPath(intsx、intsy、intx、inty){ memcpy(tmp_图,图,尺寸(图)); BFSArray.clear(); 步行tmp; tmp.x=sx; tmp.y=sy; tmp.walk_计数=0; tmp.back=-1; BFSArray.推回(tmp); int i=0; 而(iHard\nN->Normal\nE->Easy\n\n输入:”); 炭扩散; int-speedmod=3; cin>>扩散; if(diffi=='N'){speedmod=2;}if(diffi=='H'){speedmod=1;}if(diffi=='N'){speedmod=2;}否则if(diffi=='H'){speedmod=1;} 系统(“cls”); ShowMap(); gotoxy(x,y);cout,c++,colors,pacman,C++,Colors,Pacman" /> y=y; } 无效移动x(整数p){ 如果(map[y][x+p]='')x+=p; } 无效移动(整数p){ 如果(map[y+p][x]='')y+=p; } 无效移动(整数p,整数q){ x+=p; y+=q; } int get_x(){return x;} int get_y(){return y;} 空图(字符p){ map[x][y]=p; gotoxy(x,y);printf(“%c”,p); } 私人: int x; int-y; }; 结构步行{ 长途跋涉; 长x; 长y; 长背; }; 结构目标{ 长x; 长y; }; 向量行走队列; 载体BFSArray; void AddArray(int x,int y,int wc,int back){ 如果(tmp|U图[y][x]=''tmp|U图[y][x]=''){ tmp#u图[y][x]='#'; 步行tmp; tmp.x=x; tmp.y=y; tmp.walk_count=wc; tmp.back=back; BFSArray.推回(tmp); } } void FindPath(intsx、intsy、intx、inty){ memcpy(tmp_图,图,尺寸(图)); BFSArray.clear(); 步行tmp; tmp.x=sx; tmp.y=sy; tmp.walk_计数=0; tmp.back=-1; BFSArray.推回(tmp); int i=0; 而(iHard\nN->Normal\nE->Easy\n\n输入:”); 炭扩散; int-speedmod=3; cin>>扩散; if(diffi=='N'){speedmod=2;}if(diffi=='H'){speedmod=1;}if(diffi=='N'){speedmod=2;}否则if(diffi=='H'){speedmod=1;} 系统(“cls”); ShowMap(); gotoxy(x,y);cout,c++,colors,pacman,C++,Colors,Pacman" />

C++;游戏颜色需要 我开始用C++制作一个PACMAN风格的游戏,我想做的是给每个东西一个不同的颜色,比如玩家(O)黄色,敌人的鬼(@)红色,水果(或)或者你称之为蓝色,障碍(α)棕色和加号(+)绿色。 希望你能帮助我 #include <iostream> #include <stdio.h> #include <windows.h> #include <string> #include <vector> #include <stdlib.h> #include <conio.h> using namespace std; char tmp_map[21][60]; char map[21][60] = { "+#########################################+", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "+#########################################+" }; void ShowMap() { for(int i = 0; i < 21; i++) { printf("%s\n",map[i] ); } } void gotoxy( short x, short y ) { HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE) ; COORD position = { x, y } ; SetConsoleCursorPosition( hStdout, position ) ; } class entity { public: entity( int x, int y ){ this ->x = x; this ->y = y; } void move_x( int p ){ if( map[y][x+p] == ' ' ) x += p; } void move_y( int p ){ if( map[y+p][x] == ' ' ) y += p; } void move( int p, int q ){ x += p; y += q; } int get_x(){ return x; } int get_y(){ return y; } void draw( char p ){ map[x][y] = p; gotoxy( x, y ); printf( "%c", p ); } private: int x; int y; }; struct walk { long walk_count; long x; long y; long back; }; struct target { long x; long y; }; vector<target> walk_queue; vector<walk> BFSArray; void AddArray( int x, int y, int wc , int back ){ if( tmp_map[y][x] == ' ' || tmp_map[y][x] == '.' ){ tmp_map[y][x] = '#'; walk tmp; tmp.x = x; tmp.y = y; tmp.walk_count = wc; tmp.back = back; BFSArray.push_back( tmp ); } } void FindPath( int sx, int sy, int x, int y ){ memcpy( tmp_map, map, sizeof(map) ); BFSArray.clear(); walk tmp; tmp.x = sx; tmp.y = sy; tmp.walk_count = 0; tmp.back = -1; BFSArray.push_back( tmp ); int i = 0; while( i < BFSArray.size() ){ if( BFSArray[i].x == x && BFSArray[i].y == y ){ walk_queue.clear(); target tmp2; while( BFSArray[i].walk_count != 0 ){ tmp2.x = BFSArray[i].x; tmp2.y = BFSArray[i].y; walk_queue.push_back( tmp2 ); i = BFSArray[i].back; } break; } AddArray( BFSArray[i].x+1, BFSArray[i].y, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); /* AddArray( BFSArray[i].x+1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x+1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x+1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x+1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); */ i++; } BFSArray.clear(); } int main() { bool running = true; int x = 14; // hero column int y = 16; // hero row int old_x; int old_y; int a = 1000000000; int ex = 4;//enemy column int ey = 3;//enemy row int pts = 0; system("COLOR 07"); printf("Hello World\n\n"); printf("H -> Hard\nN -> Normal\nE -> Easy\n\nInput : "); char diffi; int speedmod = 3; cin>>diffi; if( diffi=='N'){speedmod=2;}if(diffi=='H'){speedmod=1;}if( diffi=='n') {speedmod=2;}else if(diffi=='h'){speedmod=1;} system("cls"); ShowMap(); gotoxy(x,y);cout<<"s"; int frame=0; FindPath( ex,ey,x,y ); while( running ){ gotoxy( x, y );printf(" "); old_x = x; old_y = y; if ( GetAsyncKeyState( VK_UP ) ){ if( map[y-1][x] == '.' ){ y--; pts += 10; }else if( map[y-1][x] == ' ' ) y--; if( map[y-1][x] == '|' ) y--; if( map[y-1][x] == '_' ) y--; } if ( GetAsyncKeyState( VK_DOWN ) ){ if( map[y+1][x] == '.' ){ y++; pts += 10; }else if( map[y+1][x] == ' ' ) y++; if( map[y+1][x] == '|' ) y++; if( map[y+1][x] == '_' ) y++; } if ( GetAsyncKeyState( VK_LEFT ) ){ if( map[y][x-1] == '.' ){ x--; pts += 10; }else if( map[y][x-1] == ' ' ) x--; if( map[y][x-1] == '|' ) x--; if( map[y][x-1] == '_' ) x--; } if ( GetAsyncKeyState( VK_RIGHT ) ){ if( map[y][x+1] == '.' ){ x++; pts += 10; }else if( map[y][x+1] == ' ' ) x++; if( map[y][x+1] == '|' ) x++; if( map[y][x+1] == '_' ) x++; } if( old_x != x || old_y != y ){ FindPath( ex,ey,x,y ); } gotoxy( x,y );printf("o"); map[ey][ex] = '.'; gotoxy( ex, ey );printf("."); if( frame%speedmod == 0 && walk_queue.size() != 0 ){ ex = walk_queue.back().x; ey = walk_queue.back().y; walk_queue.pop_back(); } gotoxy( ex, ey ); printf("@"); if( ex == x && ey == y ){ break; } gotoxy( 32, 18 ); gotoxy( 45, 1 ); cout <<pts; Sleep( 100 ); frame++; } if(pts < 1000000) { system("cls"); printf("You Lose and your points: %i",pts ); cin.get(); cin.get(); cin.get(); cin.get(); cin.get(); return 0; } else if(pts > 1000000) { system("cls"); printf("You Won and your Points: %i",pts); cin.get(); cin.get(); cin.get(); cin.get(); cin.get(); return 0; } } #包括 #包括 #包括 #包括 #包括 #包括 #包括 使用名称空间std; chartmp_图[21][60]; 字符映射[21][60]={ "+#########################################+", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "+#########################################+" }; void ShowMap() { 对于(int i=0;ix=x; 这->y=y; } 无效移动x(整数p){ 如果(map[y][x+p]='')x+=p; } 无效移动(整数p){ 如果(map[y+p][x]='')y+=p; } 无效移动(整数p,整数q){ x+=p; y+=q; } int get_x(){return x;} int get_y(){return y;} 空图(字符p){ map[x][y]=p; gotoxy(x,y);printf(“%c”,p); } 私人: int x; int-y; }; 结构步行{ 长途跋涉; 长x; 长y; 长背; }; 结构目标{ 长x; 长y; }; 向量行走队列; 载体BFSArray; void AddArray(int x,int y,int wc,int back){ 如果(tmp|U图[y][x]=''tmp|U图[y][x]=''){ tmp#u图[y][x]='#'; 步行tmp; tmp.x=x; tmp.y=y; tmp.walk_count=wc; tmp.back=back; BFSArray.推回(tmp); } } void FindPath(intsx、intsy、intx、inty){ memcpy(tmp_图,图,尺寸(图)); BFSArray.clear(); 步行tmp; tmp.x=sx; tmp.y=sy; tmp.walk_计数=0; tmp.back=-1; BFSArray.推回(tmp); int i=0; 而(iHard\nN->Normal\nE->Easy\n\n输入:”); 炭扩散; int-speedmod=3; cin>>扩散; if(diffi=='N'){speedmod=2;}if(diffi=='H'){speedmod=1;}if(diffi=='N'){speedmod=2;}否则if(diffi=='H'){speedmod=1;} 系统(“cls”); ShowMap(); gotoxy(x,y);cout

C++;游戏颜色需要 我开始用C++制作一个PACMAN风格的游戏,我想做的是给每个东西一个不同的颜色,比如玩家(O)黄色,敌人的鬼(@)红色,水果(或)或者你称之为蓝色,障碍(α)棕色和加号(+)绿色。 希望你能帮助我 #include <iostream> #include <stdio.h> #include <windows.h> #include <string> #include <vector> #include <stdlib.h> #include <conio.h> using namespace std; char tmp_map[21][60]; char map[21][60] = { "+#########################################+", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "+#########################################+" }; void ShowMap() { for(int i = 0; i < 21; i++) { printf("%s\n",map[i] ); } } void gotoxy( short x, short y ) { HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE) ; COORD position = { x, y } ; SetConsoleCursorPosition( hStdout, position ) ; } class entity { public: entity( int x, int y ){ this ->x = x; this ->y = y; } void move_x( int p ){ if( map[y][x+p] == ' ' ) x += p; } void move_y( int p ){ if( map[y+p][x] == ' ' ) y += p; } void move( int p, int q ){ x += p; y += q; } int get_x(){ return x; } int get_y(){ return y; } void draw( char p ){ map[x][y] = p; gotoxy( x, y ); printf( "%c", p ); } private: int x; int y; }; struct walk { long walk_count; long x; long y; long back; }; struct target { long x; long y; }; vector<target> walk_queue; vector<walk> BFSArray; void AddArray( int x, int y, int wc , int back ){ if( tmp_map[y][x] == ' ' || tmp_map[y][x] == '.' ){ tmp_map[y][x] = '#'; walk tmp; tmp.x = x; tmp.y = y; tmp.walk_count = wc; tmp.back = back; BFSArray.push_back( tmp ); } } void FindPath( int sx, int sy, int x, int y ){ memcpy( tmp_map, map, sizeof(map) ); BFSArray.clear(); walk tmp; tmp.x = sx; tmp.y = sy; tmp.walk_count = 0; tmp.back = -1; BFSArray.push_back( tmp ); int i = 0; while( i < BFSArray.size() ){ if( BFSArray[i].x == x && BFSArray[i].y == y ){ walk_queue.clear(); target tmp2; while( BFSArray[i].walk_count != 0 ){ tmp2.x = BFSArray[i].x; tmp2.y = BFSArray[i].y; walk_queue.push_back( tmp2 ); i = BFSArray[i].back; } break; } AddArray( BFSArray[i].x+1, BFSArray[i].y, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); /* AddArray( BFSArray[i].x+1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x+1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x+1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x+1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y+1, BFSArray[i].walk_count+1, i ); AddArray( BFSArray[i].x-1, BFSArray[i].y-1, BFSArray[i].walk_count+1, i ); */ i++; } BFSArray.clear(); } int main() { bool running = true; int x = 14; // hero column int y = 16; // hero row int old_x; int old_y; int a = 1000000000; int ex = 4;//enemy column int ey = 3;//enemy row int pts = 0; system("COLOR 07"); printf("Hello World\n\n"); printf("H -> Hard\nN -> Normal\nE -> Easy\n\nInput : "); char diffi; int speedmod = 3; cin>>diffi; if( diffi=='N'){speedmod=2;}if(diffi=='H'){speedmod=1;}if( diffi=='n') {speedmod=2;}else if(diffi=='h'){speedmod=1;} system("cls"); ShowMap(); gotoxy(x,y);cout<<"s"; int frame=0; FindPath( ex,ey,x,y ); while( running ){ gotoxy( x, y );printf(" "); old_x = x; old_y = y; if ( GetAsyncKeyState( VK_UP ) ){ if( map[y-1][x] == '.' ){ y--; pts += 10; }else if( map[y-1][x] == ' ' ) y--; if( map[y-1][x] == '|' ) y--; if( map[y-1][x] == '_' ) y--; } if ( GetAsyncKeyState( VK_DOWN ) ){ if( map[y+1][x] == '.' ){ y++; pts += 10; }else if( map[y+1][x] == ' ' ) y++; if( map[y+1][x] == '|' ) y++; if( map[y+1][x] == '_' ) y++; } if ( GetAsyncKeyState( VK_LEFT ) ){ if( map[y][x-1] == '.' ){ x--; pts += 10; }else if( map[y][x-1] == ' ' ) x--; if( map[y][x-1] == '|' ) x--; if( map[y][x-1] == '_' ) x--; } if ( GetAsyncKeyState( VK_RIGHT ) ){ if( map[y][x+1] == '.' ){ x++; pts += 10; }else if( map[y][x+1] == ' ' ) x++; if( map[y][x+1] == '|' ) x++; if( map[y][x+1] == '_' ) x++; } if( old_x != x || old_y != y ){ FindPath( ex,ey,x,y ); } gotoxy( x,y );printf("o"); map[ey][ex] = '.'; gotoxy( ex, ey );printf("."); if( frame%speedmod == 0 && walk_queue.size() != 0 ){ ex = walk_queue.back().x; ey = walk_queue.back().y; walk_queue.pop_back(); } gotoxy( ex, ey ); printf("@"); if( ex == x && ey == y ){ break; } gotoxy( 32, 18 ); gotoxy( 45, 1 ); cout <<pts; Sleep( 100 ); frame++; } if(pts < 1000000) { system("cls"); printf("You Lose and your points: %i",pts ); cin.get(); cin.get(); cin.get(); cin.get(); cin.get(); return 0; } else if(pts > 1000000) { system("cls"); printf("You Won and your Points: %i",pts); cin.get(); cin.get(); cin.get(); cin.get(); cin.get(); return 0; } } #包括 #包括 #包括 #包括 #包括 #包括 #包括 使用名称空间std; chartmp_图[21][60]; 字符映射[21][60]={ "+#########################################+", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "# #", "+#########################################+" }; void ShowMap() { 对于(int i=0;ix=x; 这->y=y; } 无效移动x(整数p){ 如果(map[y][x+p]='')x+=p; } 无效移动(整数p){ 如果(map[y+p][x]='')y+=p; } 无效移动(整数p,整数q){ x+=p; y+=q; } int get_x(){return x;} int get_y(){return y;} 空图(字符p){ map[x][y]=p; gotoxy(x,y);printf(“%c”,p); } 私人: int x; int-y; }; 结构步行{ 长途跋涉; 长x; 长y; 长背; }; 结构目标{ 长x; 长y; }; 向量行走队列; 载体BFSArray; void AddArray(int x,int y,int wc,int back){ 如果(tmp|U图[y][x]=''tmp|U图[y][x]=''){ tmp#u图[y][x]='#'; 步行tmp; tmp.x=x; tmp.y=y; tmp.walk_count=wc; tmp.back=back; BFSArray.推回(tmp); } } void FindPath(intsx、intsy、intx、inty){ memcpy(tmp_图,图,尺寸(图)); BFSArray.clear(); 步行tmp; tmp.x=sx; tmp.y=sy; tmp.walk_计数=0; tmp.back=-1; BFSArray.推回(tmp); int i=0; 而(iHard\nN->Normal\nE->Easy\n\n输入:”); 炭扩散; int-speedmod=3; cin>>扩散; if(diffi=='N'){speedmod=2;}if(diffi=='H'){speedmod=1;}if(diffi=='N'){speedmod=2;}否则if(diffi=='H'){speedmod=1;} 系统(“cls”); ShowMap(); gotoxy(x,y);cout,c++,colors,pacman,C++,Colors,Pacman,我在互联网上找到了这段代码的一部分,其中的一部分是我自己写的。我创建了一个名为color的类,并重载了运算符。输出文本的颜色可以通过调用设置。请不要发布整个程序——因此在问题中要求最少的代码示例,以节省每个人的时间:这使回答者更容易知道如何帮助,并使问题更容易搜索到那些有类似问题的人。 #ifndef COLOUR_H #define COLOUR_H #include <iostream> #include <windows.h> inline void SetCo

我在互联网上找到了这段代码的一部分,其中的一部分是我自己写的。我创建了一个名为color的类,并重载了
运算符。输出文本的颜色可以通过调用设置。请不要发布整个程序——因此在问题中要求最少的代码示例,以节省每个人的时间:这使回答者更容易知道如何帮助,并使问题更容易搜索到那些有类似问题的人。
#ifndef COLOUR_H
#define COLOUR_H

#include <iostream>
#include <windows.h>

inline void SetColour (WORD val) {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), val);
}

class Colour {
    private:
        WORD val;
    public:
        Colour(WORD x) : val(x) { }
        void set() const { SetColour(val); }
        friend std::ostream& operator<<(std::ostream &, const Colour &);
};

std::ostream& operator<<(std::ostream &out, const Colour &c) {
    c.set();
    return out;
}

static const Colour blue (1);
static const Colour green (2);
static const Colour cyan (3);
static const Colour red (4);
static const Colour purple (5);
static const Colour dyellow (6);
static const Colour dwhite (7);
static const Colour grey (8);
static const Colour bblue (9);
static const Colour bgreen (10);
static const Colour bcyan (11);
static const Colour bred (12);
static const Colour pink (13);
static const Colour yellow (14);
static const Colour white (15);

/*
 * 1: Blue
 * 2: Green
 * 3: Cyan
 * 4: Red
 * 5: Purple
 * 6: Yellow (Dark)
 * 7: Default white
 * 8: Gray/Grey
 * 9: Bright blue
 * 10: Brigth green
 * 11: Bright cyan
 * 12: Bright red
 * 13: Pink/Magenta
 * 14: Yellow
 * 15: Bright white 
 */

#endif
std::cout << red << "This text is red\n";
std::cout << blue << "This text is blue";