Ejemplo n.º 1
0
int main(int argc, char **argv) {
  SDL_Init(SDL_INIT_AUDIO);

  int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these..
  assert(ret == 0);

  sound = Mix_LoadWAV("sound.ogg");
  assert(sound);
  sound2 = Mix_LoadWAV("sound2.wav");
  assert(sound);

  int channel = play();
  printf( "Pausing Channel %d", channel );
  Mix_Pause(channel);
  int paused = Mix_Paused(channel);
  printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" );
  assert(paused);
  Mix_Resume(channel);
  paused = Mix_Paused(channel);
  printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" );
  assert(paused == 0);

  if (argc == 12121) play2(); // keep it alive

  emscripten_run_script("element = document.createElement('input');"
                        "element.setAttribute('type', 'button');"
                        "element.setAttribute('value', 'replay!');"
                        "element.setAttribute('onclick', 'Module[\"_play\"]()');"
                        "document.body.appendChild(element);");

  printf("you should hear two sounds. press the button to replay!\n");

  return 0;
}
Ejemplo n.º 2
0
void play2()
{
	printf("\nPlayer 2 playing\n");
	printf("\nEnter the row: ");
	scanf("%d",&row);
	row--;
	printf("\nEnter the column: ");
	scanf("%d",&col);
	col--;
	if(row < 3 && row >= 0 && col < 3 && col >= 0 && !ch[row][col])
	{
		ch[row][col] = 'o';
		count--;
		player = win();
		if(player == 0)
		{
		    system("cls");
			printf("--------------------------------->Player 2 Wins!!! Congratulations!!!<----------------------------\n");
			count = 0;
			display();
		}
		else
		{
		    system("cls");
			display();
		}
	}
	else
	{
		printf("\nWrong input... Enter again");
		play2();
	}
}
Ejemplo n.º 3
0
int main(int argc, char **argv) {
  SDL_Init(SDL_INIT_AUDIO);

  int ret = Mix_OpenAudio(0, 0, 0, 0); // we ignore all these..
  assert(ret == 0);

  {
      SDL_RWops * ops = SDL_RWFromFile("sound.ogg", "r");
      sound = Mix_LoadWAV_RW(ops, 0);
      SDL_FreeRW(ops);
      assert(sound);
  }

  {
      struct stat info;
      int result = stat("noise.ogg", &info);
      char * bytes = malloc( info.st_size );
      FILE * f = fopen( "noise.ogg", "rb" );
      fread( bytes, 1, info.st_size, f  );
      fclose(f);

      SDL_RWops * ops = SDL_RWFromConstMem(bytes, info.st_size);
      sound3 = Mix_LoadWAV_RW(ops, 0);
      SDL_FreeRW(ops);
      free(bytes);
  }

  {
      music = Mix_LoadMUS("the_entertainer.ogg");
  }
  
  
  sound2 = Mix_LoadWAV("sound2.wav");
  assert(sound2);

  int channel = play();
  printf( "Pausing Channel %d", channel );
  Mix_Pause(channel);
  int paused = Mix_Paused(channel);
  printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" );
  assert(paused);
  Mix_Resume(channel);
  paused = Mix_Paused(channel);
  printf( "Channel %d %s", channel, paused ? "is paused" : "is NOT paused" );
  assert(paused == 0);

  if (argc == 12121) play2(); // keep it alive

  emscripten_run_script("element = document.createElement('input');"
                        "element.setAttribute('type', 'button');"
                        "element.setAttribute('value', 'replay!');"
                        "element.setAttribute('onclick', 'Module[\"_play\"]()');"
                        "document.body.appendChild(element);");

  printf("you should hear two sounds. press the button to replay!\n");

  return 0;
}
Ejemplo n.º 4
0
int main()
{
    draw_board();
    while(1)
    {
        play1();
        play2();
    }
    return 0;
}
Ejemplo n.º 5
0
void	fonction()
{
  int	c;
  char	cc;
  int	n;
  int	j;

  j = 0;
  n = 0;

  char	tab[9][18] = {
    {'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
    {' ',' ','#',' ',' ',' ',' ',' ',' ',' ','#',' ','#',' ',' ',' ',' ','#'},
    {'#',' ','#',' ','#',' ','#',' ','#','#','#',' ','#','#','#',' ',' ',' '},
    {'#',' ',' ',' ','#',' ',' ',' ','#',' ',' ','#',' ',' ',' ',' ','#',' '},
    {'#','#','#',' ','#','#','#','#','#','#',' ',' ',' ','#',' ',' ','#','#'},
    {'#',' ',' ',' ',' ',' ','#','#',' ',' ',' ','#',' ','#','#','#','#','#'},
    {' ',' ','#','#','#',' ','#','#',' ','#','#','#',' ','#','#',' ','#',' '},
    {'#','#','#',' ',' ',' ',' ',' ',' ','#','#','#',' ',' ',' ','#','#',' '},
    {'#','#','#','#','#','#','#','#','#','#','#','#','#','#',' ','#','#','#'}};
  affiche2d(tab);
  while (1)
    {
      if (j == 0)
        j = menu(n);
      char tab[7][15] = {
	{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'},
	{'8',' ',' ','0','0',' ',' ',' ',' ',' ','0','0',' ','0','0'}, 
	{'0','0',' ','0','0',' ','0','0','0',' ','0','0',' ','0','0'}, 
	{'0','0',' ','0','0',' ','0','0',' ',' ',' ',' ',' ','0','0'}, 
	{'0','0',' ',' ',' ',' ','0','0','0','0','0','0',' ','0','0'},
	{'0','0','0','0','0',' ',' ',' ',' ',' ','0','0',' ',' ',' '},
	{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'}
      };
      my_putstr("Rejouez oui(o)/non(n)/menu(m)\n");
      cc = getchar();
      while ((c = getchar()) != '\n' && c != EOF);
      my_putstr("\033[H\033[2J");
      if (cc == 'o')
	{
	  if (j == 1)
	    play1(tab, n, 0);
	  if (j == 2)
	    play2();
	  if (j == 3)
	    play1(tab, n, 1);
	  if (j == 4)
	    play1(tab, n, 2);
	}
      if (cc == 'm')
	j = menu(n);
      if (cc == 'n')
	return ;
    }
}
Ejemplo n.º 6
0
int find(void){
    int i,j,k;
    for(i=0;i<52;i++)
        hand[i]=0;
    for(i=0;i<7;i++){
        for(j=0;j<52;j++)
            pile[i][j]=0;
    }
    for(i=0;i<7;i++){
        pilenum[i]=2;
        firstnum[i]=2;
    }
    firstnum[7]=38;
    handnum=38;
    for(i=0;i<7;i++){
        pile[i][0]=first[i][0];
        pile[i][1]=first[i][1];
    }
    for(i=0;i<38;i++)
        hand[i]=first[7][i];
    count=14;
    for(i=0,j=1;j<=f;j++){
        if(i==7)
            i=0;
        if(pilenum[i]==0){
            i++;
            if(i==7)
                i=0;
        }
        play(i++);
    }
    for(j=0;;i++,j++){
        if(i==7)
            i=0;
        if(j==7)
            j=0;
        while(pilenum[i]==0){
            i++;
            if(i==7)
                i=0;
        }
        while(firstnum[j]==0){
            j++;
            if(j==7)
                j=0;
        }
        play(i);
        play2(j);
        if(isdraw2()){
            return count;
        }
    }


}
Ejemplo n.º 7
0
void display()
{
    int j;
    int i;
    printf("\t\t  <TIC-TAC-TOE>\n");
	for(j = 0; j < 10;j++)
	{
		printf("  ");
	}
	for(j = 0;j < 3;j++)
	{
		printf(" - ");
	}
	printf("\n");
	for(i = 0;i < 3;i++)
	{
		for(j = 0; j < 10;j++)
		{
			printf("  ");
		}
		for(j = 0;j < 3;j++)
		{
			printf("|%c|",ch[i][j]);
		}
		printf("\n");
		for(j = 0; j < 10;j++)
		{
			printf("  ");
		}
		for(j = 0;j < 3;j++)
		{
			printf(" - ");
		}
		printf("\n");
	}

	if(count)
	{
		if(player == 1)
		{
			play1();
		}
		else
		{
			play2();
		}
	}
	else
	{
		printf("\n----------------------------------->END OF GAME<-------------------------------\n");
		again();
	}
}
Ejemplo n.º 8
0
int main() {


    time_t secs;
    time(&secs);
    srand( (unsigned int)secs);

    dir = rand() % 4 + 1;
    BITMAP *buffer, *sball, *player1,*player2;
    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT_WINDOWED, 440, 280, 0, 0);
    buffer = create_bitmap( 440, 280);
    sball=create_bitmap(50,50);
    player1 = create_bitmap( 10, 60);
    player2 = create_bitmap( 10, 60);
    clear_to_color( sball, makecol( 255, 0, 0 ) );
    clear_to_color( player1, makecol( 0, 255, 0 ) );
    clear_to_color( player2, makecol( 0, 255, 0 ) );
    while( !key[KEY_ESC]) {
        clear_to_color( buffer, makecol( 0, 0, 255 ) );
        ball();
        play1();
        play2();
//rest(1);
        blit(sball,buffer,0,0,x,y,sball->w,sball->h);
        blit(player1,buffer,0,0,xx,yy,player1->w,player1->h);
        blit(player2,buffer,0,0,xxx,yyy,player2->w,player2->h);
        blit(buffer,screen,0,0,0,0,440,280);
        std::cout<<"dir"<<dir<<std::endl;
    }

    return 0;

}
Ejemplo n.º 9
0
void createSons()
{
    int pid1, pid2;
    int player1 = 0;
    int player2 = 10;

    time_t t;

    pid1 = fork();
    switch(pid1)
    {
        case -1:
            printf("No child created!\n");
            exit(1);
        case 0:
            signal(SIGINT, my_handler);
            while(1)
            {
                pause();
                srand((unsigned) time(&t));
                printf("Player1 Dice!\n");
                draws[0] = throwTheDice();
                if(*gameStarted == 1)
                {
                    play1(draws[0]);
                }
                sleep(4);
                kill(getppid(), SIGINT);
            }
            break;
        default:
            pid2 = fork();
            switch(pid2)
            {
                case -1:
                    printf("No child created!\n");
                    exit(1);
                case 0:
                    signal(SIGINT, my_handler);
                    while(1)
                    {
                        pause();
                        srand((unsigned) time(&t));
                        printf("Player2 Dice!\n");
                        draws[1] = throwTheDice();
                        if(*gameStarted == 1)
                        {
                            play2(draws[1]);
                        }
                        sleep(4);
                        kill(getppid(), SIGINT);
                    }
                    break;
                default:
                    signal(SIGINT,my_handler);
                    printf("I'm the father!\n");
                    sleep(4);
                    while(1)
                    {
                        kill(pid1, SIGINT);
                        pause();
                        printf("Player1 dice: %d\n", draws[0]);
                        printf("\n");
                        kill(pid2, SIGINT);
                        pause();
                        printf("Player2 dice: %d\n", draws[1]);
                        printf("\n");

                        if(draws[1] < draws[0])
                        {
                            *gameStarted = 1;
                            printf("Player1 win the dice and will start the game!\n");
                            printf("\n");
                            printArray(arr, arrSIZE);
                            while(1) {
                                kill(pid1, SIGINT);
                                pause();
                                printf("Player1 dice: %d\n", draws[0]);
                                isWinner();
                                printArray(arr, arrSIZE);

                                kill(pid2, SIGINT);
                                pause();
                                printf("Player1 dice: %d\n", draws[0]);
                                isWinner();
                                printArray(arr, arrSIZE);
                            }
                            break;
                        }
                        else if(draws[1] > draws[0])
                        {
                            *gameStarted = 1;
                            printf("Player2 win the dice and will start the game!\n");
                            printf("\n");
                            printArray(arr, arrSIZE);
                            while(1) {
                                kill(pid2, SIGINT);
                                pause();
                                printf("Player2 dice: %d\n", draws[1]);
                                isWinner();
                                printArray(arr, arrSIZE);

                                kill(pid1, SIGINT);
                                pause();
                                printf("Player1 dice: %d\n", draws[0]);
                                isWinner();
                                printArray(arr, arrSIZE);
                            }
                            break;
                        }
                        else
                            printf("Dice's are equals, try again please!\n");
                    }
            }
    }
}
Ejemplo n.º 10
0
int check(int ply)
{
    int i=0;
    switch(ply){
case 7 :
    if(digits[6]==0){
    digits[6]=xoro(i);
    gotoxy(28,9);
    printf("%c", xo);
    numb++;
      }else{ if(xo== 'O'){ play2();}
           else if(xo== 'X'){ play1(); }}
    break;
case 4 :
 if(digits[3]==0){
    digits[3]=xoro(i);
    gotoxy(28,12);
    printf("%c", xo);
    numb++;
        }else{ if(xo== 'O'){ play2();}
           else if(xo== 'X'){ play1(); }}
    break;
 case 1 :
    if(digits[0]==0){
    digits[0]=xoro(i);
    gotoxy(28,15);
    printf("%c", xo);
    numb++;
        }else{ if(xo== 'O'){ play2();}
           else if(xo== 'X'){ play1(); }}
    break;
 case 2 :
    if(digits[1]==0){
    digits[1]=xoro(i);
    gotoxy(36,15);
    printf("%c", xo);
    numb++;
        }else{ if(xo== 'O'){ play2();}
           else if(xo== 'X'){ play1(); }}
    break;
 case 5 :
    if(digits[4]==0){
    digits[4]=xoro(i);
    gotoxy(36,12);
    printf("%c", xo);
    numb++;
       }else{ if(xo== 'O'){ play2();}
           else if(xo== 'X'){ play1(); }}
    break;
 case 8 :
    if(digits[7]==0){
    digits[7]=xoro(i);
    gotoxy(36,9);
    printf("%c", xo);
    numb++;
        }else{ if(xo== 'O'){ play2();}
           else if(xo== 'X'){ play1(); }}
    break;
 case 9 :
    if(digits[8]==0){
    digits[8]=xoro(i);
    gotoxy(44,9);
    printf("%c", xo);
    numb++;
      }else{ if(xo== 'O'){ play2();}
           else if(xo== 'X'){ play1(); }}
    break;
 case 6 :
    if(digits[5]==0){
    digits[5]=xoro(i);
    gotoxy(44,12);
    printf("%c", xo);
    numb++;
    }else{ if(xo== 'O'){ play2();}
           else if(xo== 'X'){ play1(); }}
    break;
 case 3 :
    if(digits[2]==0){
    digits[2]=xoro(i);
    gotoxy(44,15);
    printf("%c", xo);
    numb++;
       }else{ if(xo== 'O'){ play2();}
           else if(xo== 'X'){ play1(); }}
    break;

 default :
    play1();}

 gotoxy(36,18);
}