SAE11_2023/deplacement.c
2023-12-12 16:07:54 +01:00

89 lines
1.6 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <graph.h>
#define LARGEUR 40
#define HAUTEUR 60
#define TAILLE_MAX 100
int x, y;
input();
if (_kbhit()) {
switch (_getch()) {
case "XK_Right":
x ++;
break;
case "XK_Left":
x --;
break;
case "XK_Up":
y ++;
break;
case "XK_Down":
y --;
gameOver = 1;
break;
}
}
}
void logique() {
int i;
int gameOver,y,x, queueX[], queueY[], longueurQueue[];
int prevX = queueX[0];
int prevY = queueY[0];
int prev2X, prev2Y;
queueX[0] = x;
queueY[0] = y;
for (i = 1; i < longueurQueue; i++) {
prev2X = queueX[i];
prev2Y = queueY[i];
queueX[i] = prevX;
queueY[i] = prevY;
prevX = prev2X;
prevY = prev2Y;
}
switch (_getch()) {
gameOver = 1;
break;
case "XK_Right":
x++;
break;
case "XK_Left":
x--;
break;
case "XK_Up":
y++;
break;
case "XK_Down":
y--;
}
}
int main(void) {
int score;
int gameOver;
InitialiserGraphique();
CreerFenetre(0,0,800,500);
srand(time(NULL));
initialiser();
while (gameOver != 1) {
dessiner();
input();
logique();
Sleep(50);
}
printf("Game Over!\n");
printf("Votre score est: %d\n", score);
}
FermerGraphique();
}