modification timer
This commit is contained in:
80
main.c
80
main.c
@@ -2,7 +2,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <graph.h>
|
#include <graph.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#define CYCLE 10000L
|
|
||||||
|
|
||||||
|
|
||||||
#define LARGEUR_FENETRE 1050
|
#define LARGEUR_FENETRE 1050
|
||||||
@@ -11,6 +10,38 @@
|
|||||||
#define NBR_COLONNE 60
|
#define NBR_COLONNE 60
|
||||||
#define NBR_LIGNE 40
|
#define NBR_LIGNE 40
|
||||||
|
|
||||||
|
void ConvertirMicrosecondes(unsigned long microsecondes, int *minutes, int *secondes) {
|
||||||
|
*secondes = (microsecondes % 60000000) / 1000000;
|
||||||
|
*minutes = *secondes % 60;
|
||||||
|
*secondes = *secondes - *minutes * 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AttendreMillisecondes(unsigned long millisecondes) {
|
||||||
|
unsigned long debut = Microsecondes();
|
||||||
|
unsigned long attente = millisecondes * 1000;
|
||||||
|
while(Microsecondes() - debut < attente){
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void timer(){
|
||||||
|
const unsigned long CYCLE = 1000000L;
|
||||||
|
|
||||||
|
unsigned long suivant = Microsecondes() + CYCLE;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if (Microsecondes() > suivant) {
|
||||||
|
|
||||||
|
int minutes, secondes;
|
||||||
|
ConvertirMicrosecondes(Microsecondes(), &minutes, &secondes);
|
||||||
|
|
||||||
|
printf("Temps écoulé : %02d:%02d\n", minutes, secondes);
|
||||||
|
EcrireTexte(40*TAILLE_CASE,2*TAILLE_CASE,minutes,2);
|
||||||
|
EcrireTexte(40*TAILLE_CASE,5*TAILLE_CASE,secondes,2);
|
||||||
|
suivant = Microsecondes() + CYCLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int x;
|
int x;
|
||||||
@@ -27,9 +58,6 @@ void afficherSerpent(Segment serpent[], int taille) {
|
|||||||
for (i = 0; i < 10; i++) {
|
for (i = 0; i < 10; i++) {
|
||||||
serpent[i].x = LARGEUR_FENETRE / 2 + i * TAILLE_CASE;
|
serpent[i].x = LARGEUR_FENETRE / 2 + i * TAILLE_CASE;
|
||||||
serpent[i].y = HAUTEUR_FENETRE / 2;
|
serpent[i].y = HAUTEUR_FENETRE / 2;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < taille; i++) {
|
|
||||||
RemplirRectangle(serpent[i].x , serpent[i].y, TAILLE_CASE, TAILLE_CASE);
|
RemplirRectangle(serpent[i].x , serpent[i].y, TAILLE_CASE, TAILLE_CASE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,29 +132,13 @@ void deplacerSerpent(int longueurSerpent, Segment serpent[], int direction){
|
|||||||
ChoisirCouleurDessin(s);
|
ChoisirCouleurDessin(s);
|
||||||
RemplirRectangle(serpent[i].x, serpent[i].y, TAILLE_CASE, TAILLE_CASE);
|
RemplirRectangle(serpent[i].x, serpent[i].y, TAILLE_CASE, TAILLE_CASE);
|
||||||
}
|
}
|
||||||
Attendre(100);
|
AttendreMillisecondes(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long Microsecondes() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConvertirMicrosecondes(unsigned long microsecondes, int *minutes, int *secondes) {
|
|
||||||
*minutes = microsecondes / 60000000;
|
|
||||||
*secondes = (microsecondes % 60000000) / 1000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AttendreMicrosecondes(unsigned long microsecondes) {
|
|
||||||
clock_t debut = clock();
|
|
||||||
while ((clock() - debut) * 1000000 / CLOCKS_PER_SEC < microsecondes);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int touche,i, j,x=0,direction=1,longueurSerpent=10;
|
int touche,i, j,x=0,direction=1,longueurSerpent=10;
|
||||||
Segment serpent[10];
|
Segment* serpent = (Segment*) malloc (longueurSerpent*sizeof(Segment));
|
||||||
couleur c;
|
couleur c;
|
||||||
couleur v;
|
couleur v;
|
||||||
couleur s;
|
couleur s;
|
||||||
@@ -141,25 +153,6 @@ int main() {
|
|||||||
EcranJeu();
|
EcranJeu();
|
||||||
afficherPastilleAleatoire(5);
|
afficherPastilleAleatoire(5);
|
||||||
afficherSerpent(serpent, longueurSerpent);
|
afficherSerpent(serpent, longueurSerpent);
|
||||||
|
|
||||||
const unsigned long CYCLE = 1000000L;
|
|
||||||
|
|
||||||
unsigned long suivant = Microsecondes() + CYCLE;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
if (Microsecondes() > suivant) {
|
|
||||||
|
|
||||||
int minutes, secondes;
|
|
||||||
ConvertirMicrosecondes(Microsecondes(), &minutes, &secondes);
|
|
||||||
|
|
||||||
printf("Temps écoulé : %02d:%02d\n", minutes, secondes);
|
|
||||||
|
|
||||||
suivant = Microsecondes() + CYCLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AttendreMicrosecondes(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
@@ -187,9 +180,8 @@ int main() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
deplacerSerpent(longueurSerpent, serpent, direction);
|
||||||
deplacerSerpent(longueurSerpent, serpent, direction);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user