Exemplo n.º 1
0
void *proc2 (int semid) {
	//printf("thread 2 : create\n");
	int i;
	for(i='a';i<'z'+1;i++){
		prendre(semid, 1);
		printf("%c",i);
		fflush (stdout);// flushing or repositioning required
		rendre(semid, 0);
	}
	exit(0);
}
Exemplo n.º 2
0
void            salle02()
{
  char		*entree;
  int           action;
  int           randmuni;
  int           randmedic;


  entree = malloc(sizeof(char*));
  action = 0;
  g_map[1][0].visited = 1;
  g_map[1][0].content = 1;
  look();
  srand(time(NULL));
  randmuni = rand();
  randmedic = rand();
  MUNI_MAP = 0;
  MEDIC_MAP = 0;

  if (randmedic%10 == 0)
    {
      MEDIC_MAP = 1;
    }
  if ((randmuni%4 == 0))
    {
      MUNI_MAP = 4;
    }
  while (action == 0)
    {
      /*On propose ici le prompt au joueur*/
      action = readline();
      /*Traitement de laction :*/
      if (action == 2)
        {
	  my_putstr("\nJe serai bien reste a l'abri ici pour attendre les secours... Mais je risque de manquer de nouriture et d'eau.\n");
	  my_putstr("C'est reparti pour l'aventure dans ce vaisseau super-flippant !\n");
	  g_map[1][0].content = 0;
	  SALLE = 3;
          salle03();
        }
      /*Prendre*/
      if (action == 5)
        {
	  prendre();
          action = 0;
        }
      /*fin prendre*/
      if ((action == 1) || ((action >= 3) && (action <= 4)))
        {
          erreur_depla();
          action = 0;
        }
    }
}
Exemplo n.º 3
0
void            salle11()
{
  int           action;
  char          *entree;
  int           randmob;

  entree = malloc(sizeof(char*));
  action = 0;
  g_map[4][0].visited = 1;
  g_map[4][0].content = 1;
  look();
  srand(time(NULL));
  randmob = rand();
  MUNI_MAP = 0;
  MEDIC_MAP = 0;

  if ((randmob%4 == 0) && (ARME_EQUIP > 0))
    {
      start_battle();
    }
  while (action == 0)
    {
      /*On propose ici le prompt au joueur*/
      action = readline();
      /*Traitement de laction :*/
      if (action == 3)
        {
	  my_putstr("\nVous avez raison, quittons vite cette réserve flippante !\n");
	  g_map[4][0].content = 0;
	  SALLE = 8;
          salle08();
        }

      /*Prendre*/
      if (action == 5)
        {
          prendre();
          action = 0;
        }
      /*fin prendre*/

      if ((action == 1) || (action == 2) || (action == 4))
	{
	  erreur_depla();
	  action = 0;
	}
    }
}
Exemplo n.º 4
0
void *proc1 (int tube[2], int semid) {
	char cmd[50];
	int file_rd=fileno(stdin);  /* filedescriptor = 0 */
	int file_wr=fileno(stdout); /* filedescriptor = 1 */
	int l;
	do{
		prendre(semid, 0);
		dup2(tube[WRITE_END], file_wr);
		close(tube[READ_END]);
		fgets(cmd, 50, stdin);
		l=strlen(cmd);
		write(tube[WRITE_END], cmd, l);
		rendre(semid,1);
	}while(strcmp(cmd,"quit\n")!=0);
	close(tube[WRITE_END]);
	exit(0);
}
Exemplo n.º 5
0
void *proc2 (int tube[2], int semid) {
	char cmd[50];
	int file_rd=fileno(stdin);  /* filedescriptor = 0 */
	int file_wr=fileno(stdout); /* filedescriptor = 1 */
	int l;
	int i;
	do{
		prendre(semid, 1);
		dup2(tube[READ_END], file_rd);
		close(tube[WRITE_END]);

		l = read(tube[READ_END], cmd, 50);
		for(i=0;i<l-1;i++){
			cmd[i] = toupper(cmd[i]);
		}
		cmd[l-1] = '\0';
		printf("%s\n", cmd);
		rendre(semid, 0);
	}while(strcmp(cmd,"QUIT\n")!=0);
	close(tube[READ_END]);
    exit(0);
}
Exemplo n.º 6
0
void            salle12()
{
  int           action;
  int           randmob;
  int           randmuni;
  int           randmedic;

  action = 0;
  g_map[4][1].visited = 1;
  g_map[4][1].content = 1;
  srand(time(NULL));
  randmob = rand();
  randmuni = rand();
  randmedic = rand();
  MUNI_MAP = 0;
  MEDIC_MAP = 0;

  if (randmedic%10 == 0)
    {
      MEDIC_MAP = 1;
    }
  if ((randmob%4 == 0) && (ARME_EQUIP > 0))
    {
      start_battle();
    }
  if ((randmuni%4 == 0))
    {
      MUNI_MAP = 4;
    }
  while (action == 0)
    {
      /*On propose ici le prompt au joueur*/
      action = readline();
      /*Traitement de laction :*/
      if (action == 3)
        {
	  if (DIAG_S12A09 == 0)
	    {
	      my_putstr("\nJ'arrive dans une grande salle. Oh mon dieu, il y a des hommes au sol...\n");
	      //sleep(2);
	      my_putstr("J'en compte quatre. Il y a du sang partout... Ils s'en sont moins bien sortis que moi...\n");
	      //sleep(2);
	      my_putstr("J'ai pris leurs pouls, tous morts.\n");
	      //sleep(7);
	      my_putstr("Je ne peux rien faire pour eux, continuons.\n");
	      DIAG_S12A09 = 1;
	    }
	  else
	    {
	      my_putstr("OK, je me dirige vers la salle suivante.\n");
	    }
	  g_map[4][1].content = 0;
	  SALLE = 9;
	  salle09();
	}
      if (action == 4)
        {
	  my_putstr("Je traverse un long couloir... Tout est silencieux ici, pas tres rassurant...\n");
	  my_putstr("Je suis arrive dans une grande salle.\n");
	  g_map[4][1].content = 0;
	  SALLE = 13;
	  salle13();
	}
      if (action == 5)
        {
          prendre();
          action = 0;
        }
      if ((action >= 1) && (action <= 2))
        {
	  erreur_depla();
	  action = 0;
        }
    }
}
Exemplo n.º 7
0
void            salle18()
{

  char      *mort;
  int     choix;
  int           action;
  int           randmob;
  int           randmuni;
  int           randmedic;


  choix = 0;
  mort = NULL;
  action = 0;
  g_map[7][1].visited = 1;
  g_map[7][1].content = 1;
  look();
  srand(time(NULL));
  srand(time(NULL));
  randmob = rand();
  randmuni = rand();
  randmedic = rand();
  MUNI_MAP = 0;
  MEDIC_MAP = 0;

  if (randmedic%10 == 0)
    {
      MEDIC_MAP = 1;
    }
  if ((randmob%4 == 0) && (ARME_EQUIP > 0))
    {
      start_battle();
    }
  if ((randmuni%4 == 0))
    {
      MUNI_MAP = 4;
    }
  while (action == 0)
    {
      /*On propose ici le prompt au joueur*/
      action = readline();
      /*Traitement de laction :*/
      if (action == 3)
        {
	  g_map[7][1].content = 0;
	  SALLE = 17;
	  salle17();
	}
      if (action == 4)
	{
	  my_putstr("\nVous etes sur de vouloir aller par la ???\nL'air c'est extrement rafrechie ici... ce n'est pas un bon signe\n\n");
	  my_putstr("Dois-je continuer ???\n   >");
	  while (choix == 0)
	    {
	      mort = readLine();
	      if (strcmp(mort, "oui") == 0)
		choix = 1;
	      else if (strcmp(mort, "non") == 0)
		choix = 2;
	    }
	  if (choix == 1)
	    {
	      if (COMBI == 0)
		{
		  my_putstr("J'entre dans le hangar !\nIl y a un enorme trou dans la coque !\n");
		  my_putstr("Je me sens mal !...\n");
		  //sleep(2);
		  my_putstr("Je...\n");
		  gameover();
		  score("radiations");
		}
	      else
		{
		  my_putstr("\nPfiou!!! Heureusement que j'ai ma combinaison sinon je ne pense pas survivre.\n\n");
		  g_map[7][1].content = 0;
		  SALLE = 19;
		  salle19();
		  choix = 0;
		}
	    }
	  else
	    {
	      my_putstr("\nVous avez surement raison une foi de plus,je vais vous ecouter\n\n");
	      choix = 0;
	      action = 0;
	    }
	}
      /*Prendre*/
      if (action == 5)
        {
          prendre();
          action = 0;
        }
      /*fin prendre*/
      if ((action >= 1) && (action <= 2))
        {
	  erreur_depla();
	  action = 0;
        }
    }
}
Exemplo n.º 8
0
void            salle16()
{
  int           action;
  int           randmuni;
  int           randmedic;


  action = 0;
  g_map[7][0].visited = 1;
  g_map[7][0].content = 1;
  look();
  srand(time(NULL));
  randmuni = rand();
  randmedic = rand();
  MUNI_MAP = 0;
  MEDIC_MAP = 0;

  if (randmedic%10 == 0)
    {
      MEDIC_MAP = 1;
    }
  if ((randmuni%4 == 0))
    {
      MUNI_MAP = 4;
    }
  while (action == 0)
    {
      /*On propose ici le prompt au joueur*/
      action = readline();
      /*Traitement de laction :*/
      if (action == 3)
        {
	  my_putstr("\nVous avez raison, je ferai mieux de ne pas rester dans le coin trop longtemps !\n");
	  g_map[7][0].content = 0;
	  SALLE = 15;
          salle15();
        }
      if (action == 4)
        {
	  if (BOSS_BATTU == 0)
	    {
	      start_battle();
	    }
	  else
	    {
	      my_putstr("Le cadavre de la larve géante gît au sol... C'est répugnant !\n");
	      my_putstr("Je ne vois rien à faire pour le moment, à moins que vous ne sachiez comment combler le trou béant dans la coque ?\n");
	    }
	  action = 0;
        }
      /*Prendre*/
      if (action == 5)
        {
          prendre();
          action = 0;
        }
      /*fin prendre*/
      if ((action >= 1) && (action <= 2))
        {
          erreur_depla();
          action = 0;
        }
    }
}
Exemplo n.º 9
0
void            salle06()
{
  int           action;
  int           randmob;
  int           randmuni;
  int           randmedic;


  action = 0;
  g_map[2][1].visited = 1;
  g_map[2][1].content = 1;
  look();
  srand(time(NULL));
  randmob = rand();
  randmuni = rand();
  randmedic = rand();
  MUNI_MAP = 0;
  MEDIC_MAP = 0;

  if (randmedic%10 == 0)
    {
      MEDIC_MAP = 1;
    }
  if ((randmob%4 == 0) && (ARME_EQUIP > 0))
    {
      start_battle();
    }
  if ((randmuni%4 == 0))
    {
      MUNI_MAP = 4;
    }
  while (action == 0)
    {
      /*On propose ici le prompt au joueur*/
      action = readline();
      /*Traitement de laction :*/
      if (action == 1)
        {
	  my_putstr("\nCe couloir ouvre sur plusieurs portes. Il y a des noms a l'entree de chaque porte. ");
	  my_putstr("COLAS, CURLLY, ... Ce doit etre les quartiers des hommes de l'equipage.\n");
	  my_putstr("Esperons que j'en aprenne d'avantage sur l'equipage.");
	  g_map[2][1].content = 0;
	  SALLE = 5;
          salle05();
        }
      if (action == 2)
        {
	  my_putstr("\nOn dirait... Des quartiers ! Tout est en desordre, mais je devine aux bottes et aux accessoires sur les lits que ce doit etre les quartiers des femmes.\n\n");
	  g_map[2][1].content = 0;
	  SALLE = 7;
	  salle07();
        }
      if (action == 3)
        {
	  if (CARTE_ACCES == 0)
            {
              my_putstr("\nLa porte est fermee. On dirait qu'il faut une badge d'acces.\n");
	      my_putstr("Super, je suis piegee dans un vaisseau flippant, enfermee avec des cadavres...\n");
	      my_putstr("Tout. Va. Bien !\n\n");
              action = 0;
            }
          else
            {
	      my_putstr("J'essaye le badge sur le boitier de la porte...\n");
	      //sleep(2);
	      my_putstr("Et... Ca marche, la porte s'est ouverte !\n");
              g_map[2][1].content = 0;
              SALLE = 3;
              salle03();
            }
        }
      if (action == 4)
        {
          erreur_depla();
          action = 0;
        }
      if (action == 5)
        {
          prendre();
	  action = 0;
        }
    }
}
Exemplo n.º 10
0
int main(int argc, char *argv[]){
	int nbByteCom;
	int i=0, x, y, a, b, k, l, erreur, mauvMouv;
	char str2[100];
	char stop;
	int nbPara;
	int nbPionJ;
	int sockfd;
	DATA *dataBuf=(DATA*)malloc(sizeof(DATA));
	DAMIER *damier;
	PION *p;
	DATA dataFin;
	dataFin.type=FIN;
	damier = init_damier();
	if(damier==NULL){
		printf("Initialisation du damier échouée\n");
		return 0;
	}

	if(argc==2){
		printf("Server, en attente d'un client sur le port %s\n", argv[1]);
		sockfd=server(atoi(argv[1]));
		if(sockfd<0) return 1;
		aff_damier(*damier);

	}else if(argc==3){
		printf("Client, connection au server %s, sur le port %s\n", argv[1], argv[2]);
		sockfd=client(argv[1],atoi(argv[2]));
		if(sockfd<0) return 1;
		
		aff_damier(*damier);
		affTour(damier);
		printf("Nombre de prise possible : %d\n", verif_possibilite_prendre(damier));
		puts("En attente du joueur adverse...");
		nbByteCom=read(sockfd,dataBuf,sizeof(DATA));
		if(nbByteCom>0){
			while(dataBuf->type!=FIN){
				if(readData(damier,*dataBuf)){
					printf("Desynchronisation\n");
					close(sockfd);
					free(dataBuf);
					free_damier(damier);
					return 1;
				}
				aff_damier(*damier);
				nbByteCom=read(sockfd,dataBuf,sizeof(DATA));
			}
		}else{
			printf("Connection perdue\n");
			close(sockfd);
			if(dataBuf!=NULL) free(dataBuf);
			if(damier!=NULL) free_damier(damier);
			exit(0);
		}
		tour_suivant(damier);
	}else{
		printf("Nombre d'arguments incorrect\n");
		return 1;
	}


	while(!fin_partie(damier)){
		mauvMouv=1;
		promotion(damier);
		affTour(damier);
		printf("Nombre de prise possible : %d\n", verif_possibilite_prendre(damier));
		while(mauvMouv){
			mauvMouv=0;
			printf("Action sur un pion : ");
			nbPara=sscanf(fgets(str2,14,stdin),"%d,%d %d,%d %d,%d", &x, &y, &a, &b, &k, &l);
			if(nbPara<1){
				printf("Bye!\n");
				close(sockfd);
				if(dataBuf!=NULL) free(dataBuf);
				if(damier!=NULL) free_damier(damier);
				exit(0);	
			}
			while(nbPara<4){
				printf("paramètre manquant(%d)\n",nbPara);
				printf("Action sur un pion : ");
				nbPara=sscanf(fgets(str2,14,stdin),"%d,%d %d,%d %d,%d", &x, &y, &a, &b, &k, &l);
				if(nbPara<1){
					printf("Bye!\n");
					close(sockfd);
					if(dataBuf!=NULL) free(dataBuf);
					if(damier!=NULL) free_damier(damier);
					exit(0);	
				}
			}
			PION *p1 = rech_pion_c(damier,x,y);
			if(nbPara<6){
				k=a+(a-x);
				l=b+(b-y);
			}
			if(verif_possibilite_prendre(damier)==0){
				if(deplacer(damier,p1,a,b)==0){
					printf("Pion déplacé en (%d,%d)\n",a,b);
					nbByteCom=write(sockfd,&last_modif,sizeof(DATA));
				}else{
					printf("MAUVAIS MOUVEMENT\n");
					mauvMouv=1;
				}
			}else{
				if(prendre(damier,p1,rech_pion_c(damier,a,b),k,l)==0){
					printf("Prise de (%d,%d) par (%d,%d) en (%d,%d)\n",a,b,x,y,k,l);
					nbByteCom=write(sockfd,&last_modif,sizeof(DATA));
					while(verif_possibilite_prendre(damier)>0){
						aff_damier(*damier);
						printf("Rafle : ");
						nbPara=sscanf(fgets(str2,14,stdin),"%d,%d %d,%d %d,%d", &x, &y, &a, &b, &k, &l);
						if(nbPara<1){
							printf("Bye!\n");
							close(sockfd);
							if(dataBuf!=NULL) free(dataBuf);
							if(damier!=NULL) free_damier(damier);
							exit(0);	
						}
						while(nbPara<4){
							printf("paramètre manquant(%d)\n",nbPara);
							printf("Rafle : ");
							nbPara=sscanf(fgets(str2,14,stdin),"%d,%d %d,%d %d,%d", &x, &y, &a, &b, &k, &l);
							if(nbPara<1){
								printf("Bye!\n");
								close(sockfd);
								if(dataBuf!=NULL) free(dataBuf);
								if(damier!=NULL) free_damier(damier);
								exit(0);	
							}
						}
						if(nbPara<6){
							k=a+(a-x);
							l=b+(b-y);
						}
						if(prendre(damier,p1,rech_pion_c(damier,a,b),k,l)==0){
							printf("Prise de (%d,%d) par (%d,%d) en (%d,%d)\n",a,b,x,y,k,l);
							nbByteCom=write(sockfd,&last_modif,sizeof(DATA));
						}else{
							printf("Prise de (%d,%d) par (%d,%d) en (%d,%d)\n",a,b,x,y,k,l);
							printf("MAUVAIS MOUVEMENT\n");
						}
					}
				}else{
					printf("MAUVAIS MOUVEMENT\n");
					mauvMouv=1;
				}
			}
		}
		aff_damier(*damier);
		nbByteCom=write(sockfd,&dataFin,sizeof(DATA));
		tour_suivant(damier);
		affTour(damier);
		printf("Nombre de prise possible : %d\n", verif_possibilite_prendre(damier));
		printf("En attente du joueur adverse...\n");
		nbByteCom=read(sockfd,dataBuf,sizeof(DATA));
		if(nbByteCom>0){
			while(dataBuf->type!=FIN){
				if(readData(damier,*dataBuf)){
					printf("Desynchronisation\n");
					close(sockfd);
					free(dataBuf);
					free_damier(damier);
					return 1;
				}
				aff_damier(*damier);
				nbByteCom=read(sockfd,dataBuf,sizeof(DATA));
			}
		}else{
			printf("Connection perdue\n");
			close(sockfd);
			if(dataBuf!=NULL) free(dataBuf);
			if(damier!=NULL) free_damier(damier);
			exit(0);
		}
		tour_suivant(damier);
	}
	free_damier(damier);
	free(dataBuf);
	close(sockfd);
	return 0;
}
Exemplo n.º 11
0
void            salle23()
{
  int           action;
  int           randmob;
  int           randmuni;
  int           randmedic;


  action = 0;
  g_map[5][2].visited = 1;
  g_map[5][2].content = 1;
  look();
  srand(time(NULL));
  randmob = rand();
  randmuni = rand();
  randmedic = rand();
  MUNI_MAP = 0;
  MEDIC_MAP = 0;

  if (randmedic%10 == 0)
    {
      MEDIC_MAP = 1;
    }
  if ((randmob%4 == 0) && (ARME_EQUIP > 0))
    {
      start_battle();
    }
  if ((randmuni%4 == 0))
    {
      MUNI_MAP = 4;
    }
  while (action == 0)
    {
      /*On propose ici le prompt au joueur*/
      action = readline();
      /*Traitement de laction :*/
      if (action == 1)
        {
	  my_putstr("\nC'est dommage de quitter cette reserve j'en suis sur que d'autre chose qui pourrait mettre utile se cache dedant.\n\n");
	  g_map[5][2].content = 0;
	  SALLE = 13;
	  salle13();
	}
      if (action == 4)
        {
	  my_putstr("\nDes etageres remplie de cartons a ne plus savoir quoi en faire apparament, j'espere en tirer profit");
	  my_putstr(" pour tout le temp que je met a chercher dans chaque carton...\n\n");
	  g_map[5][2].content = 0;
	  SALLE = 24;
	  salle24();
	}

      /*Prendre*/
      if (action == 5)
        {
          prendre();
          action = 0;
        }
      /*fin prendre*/
      if ((action >= 2) && (action <= 3))
        {
	  erreur_depla();
	  action = 0;
        }
    }
}
Exemplo n.º 12
0
void            salle05()
{
  int           action;
  int           randmob;
  int           randmuni;
  int           randmedic;


  action = 0;
  g_map[2][0].visited = 1;
  g_map[2][0].content = 1;
  look();
  srand(time(NULL));
  randmob = rand();
  randmuni = rand();
  randmedic = rand();
  MUNI_MAP = 0;
  MEDIC_MAP = 0;

  if (randmedic%10 == 0)
    {
      MEDIC_MAP = 1;
    }
  if ((randmob%4 == 0) && (ARME_EQUIP > 0))
    {
      start_battle();
    }
  if ((randmuni%4 == 0))
    {
      MUNI_MAP = 4;
    }
  while (action == 0)
    {
      /*On propose ici le prompt au joueur*/
      action = readline();
      /*Traitement de laction :*/
      if (action == 2)
        {
	  my_putstr("\nje traverse un petit couloir etroit. Je commence a avoir sacrementpeur...\n\n");
	      g_map[2][0].content = 0;
	      SALLE = 6;
	      salle06();
	}
      if (action == 4)
        {
	  my_putstr("\nOn retourne vers le cadavre du sergent, vous etes sur de vouloir vraiment y retourner ? Moi personnelement cela ne me plait pas.");
	  g_map[2][0].content = 0;
	  SALLE = 8;
	  salle08();
	}
      if (action == 5)
        {
          prendre();
	  action = 0;
        }
      if ((action == 1) || (action == 3))
        {
	  erreur_depla();
	  action = 0;
        }
    }
}