Beispiel #1
0
void def_target_pink(char maze[L][C],int ghost[3],int pacman[3],int target[2])
{                          
  int result,copia[3],i=ghost[0],j=ghost[1],d=ghost[2];

  copia[0]=ghost[0];
  copia[1]=ghost[1];
  copia[2]=ghost[2];
  if (d == UP) // se a direção to pacman for para cima valida 4 "casas" para cima
  {
    copia[0]-=TARGET;
    result = validate_position (maze,copia);// falta terminar de adaptar de 2 variaveis para um vetor
    if (result == 1)
    {
      target[0]=i-TARGET;
      target[1]=j;
     // maze[i-TARGET][j] = 'T';
    
    }
  }
  else if (d == RIGHT)
  {
    copia[1]+=TARGET;
    result = validate_position (maze,copia);
    if (result == 1)
    {
      target[0]=i;
      target[1]=j+TARGET;
    //  maze[i][j+TARGET] = 'T';
      
    }
  }
  else if (d == DOWN)
  {
    copia[0]+=TARGET;
    result = validate_position (maze,copia);
    if (result == 1)
    {
      target[0]= i+TARGET;
      target[1]= j;
    //  maze[i+TARGET][j] = 'T';
     
    }
  }
  else if (d == LEFT)
  {
    copia[1]-=4;
    result = validate_position (maze,copia);
    if (result == 1)
    {
      target[0]=i;
      target[1]=j-TARGET;
     // maze[i][j-TARGET];
	}
  }
}
bool CL_IODeviceProvider_Memory::seek(int requested_position, CL_IODevice::SeekMode mode)
{
	validate_position();
	int new_position = position;
	switch (mode)
	{
	case CL_IODevice::seek_set:
		new_position = requested_position;
		break;
	case CL_IODevice::seek_cur:
		new_position += requested_position;
		break;
	case CL_IODevice::seek_end:
		new_position = data.get_size() + requested_position;
		break;
	default:
		return false;
	}

	if (new_position >= 0 && new_position <= data.get_size())
	{
		position = new_position;
		return true;
	}
	else
	{
		return false;
	}
}
int CL_IODeviceProvider_Memory::peek(void *recv_data, int len)
{
	validate_position();
	int data_available = data.get_size() - position;
	if (len > data_available)
		len = data_available;
	memcpy(recv_data, data.get_data() + position, len);
	return len;
}
int CL_IODeviceProvider_Memory::send(const void *send_data, int len, bool send_all)
{
	validate_position();
	int size_needed = position + len;
	if (size_needed > data.get_size())
		data.set_size(size_needed);
	memcpy(data.get_data() + position, send_data, len);
	position += len;
	return len;
}
int IODeviceProvider_Memory::receive(void *recv_data, int len, bool receive_all)
{
	validate_position();
	int data_available = data.get_size() - position;
	if (len > data_available)
		len = data_available;
	memcpy(recv_data, data.get_data() + position, len);
	position += len;
	return len;
}
Beispiel #6
0
void walking(char maze[23][30], int ghost[3], int target[2])
{
	int x,y; 
	y =  ghost[0];
	x =  ghost[1]; 


	while (target[0] != ghost[0] || target[1] != ghost[1] )
	{
		switch (ghost[2])
		{
			case 1:
				y = y+1;
				break;
			case 2:
				x = x+1;
				break;
			case 3:
				y = y-1;
				break;
			case 4:
				x = x-1;
				break;	
		}
		if (validate_position(maze, y, x))
		{
			ghost[0] = y;      
			ghost[1] = x;
			if (maze[y][x] != '7' &&  maze[y][x] != '8' )
			{
				maze[y][x]  = '3'; 
			}else
			{
				if (maze[y][x] != '8')
				{
					change_path(maze,ghost,target); 
	//neste momenro o ghost será atualizado com o melhor caminho da bifurcação
				}
			}
		}else
		{
			x = ghost[1];
			y = ghost[0];
			ghost[2] += 1;
			if (ghost[2] > 4)
			{
				ghost[2] = 1;
			}
		}
	}

}
Beispiel #7
0
int main (int argc, char *argv[])
{
  int ghost[3],pacman[3], target[2];
  char maze[L][C];
  char ch;
  int i=0,j=0;
  FILE *fp;
  fp = fopen("maze.txt","r" );
  if(fp == NULL)
	printf("Erro, nao foi possivel abrir o arquivo\n");
  else
	while( (ch=fgetc(fp))!= EOF )
	{
		if (ch != '\n')
		{
			maze[i][j] = ch;
			j++;
		}else
		{
			j = 0;
			i++;
		}
	}		
  fclose(fp);
	
  clear_screen();
  
  printf ( "\t>>> BLINKY GHOST <<<\n \n" );

  do
  {
  	print_maze(maze);
	printf ( "Qual a posição do GHOST? (x,y)\n" );
  	printf ( "x: " );
  	scanf ( "%d", &ghost[0] ); // referente a coluna - ghost
  	printf ( "y: " );
  	scanf ( "%d", &ghost[1] ); // referente a linha - ghost
	printf ( "Direção do ghost = 1-Down , 2-Right, 3-Up, 4-Left = " );
        scanf ("%d", &ghost[2]);
	clear_screen();
  }while (!validate_position(maze,ghost[0],ghost[1]) || ghost[2] > 4 ||ghost[2] < 1);                                           
	position (maze,ghost,'3');

  do 
  {
	clear_screen();
  	print_maze (maze);
  	printf ( "Qual a posição do Pacman? (x,y)\n" );
  	printf ( "x: " );
  	scanf ( "%d", &pacman[0]); // referente a coluna - ghost
  	printf ( "y: " );
  	scanf ( "%d", &pacman[1]); // referente a linha - ghost
  }while (!validate_position(maze,pacman[0],pacman[1]));                         
  do
  {  	
        printf ( "Direção do Pac-mam: 1-Down , 2-Right, 3-Up, 4-Left =  " );
        scanf ("%d",&pacman[2]);
  }while( pacman[2]>4 ||pacman[2]<1);

  target_blinky(pacman,target);
  position (maze,pacman,'5' );//mudar os parametros
  print_maze (maze);
  walking(maze,ghost,target);//mudar os parametros
  print_maze (maze);
  
  return 0;
}
int CL_IODeviceProvider_Memory::get_position() const
{
	validate_position();
	return position;
}
Beispiel #9
0
int main (int argc, char *argv[])
{
  int ghost[3],pacman[3], red[3], target[2], number_ghost;
  char maze[L][C];
  char ch;
  int i=0,j=0;
  FILE *fp;
  fp = fopen("maze.txt","r" );
  if(fp == NULL)
	printf("Erro, nao foi possivel abrir o arquivo\n");
  else
	while( (ch=fgetc(fp))!= EOF )
	{
		if (ch != '\n')
		{
			maze[i][j] = ch;
			j++;
		}else
		{
			j = 0;
			i++;
		}
	}		
  fclose(fp);
	
  clear_screen();
  print_maze(maze);
 
  printf ( "\t>>> GHOSTS <<<\n" );
  printf ( "1.BLINK  2.PINK  3.INKY  4.CLYDE\n" );
  do
  {  	  
  	  printf ( "Qual o numero do Ghost? = " );
          scanf ("%d", &number_ghost);
  }while(number_ghost > 4 || number_ghost < 1 );  
  //number_ghost = 2;
  do
  {
  	print_maze(maze);
	printf ( "Qual a posição do GHOST? (x,y)\n" );
  	printf ( "x: " );
  	scanf ( "%d", &ghost[1] ); // referente a coluna - ghost
  	printf ( "y: " );
  	scanf ( "%d", &ghost[0] ); // referente a linha - ghost
	printf ( "Direção do ghost = 1-Down , 2-Right, 3-Up, 4-Left = " );
        scanf ("%d", &ghost[2]);
	clear_screen();
  }while (!validate_position(maze,ghost[0],ghost[1]) || ghost[2] > 4 ||ghost[2] < 1);                                           //mudar os parametros
	position (maze,ghost,'3');
    
    
   do
  {
  	print_maze(maze);
	printf ( "Qual a posição do RED? (x,y)\n" );
  	printf ( "x: " );
  	scanf ( "%d", &red[1] ); // referente a coluna - ghost
  	printf ( "y: " );
  	scanf ( "%d", &red[0] ); // referente a linha - ghost
	printf ( "Direção do red = 1-Down , 2-Right, 3-Up, 4-Left = " );
        scanf ("%d", &red[2]);
	clear_screen();
  }while (!validate_position(maze,red[0],red[1]) || red[2] > 4 ||red[2] < 1);                                           //mudar os parametros
	position (maze,red,'4');
    
    
  do 
  {
	clear_screen();
  	print_maze (maze);
  	printf ( "Qual a posição do Pacman? (x,y)\n" );
  	printf ( "x: " );
  	scanf ( "%d", &pacman[1]); // referente a coluna - ghost
  	printf ( "y: " );
  	scanf ( "%d", &pacman[0]); // referente a linha - ghost
  }while (!validate_position(maze,pacman[0],pacman[1]));                          //mudar os parametros
  
  do
  {  	
        printf ( "Direção do Pac-mam: 1-Down , 2-Right, 3-Up, 4-Left =  " );
        scanf ("%d",&pacman[2]);
  }while( pacman[2]>4 ||pacman[2]<1);
  position (maze,pacman,'5' );//mudar os parametros
  
  dist(pacman);
  //marca_target aqui// calcular o target aqui e passa-lo para a walking
  //target[0]=(pacman[0]-red[0])+pacman[0];
  //target[1]=(pacman[1]-red[1])+pacman[1];
  //verifica_target(maze, target);
  calcula_target(maze, red, pacman, target);
  position(maze, target, '8');
  print_maze (maze);
  walking(maze,ghost,target);//mudar os parametros
  print_maze (maze);
  
  return 0;
}