Ejemplo n.º 1
0
static void sound_callback(gchar *file)
{
  if (! gcomprisBoard)
    return;

  if (!playing_sound)
    return;

  playing_sound = FALSE;
  if (currentMode == MODE_TUX){
    if (to_tux) {
      if (firstCard && secondCard){
	if (compare_card(firstCard, secondCard)==0){
	  gc_sound_play_ogg ("sounds/gobble.wav", NULL);
	  win_id = g_timeout_add (1000,
				  (GSourceFunc) hide_card, NULL);
	  tux_id = g_timeout_add (2000,
				  (GSourceFunc) tux_play, NULL);
	  return;
	} else {
	  to_tux = FALSE;
	  return;
	}
      } else {
	tux_id = g_timeout_add (2000,
			      (GSourceFunc) tux_play, NULL);
	return;
      }
    }
  }
  if (firstCard && secondCard)
    check_win();
}
Ejemplo n.º 2
0
static void check_win()
{

  gint timeout, timeout_tux;

  if (currentUiMode == UIMODE_SOUND){
    timeout = 200;
    timeout_tux = 500;
  }
  else {
    timeout = 1000;
    timeout_tux = 2000;
  }


  // Check win
  if (compare_card((gpointer) firstCard, (gpointer) secondCard) == 0) {
    gc_sound_play_ogg ("sounds/flip.wav", NULL);
    win_id = g_timeout_add (timeout,
			    (GSourceFunc) hide_card, NULL);
    lock_user = FALSE;
    return;
  }

  if (currentMode == MODE_TUX){
    /* time to tux to play, after a delay */
    to_tux = TRUE;
    g_warning("Now tux will play !");
    tux_id = g_timeout_add (timeout_tux,
			    (GSourceFunc) tux_play, NULL);
    lock_user = FALSE;
    return;
  }

}
Ejemplo n.º 3
0
static gint tux_play(){
  int rx, ry;

  if (Paused){
    g_warning("Paused");
    return TRUE;
  }

  if ( ! to_tux )
    return TRUE;

  if(secondCard)
    {
      display_card(firstCard, ON_BACK);
      firstCard = NULL;
      display_card(secondCard, ON_BACK);
      secondCard = NULL;
    }

  if (winning_pairs){
    if (!firstCard){
      firstCard = ((WINNING *) winning_pairs->data)->first ;
      display_card(firstCard, ON_FRONT);
      if (currentUiMode == UIMODE_SOUND)
	return FALSE;
      else
	return TRUE;
    } else {
      secondCard = ((WINNING *) winning_pairs->data)->second;
      display_card(secondCard, ON_FRONT);
      if (currentUiMode == UIMODE_SOUND)
	return FALSE;
      else {
	gc_sound_play_ogg ("sounds/flip.wav", NULL);
	win_id = g_timeout_add (1000,
				(GSourceFunc) hide_card, NULL);
	return TRUE;
      }
    }
  }

  // Randomly set the pair
  rx = g_random_int_range( 0, numberOfColumn);
  ry = g_random_int_range(0, numberOfLine);

  gboolean  stay_unknown = (remainingCards > (g_queue_get_length (tux_memory)
					      + (firstCard ? 1 : 0)));

  g_warning("remainingCards %d tux_memory %d -> stay_unknown %d",
	    remainingCards,
	    g_queue_get_length (tux_memory),
	    stay_unknown );

  while((memoryArray[rx][ry]->hidden) || (memoryArray[rx][ry] == firstCard)
	|| (stay_unknown && g_queue_find(tux_memory,memoryArray[rx][ry])))
    {
      g_warning("Loop to find %d %d %s", rx, ry, memoryArray[rx][ry]->data);
      rx++;
      // Wrap
      if(rx>=numberOfColumn)
	{
	  rx=0;
	  ry++;
	  if(ry>=numberOfLine)
	    ry=0;
	}
    }

  if (!firstCard){
    firstCard = memoryArray[rx][ry];
    add_card_in_tux_memory(firstCard);
    display_card(firstCard, ON_FRONT);
    if (currentUiMode == UIMODE_SOUND)
      return FALSE;
    else
      return TRUE;
  } else {
    secondCard = memoryArray[rx][ry];
    add_card_in_tux_memory(secondCard);
    display_card(secondCard, ON_FRONT);
    if (currentUiMode == UIMODE_SOUND)
      return FALSE;
    else {
      if (compare_card(firstCard, secondCard)==0){
	gc_sound_play_ogg ("sounds/flip.wav", NULL);
	win_id = g_timeout_add (1000,
				(GSourceFunc) hide_card, NULL);
	return TRUE;
      } else{
	to_tux = FALSE;
	return FALSE;
      }
    }
  }
  return FALSE;
}
Ejemplo n.º 4
0
void main()
{
  char UID[6];
  unsigned char TagType;
  char size;
//  char i;
  UART_init();
  //Inicializa Soft SPI
   SPI_init(0);

  //inicializa o modulo RFID
  MFRC522_Init();
  
  TRIS_LED1 = 0;
  TRIS_BUTTON = 1;
  TRIS_OUTPUT1 = 0;
  for(int i=0;i<10;i++)
  {
      LED1 = 1;
      __delay_ms(250);
      LED1 = 0;
      __delay_ms(250);
  }
  while(1)
  {
      if(BUTTON == 0)
      {
          num++;
      }
      if(num==8)
      {
          clear_list_cards();
          printf("Lista apagada\n\r");
          num=0;
          LED1 = 1;
          for(char i=0;i<10;i++)__delay_ms(100);
          LED1 = 0;
      }
      //Letura
    if( MFRC522_isCard( &TagType ) )
    {
      //Exibe o tipo do cartão na serial
      printf("Tipo de Tag: %u\n\r",TagType);
      //Faz a leitura do numero de serie
      if( MFRC522_ReadCardSerial( UID ) )
      {
        //Só mostra que um cartão foi lido
        LED1 = 1;
        printf("Codigo: ");
        for(int i=0; i < 5; i++)
        {
            printf("%X ",UID[i]);
        }
        printf("\n\r");

        //Gravação
        if(BUTTON == 0)
        {
            record_card(UID);
            num = 0;
            printf("Cartão cadastrado\n\r");
            LED1=1;
            __delay_ms(250);
            LED1=0;
        }
        //Comparação
        if(compare_card(UID))
        {
            OUTPUT1=1;
            printf("Cartão reconhecido!\n\r");
            for(char i=0;i<8;i++)__delay_ms(250);//2 segundos
            OUTPUT1=0;
        }
        else
        {
            printf("Cadastre o cartão\n\r");
        }
//        size = MFRC522_SelectTag( UID );
      }
      //Estado de hibernação
      //MFRC522_Halt();
    }
    LED1 = 0;
    __delay_ms(250);
  }
}