10#include <manux/config.h>
11#include <manux/types.h>
18#define PONG_RAQUETTE 5
20#define PONG_BALLE_TICKS 4
21#define PONG_SCORE_MAX 7
23#define PONG_RESET "\033[0m"
24#define PONG_CYAN "\033[36m"
25#define PONG_JAUNE "\033[33m"
26#define PONG_VERT "\033[32m"
27#define PONG_BLANC "\033[97m"
29static int pongJoueurY, pongOrdinateurY;
30static int pongBalleX, pongBalleY, pongDX, pongDY;
31static int pongScoreJoueur, pongScoreOrdinateur;
32static int pongQuitter;
34static void pongPosition(
int y,
int x)
36 printf(
"\033[%d;%dH", y, x);
39static void pongPause(
void)
44static void pongRafraichir(
void)
51static void pongEffacer(
void)
53 for (
int y = 1; y <= 25; y++) {
55 for (
int x = 1; x < 80; x++)
61static void pongScore(
void)
65 pongScoreJoueur, pongScoreOrdinateur);
68static void pongDecor(
void)
89 printf(
"j : monter k : descendre q : quitter Premier a 7");
93static void pongRaquette(
int x,
int y,
int visible,
const char *couleur)
96 pongPosition(y + i, x);
104static void pongBalle(
int visible)
106 pongPosition(pongBalleY, pongBalleX);
113static void pongRecentrer(
int direction)
121static void pongInitialiser(
void)
124 pongOrdinateurY = 11;
126 pongScoreOrdinateur = 0;
131static void pongDeplacerJoueur(
int delta)
133 int y = pongJoueurY + delta;
138 if (y != pongJoueurY) {
145static void pongDeplacerOrdinateur(
void)
148 int cible = pongBalleY;
149 int y = pongOrdinateurY;
152 else if (cible > centre)
158 if (y != pongOrdinateurY) {
165static void pongAvancerBalle(
void)
167 int nx = pongBalleX + pongDX;
168 int ny = pongBalleY + pongDY;
173 pongBalleY % 2 == 0) {
174 pongPosition(pongBalleY, pongBalleX);
178 if (ny <= PONG_HAUT || ny >=
PONG_BAS) {
180 ny = pongBalleY + pongDY;
186 pongDY = (ny < pongJoueurY + 2) ? -1 : 1;
187 nx = pongBalleX + pongDX;
190 ny >= pongOrdinateurY && ny < pongOrdinateurY +
PONG_RAQUETTE) {
192 pongDY = (ny < pongOrdinateurY + 2) ? -1 : 1;
193 nx = pongBalleX + pongDX;
197 pongScoreOrdinateur++;
223 while (!pongQuitter &&
227 for (
int i = 0; i < 16; i++) {
228 long n =
lire(0, &touche, 1);
232 pongDeplacerJoueur(-1);
233 else if (touche ==
'k')
234 pongDeplacerJoueur(1);
235 else if (touche ==
'q') {
240 if (++aiTicks >= 8) {
242 pongDeplacerOrdinateur();
254 printf(
"Partie interrompue. ");
int lire(int fd, void *buffer, int nb)
void printf(char *format,...)
Un premier printf.
: Définition des fonctions de base du mode utilisateur de ManuX.
int attendreMillisecondes(uint32_t nMs)
un appel système sans intérêt si ce n'est de faire des tests/demo