示例#1
0
bool isCleared(nodeQueue n, bool isRH)
{
	// nodeQueue c = (nodeQueue) malloc(sizeof(struct nodeQueue_s));
	// c = n;
	bool cleared;
	if (isRH)
		cleared = game_over_hr(n->m->g);
	else
		cleared = game_over_ar(n->m->g);
	return cleared;
}
示例#2
0
int main(int argc, char *argv[]){
  if(argc != 2)
    usage(argv[0]);
  int level = atoi(argv[1]);
  if(level <= 0)
    usage(argv[0]);
  game g = init_game(level);
  char buf[3][100];
  int piece_num;
  dir d;
  int distance;
  int back_code;
  while(!game_over_hr(g)){
    bool good = false;
    while(!good){
      //Loop for the break of cancel instruction
      while(!good){
	system("clear");
	print_game(g);
	printf("Move the pieces for free the piece 0 to the exit:\n");
	printf("Write exit for quit the game or cancel for restart the current move.\n");
	printf("Total move: %d\n",game_nb_moves(g));
	//First loop to take the number piece that you want to move
	back_code = take_piece_num(g, buf[0], &(piece_num));
	if(back_code == 0)
	  break;
	if(back_code == -1)
	  return EXIT_SUCCESS;
	//Second loop to take the direction where you want to move
	back_code = take_direction(g, piece_num, buf[1], &(d));
	if(back_code == 0)
	  break;
	if(back_code == -1)
	  return EXIT_SUCCESS;
	//Third loop to take the number of case that need for the move
	back_code = take_number_case(g, piece_num, d, buf[2], &(distance));
	if(back_code == 0)
	  break;
	if(back_code == -1)
	  return EXIT_SUCCESS;
	good = true;
      }
    }
  }
  system("clear");
  print_game(g);
  printf("CONGRATULATION\nYou won in %d moves\n", game_nb_moves(g));
  delete_game(g);
  return EXIT_SUCCESS;
}
示例#3
0
int main(int argc, char *argv[]){
  set_up_pieces();
  game g = new_game_hr(NB_PIECES, pieces);
  char buf[3][100];
  int piece_num;
  dir d;
  int distance;
  while(!game_over_hr(g)){
    bool good = false;
    while(!good){
      while(!good){
	set_up_board(g);
	print_game(g);
	printf("Move the pieces for free the piece 0 to the exit:\n");
	printf("Total move: %d\n",game_nb_moves(g));
	while(!good){
	  printf("What piece do you want to move?\n");
	  read(0, buf[0], sizeof(char)*100);
	  if(strcmp(buf[0], "cancel") == 10)
	    break;
	  if(strcmp(buf[0], "exit") == 10)
	    return EXIT_SUCCESS;
	  if(buf[0][0]<48 || buf[0][0]>=48+NB_PIECES || buf[0][1] != 10)
	    printf("Write a number between 0 and %d\tor write cancel or exit.\n",NB_PIECES-1);
	  else{
	    piece_num = atoi(buf[0]);
	    good = true;
	  }
	}
	if(!good)
	  break;
	good = false;
	while(!good){
	  printf("In what direction?\n");
	  read(0, buf[1],  sizeof(char)*100);
	  if(strcmp(buf[1], "cancel") == 10)
	    break;
	  if(strcmp(buf[1], "exit") == 10)
	    return EXIT_SUCCESS;
	  if(!is_dir_option(buf[1]))
	    printf("Write one of those direction: up, down, right, left\tor write cancel or exit.\n");
	  else{
	    for(int i=0; i<4; ++i){
	      if(strcmp(buf[1], direction[i].dir_name) == 10)
		d = direction[i].dir_option;
	    }
	    if(!good_direction(g, piece_num, d)){
	      if(is_horizontal(game_piece(g, piece_num)))
		printf("The piece %d cannot move vertycaly\n", piece_num);
	      else
		printf("The piece %d cannot move horizontaly\n", piece_num);
	    }else
	      good = true;
	  }
	}
	if(!good)
	  break;
	good = false;
	while(!good){
	  printf("How many case?\n");
	  read(0, buf[2],  sizeof(char)*100);
	  if(strcmp(buf[2], "cancel") == 10)
	    break;
	  if(strcmp(buf[2], "exit") == 10)
	    return EXIT_SUCCESS;
	  if(buf[2][0]<48 || buf[2][0]>=48+SIZE_ARRAY || buf[2][1] != 10)
	    printf("Write a number between 0 and %d\tor write cancel or exit.\n",SIZE_ARRAY-1);
	  else{
	    distance = atoi(buf[2]);
	    good = play_move(g, piece_num, d, distance);
	    if(!good)
	      printf("The piece %d cannot move to that case.\n", piece_num);
	  }
	}
      }
    }
  }
  set_up_board(g);
  print_game(g);
  printf("CONGRETULATION\nYou won in %d moves\n", game_nb_moves(g));
  return EXIT_SUCCESS;
}