Example #1
0
void engine(char mysteryWord[], char *cat) 
{

    int Length = strlen(mysteryWord);
    int lifeLost = 0;
    int occurances = 0;
    int wrongCharOccurances = 0;
    char input = '\n'; // made to \n so it will be ignored in the first loop

    char HiddenWords[wordLength * 2] = "";// Initialize all to 0
    char wrongChars[11] = ""; //InitializeArray(wrongChars,11); 
    
    hideWord(Length,mysteryWord, HiddenWords);

    while (lifeLost < 10 && contains(HiddenWords, '_', Length * 2) > 0) 
    {
        printScreen(lifeLost, cat, mysteryWord, HiddenWords, wrongChars);
        scanf("\n%c", &input); // /n*c added so that new line char is ignored when enter button is pressed      
        if (lifeLost < 10 && input != '\n')
        {

            occurances = contains(mysteryWord, input, Length); // check if users guess is right
            wrongCharOccurances = contains(wrongChars,input,Length); //check if user has had the same guess before
            if(wrongCharOccurances == 0) // if user has not entered input before
            {
                if (occurances == 0) // If input is a wrong answer 
                {
                  wrongChars[lifeLost] = input;
                  lifeLost = lifeLost + 1;
                }
                 else 
                 {
                  changeWord(mysteryWord, HiddenWords, input,Length);
                 }
            }
        }


    }
    if (lifeLost == 10)
        
    {
        printScreen(lifeLost, cat, mysteryWord, HiddenWords, wrongChars);
        printf("You Lose!");
    }
    else {

        printScreen(lifeLost, cat, mysteryWord, HiddenWords, wrongChars);
        printf("You Win!\n");
    }
}
Example #2
0
int startGame3Points()
{
    screen[1][1] = 1;
    printScreen(screen,speed);
    sleep(1);
    screen[1][2] = 2;
    printScreen(screen,speed);
    sleep(1);
    screen[1][3] = 3;
    printScreen(screen,speed);
    sleep(1);
    headX = 3;
    headY = 1;
    return 0;
}
Example #3
0
int main(void) {

  srand((unsigned int)time(NULL));
  int snake[TAILLE_SNAKE][2],
      len_snake=10,
      pommes[TAILLE_POMME][2],
      len_pommes=5,
      direction[2]={0,-1},
      score=0,
      done=0;
  const unsigned long int tempsDepart=Microsecondes();
  unsigned long int prochainAffichage=0,prochainDeplacement=0;
  initSnake(snake,len_snake);
  initPommes(pommes, len_pommes, snake, len_snake);
  InitialiserGraphique();
  CreerFenetre(BORD,BORD,60*TAILLE_CASE+2*BORD,40*TAILLE_CASE+BORD+40);
  ChoisirEcran(1);


  /*EffacerEcran(CouleurParNom("black"));
  */
  while(!done){
    if(Microsecondes()>prochainAffichage){
      printScreen(snake, len_snake,  pommes, len_pommes, tempsDepart, score);
      prochainAffichage=Microsecondes()+CYCLE;
    }
    GestionTouche(snake, direction, &done);
    if(Microsecondes()>prochainDeplacement){
      DeplacementSnake(snake, len_snake, direction);
      CheckCollisionBord(snake);
      CheckCollisionPomme(len_pommes, pommes, snake, len_snake, &score);
      prochainDeplacement=Microsecondes()+100000;
    }
  }
}
Example #4
0
int main(int argc, char *argv[]) {
	enum color screen[MAX_LEN][MAX_LEN];
        int x = 2, y = 2;
        enum color newcolor, oldcolor, defcolor;

        defcolor = Black;
        oldcolor = Grey;
        newcolor = White;

	initScreen((enum color *)screen,defcolor);
	//initScreen(screen,defcolor);

	screen[0][0] = oldcolor;
	screen[1][1] = oldcolor;
	screen[2][1] = oldcolor;
	screen[3][3] = oldcolor;
	screen[4][4] = oldcolor;
	screen[5][5] = oldcolor;
	screen[6][6] = oldcolor;
	screen[7][7] = oldcolor;
	screen[8][8] = oldcolor;
	screen[9][9] = oldcolor;

	printScreen((enum color *)screen);
	//printScreen(screen);

	fillColor((enum color *)screen,x,y,oldcolor,newcolor);
	//fillColor(screen,x,y,oldcolor,newcolor);

	printScreen((enum color *)screen);
	//printScreen(screen);

	fillColor((enum color *)screen,x-1,y,defcolor,oldcolor);
	//fillColor(screen,x-1,y,defcolor,oldcolor);

	printScreen((enum color *)screen);
	//printScreen(screen);

	return 0;
}
Example #5
0
void *mainGameLoop()
{
    setFood();
    do
    {
        situation = judge(direction);//judge if knock the wall or facing a food.
        debugPrint(1);
        if(situation == 1)//If not hit the wall & not have a food, print out the screen.
        {
            snakeMove(direction);//Draw the screen array.
            printScreen(screen,speed);//Print out the screen for 2 seconds.
            //debugPrint(2);
        }
        if(situation == 2)//If facing a food, longer the snake by change food into the head of the snake.
        {
            snakeEat(direction);
            setFood();
            printScreen(screen,speed);
        }
        else ;
    }
    while (situation != -1);
    return ((void *)0);
}
Example #6
0
int main() {
    srand(time(0));
    bool screen[HEIGHT][WIDTH];
    for (int row = 0; row < HEIGHT; ++row) {
        for (int col = 0; col < WIDTH; ++col) {
            screen[row][col] = rand() % 2 ? true : false;
        }
    }
    printScreen(screen);
    for (int currDim = min(HEIGHT, WIDTH); currDim >= 1; --currDim) {
        if (checkForSquaresOfSize(currDim, screen)) {
            break;
        }
    }
    return 0;
}
Example #7
0
int main(void) {

  srand((unsigned int)time(NULL));
  int snake[TAILLE_SNAKE][2],
      len_snake=10,
      pommes[TAILLE_POMME][2],
      len_pommes=5,
      direction[2]={0,-1},
      score=0,
      done=0;
  unsigned long int tempsDepart=Microsecondes(), tempsActuel,tempsTmp;
  unsigned long int prochainAffichage=0,prochainDeplacement=0;
  initSnake(snake,len_snake);
  initPommes(pommes, len_pommes, snake, len_snake);
  InitialiserGraphique();
  CreerFenetre(BORD,BORD,60*TAILLE_CASE+2*BORD,40*TAILLE_CASE+BORD+40);
  ChoisirEcran(1);/*on dessine tout dans un ecran virtuel (cela joue le role de buffer)
                    puis dans la fonction printScreen on copie l'ecran virtuel sur l'ecran reel*/


  while(!done){
    tempsActuel=Microsecondes();
    if(Microsecondes()>prochainAffichage){
      printScreen(snake, len_snake,  pommes, len_pommes, tempsDepart,tempsActuel, score);
      prochainAffichage=Microsecondes()+CYCLE;
    }
    tempsTmp=Microsecondes();
    GestionTouche(snake, direction, &done);
    tempsDepart+=Microsecondes()-tempsTmp;
    if(Microsecondes()>prochainDeplacement){
      DeplacementSnake(snake, len_snake, direction);
      CheckCollisionBord(snake, &done);
      CheckCollisionQueue(snake,len_snake,&done);
      CheckCollisionPomme(len_pommes, pommes, snake, &len_snake, &score);
      prochainDeplacement=Microsecondes()+50000;
    }
  }
  FermerGraphique();
  return EXIT_SUCCESS;
}
Example #8
0
int main(void) {
  
  srand((unsigned int)time(NULL));
  int snake[TAILLE_SNAKE][2],
      len_snake=10,
      pommes[20][2],
      len_pommes=10,
      direction[2]={0,-1};
  const unsigned long int tempsDepart=Microsecondes();
  unsigned long int prochainAffichage=0,prochainDeplacement=0;
  initSnake(snake);
  initPommes(pommes);

  InitialiserGraphique();
  CreerFenetre(BORD,BORD,60*TAILLE_CASE+2*BORD,40*TAILLE_CASE+BORD+40);
  ChoisirEcran(1);


  /*EffacerEcran(CouleurParNom("black"));
  */
  while(1){
    if(Microsecondes()>prochainAffichage){

      printScreen(snake, len_snake,  pommes, len_pommes, tempsDepart, 45 );
      prochainAffichage=Microsecondes()+CYCLE;
    }
    GestionTouche(snake,direction);
    VerificationBords(snake);
    if(Microsecondes()>prochainDeplacement){
      DeplacementSnake(snake,len_snake,direction);
      prochainDeplacement=Microsecondes()+100000;

    }
    if(ToucheEnAttente()==1 && Touche()==XK_Escape){
      FermerGraphique();
      return EXIT_SUCCESS;
    }
  }
}
Example #9
0
/*!
 \brief  main program of the master

 Sets up the I2C device and ncurses ui.
 Reacts on the user input.

 \param argc
 \param argv[]
 \return int
*/
int main(int argc, char *argv[])
{
   int ch = 0;
   int i;

   //initialize an array of '#' which determines the maximum length of a bar
   for (i = 0; i<LENGTH+1; i++)
	 row[i] = '#';
   row[0] = 'a';
   row[LENGTH] = '\0';
   
   //Initialize I2C-device
   if (I2Cinit() != TRUE)
   {
       printf("Initializing I2C interface failed\n");
       exit (1);
   }

   //Initialize ncurses
   initscr();
   if(has_colors() == FALSE)
	{	endwin();
		printf("Your terminal does not support color\n");
		exit(1);
	}
   start_color();			/* Start color 			*/
   init_pair(1, COLOR_BLUE, COLOR_BLUE);
   cbreak();
   noecho();
    
   //Initialize the duty cycles of the slave
   setAllChannels();
   printScreen();

   int inc = 1;  /*!< Increment/Decrement per key press event */

   //Wait for user input
   while(ch != 'q')
   {
	 ch = getch();
	 switch(ch)
	 {
		 case '+':inc = 2; break;
		 case '-':inc = -2; break;
		 case '1': channel[0]+=inc; 
                   setSingleChannel(0); break;
		 case '2': channel[1]+=inc;
                   setSingleChannel(1); break;
		 case '3': channel[2]+=inc;
                   setSingleChannel(2); break;
		 case '4': channel[3]+=inc;
                   setSingleChannel(3); break;
		 case 'a': channel[0]+=inc; 
				   channel[1]+=inc; 
				   channel[2]+=inc; 
				   channel[3]+=inc; 
                   setAllChannels();    break;
     }
     printScreen();
   }
   endwin();  //Stop ncurses
   
   return 0;
}
Example #10
0
 void Timer::print( bool _toScreen ){
     if ( _toScreen ) 
         printScreen();
     else 
         printLog();
 }
Example #11
0
int main(void) {
	uchar i;
	int intro = 1;
	static char reciveErrorCount = 0;
	static char carrierErrorCount = 0;

	wdt_enable(WDTO_1S);
	/* Even if you don't use the watchdog, turn it off here. On newer devices,
	 * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
	 * RESET status: all port bits are inputs without pull-up.
	 * That's the way we need D+ and D-. Therefore we don't need any
	 * additional hardware initialization.
	 */

	usbInit();
	usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
	i = 0;
	while (--i) { // fake USB disconnect for > 250 ms
		wdt_reset();
		_delay_ms(1);
	}
	usbDeviceConnect();
	//sei();

	//Ports initialization and other piperials
	LCD_Initalize();
	LCD_Clear();

	/* About project screen */
	//LCD_GoTo(center("SMiW 2011/2012"), 0);
	//LCD_WriteText("SMiW 2011/2012");
	//LCD_GoTo(center("Marcin Jabrzyk"), 2);
	//LCD_WriteText("Marcin Jabrzyk");
	irmp_init(); //IR libary
	timer_init(); //IR timmer and ADC starter
	adc_init(); //ADC configuration

	cli();
	intro = 0;
	if (RFM70_Initialize(0, (uint8_t*) "Smiw2")) {
		LCD_GoTo(center("Init RFM70"), 2);
		LCD_WriteText("Init RFM70");
		_delay_ms(100);
	} else {
		LCD_GoTo(center("ERR init RFM70"), 1);
		LCD_WriteText("ERR init RFM70");
	}

	if (RFM70_Present()) {
		LCD_GoTo(center("RFM70 present"), 3);
		LCD_WriteText("RFM70 present");
	} else {
		LCD_GoTo(center("RFM70 not present"), 3);
		LCD_WriteText("RFM70 not present");
	}

	sei();
	for (;;) { /* main event loop */
		wdt_reset();
		usbPoll();

		if (RFM70_Present()) {
			sprintf(screenDebug[0], screenDebugTemplate[0], "OK");
		} else {
			sprintf(screenDebug[0], screenDebugTemplate[0], "ERROR");
		}

		if (Carrier_Detected()) {
			sprintf(screenDebug[1], screenDebugTemplate[1], "OK");
			carrierErrorCount = 0;
		} else {
			carrierErrorCount++;
		}

		if (carrierErrorCount > 50) {
			sprintf(screenDebug[1], screenDebugTemplate[1], "NONE");
		}

		char* _tempGrzejnik;
		if (Packet_Received()) {
			sprintf(screenDebug[2], screenDebugTemplate[2], "OK");
			Receive_Packet(message);

			//if from grzejnik starts with "a" else from piec
			_tempGrzejnik = strchr(message, 'a');

			if (_tempGrzejnik != NULL ) {
				strncpy(tempFromGrzejnik, _tempGrzejnik, 4);
				sprintf(screenCenter[2], screenCenterTemplate[2],
						_tempGrzejnik);
			} else {
				strncpy(tempFromPiec, message, 4);
				sprintf(screenCenter[1], screenCenterTemplate[1], message);
			}

			reciveErrorCount = 0;
		} else {
			reciveErrorCount++;
		}
		if (reciveErrorCount > 90) {
			sprintf(screenDebug[2], screenDebugTemplate[2], "WAIT");
		}

		if (irmp_get_data(&irmp_data)) { // When IR decodes a new key presed.
			lastKey = irmp_data.command; //Save the key
			itoa(irmp_data.command, lastKeyStr, 10); //Convert it to string
			sprintf(screenCenter[3], screenCenterTemplate[3], lastKeyStr);
			isChanged = 1;
			intro = 0;
		}
		if (intro == 0) {
			switch (lastKey) { //Change the view
			case 69:
				printScreenWithCenter(screenLeft);
				break; //CH-
			case 70:
				printScreen(screenCenter);
				break; //CH
			case 71:
				printScreenWithCenter(screenRight);
				break; //CH+
			case 82:
				printScreen(screenDebug);
				break;
			default:
				printScreen(screenCenter);
				break; //Any other key
			}
		}
		usbPoll();
	}
	return 0;
}