int Robot::Playing::start_main_timer() { TOP::Box & tb = TOP::box(); printf("Playing: Starting timer for %d seconds\n",ROUND_TIME); /* Watch stdin (fd 0) to see when it has input. */ FD_ZERO(&tb.rfds); FD_SET(0, &tb.rfds); for (;;) { /* Copy rfds as select modify the original */ memcpy(&tb.copy_rfds,&tb.rfds,sizeof(tb.rfds)); /* Wait up to five seconds. */ tb.tv.tv_sec = 1; tb.tv.tv_usec = 0; int retval = select(1, &tb.copy_rfds, NULL, NULL, &tb.tv); /* Don't rely on the value of tv now! */ if (retval == -1) perror("select()"); else if (retval) { printf("Data is available now.\n"); /* FD_ISSET(0, &rfds) will be true. */ char toto; read(1,&toto,1); if (toto = 'a') { printf("Shooting!\n"); setState(); } } else { tb.incrementTimer(); if (tb.getRunningTime()==ROUND_TIME) { setState(); break; } printf("No data within one seconds.\n"); } } }