Пример #1
0
void crear(int x , int y, std::vector< std::vector<int> >& visited, std::vector< std::vector<int> >& mh, std::vector< std::vector<int> >& mv )
{
	std::pair <int,int> pos;
	pos.first = x; pos.second = y;
	if (visited[y][x]){
		return;
	}else{
		visited[y][x] = 1;
		std::vector< std::pair<int,int> > vecinos;
		vecinos = dameVecinos(pos);
		for(int i =0; i<4;i++){
			if(esPosicionValida(vecinos[i]) && !visited[vecinos[i].second][vecinos[i].first]){
				//si no fue visitada, rompo la pared y me llamo recursivamente
				//la fila de arista a la derech es la posicion y
				if (right_move(x, vecinos[i].first)){ mh[y][x] = 1 ;}
				if (left_move(x, vecinos[i].first)){ mh[y][x-1] = 1;}
				if (up_move(y, vecinos[i].second)){ mv[y-1][x] = 1;}
				if (down_move(y, vecinos[i].second)){ mv[y][x] = 1;}
				crear(vecinos[i].first,vecinos[i].second,visited, mh, mv);
			}
		}
	}

}
Пример #2
0
int main(){
	//
/*	int m;
	m=getch();
    while(m){
	m=getch();
	printf("%d\n",m);

	}*/
	int temp=0, i,j;//以下所有代码,I表示行,j表示列
	/*获取控制台光标,并隐藏*/
	CONSOLE_CURSOR_INFO cci;
	HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD coord;

	system("color 5F");//改变控制台窗口背景色和文字颜色
	system("mode con cols=30 lines=11");//定义控制台窗口大小

	randDete();
	randDete();
    cci.bVisible = FALSE;//隐藏输入光标
	cci.dwSize = sizeof(cci);	
    SetConsoleCursorInfo(handle, &cci);
	printf_array();
	/*游戏主要消息循环*/
	while(1){
		temp=getch();//等待用户按下键操作
		system("cls");
		printf_array();
		is_moved=0;
		/*判断输入是或否合法*/
		if(temp!=UP&&temp!=DOWN&&temp!=LEFT&&temp!=RIGHT&&temp!=ESC)
			//printf_array();
			continue;
		else{
		/*方向键主要操作*/
		if(temp==RIGHT){
		
					right_move();
				if(is_moved==1){
						randDete();
					}
					
					printf_array();
					printf("\n");

		}
		if(temp==DOWN){
		
					down_move();
					if(is_moved==1){
						randDete();
					}
					printf_array();
					printf("\n");
		}
		if(temp==LEFT){
			left_move();
			if(is_moved==1){
				randDete();
					}
			printf_array();
			printf("\n");
		}
		if(temp==UP){
			up_move();
			if(is_moved==1){
				randDete();
			}
			printf_array();
			printf("\n");
		}
	/*使用ESC键重置游戏*/
		if(temp==ESC){
			for (i=0;i<4;i++)
			{
				for (j=0;j<4;j++)
				{
					array[i][j]=0;
				}
			}
			randDete();
			randDete();
			printf_array();
			printf("\n");
		}
	}
	}
	return 0;
}