banak3181
Messages postés1Date d'inscriptionsamedi 20 septembre 2008StatutMembreDernière intervention19 mai 2009
-
19 mai 2009 à 03:36
lectpe
Messages postés162Date d'inscriptionlundi 12 novembre 2007StatutMembreDernière intervention17 juillet 2010
-
29 mai 2009 à 13:00
s'il vous plait les gars je veux que quelqu'un me disent pourquoi ce code ne marche sur dev C++:
#include <dos.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
# include<myconio.h>const int Xmax 10, Ymax 20; //La position maximal du tableau "tetrice".const int Xmin 1, Ymin 1; //La position minimal du tableau "tetrice".int Txpos 80/2-Xmax/2, Typos 46/2-Ymax/2; //La position graphique de "tetrice" dans l'ecran.
int tetrice[(Xmax+2)*(Ymax+2)]; //Le tableau "tetrice" de dimenssion "12*22"
//ou on va stocker des "0" ou "2".
int rotation = 0; //Nous informe si l'object a fait une rotaion.
//Cette fonction initialise un tableau "t" de dimenssion "ni*nj" a zero.
void Init_a_zero(int* t, int nj, int ni)
{
int i, j; //Deux simples compteurs.
for (j = 0; j < nj; j ++) //Pour toutes les lignes.
for (i = 0; i < ni; i ++) //Pour toutes les colonnes.
t[j*ni+i] = 0; //Affectation de "0" a la position "j,i".
return;
}
//Cette fonction affiche un rectangle.
void Rectangle(int x, int y, int l, int h, int c)
{
int i;
// textcolor(c);
for (i = x+1; i < x+l; i ++)
{
gotoxy(i, y);
cprintf("Ä");
gotoxy(i, y+h);
cprintf("Ä");
}
for (i = y+1; i < y+h; i ++)
{
gotoxy(x, i);
cprintf("³");
gotoxy(x+l, i);
cprintf("³");
}
gotoxy(x, y);
cprintf("Ú");
gotoxy(x, y+h);
cprintf("À");
gotoxy(x+l, y);
cprintf("¿");
gotoxy(x+l, y+h);
cprintf("Ù");
return;
}
int Getstr(char* s, int n)
{
char c;
unsigned i = 0;
if (n > 255)
n = 255;
do
{ if ((c getch()) 8)
{
if (i > 0)
{
i --;
cprintf("\b \b");
}
continue;
}
cprintf("%c", c); if (c 13 || i n)
break;
s [i] = c;
i ++;
}
while (1);
s[i] = '\0';
if (i)
return (1);
else
return (0);
}
//Cette fonction initialise tetrice
void Init_Tetrice()
{
int i, j;
Init_a_zero(tetrice, Xmax+1+1, Ymax+1+1);
for (i = Xmin-1; i <= Xmax+1; i ++)
{
tetrice[(Ymin-1)*(Xmax+1+1)+i] = 2;
tetrice[(Ymax+1)*(Xmax+1+1)+i] = 2;
}
for (j = Ymin-1; j <= Ymax+1; j ++)
{
tetrice[j*(Xmax+1+1)+Xmin-1] = 2;
tetrice[j*(Xmax+1+1)+Xmax+1] = 2;
}
return;
}
int Test_General(int* t, int x, int y)
{
int i, j;
for (j = 0; j < 5; j ++)
for (i = 0; i < 5; i ++)
if (t[j*5+i] == 1)
{
if (x+i > Xmax || x+i < Xmin || y+j > Ymax || y+j < Ymin)
return (1);
if (tetrice[(y+j)*(Xmax+1+1)+x+i])
return (1);
}
return (0);
}
int Test_Droite(int* t, int x, int y)
{
int i, j;
for (i = 4; i >= 0; i --)
for (j = 0; j < 5; j ++)
if (t[j*5+i] == 1)
if (tetrice[(y+j)*(Xmax+1+1)+x+i+1])
return (1);
return (0);
}
int Test_Gauche(int* t, int x, int y)
{
int i, j;
for (i = 0; i < 5; i ++)
for (j = 0; j < 5; j ++)
if (t[j*5+i] == 1)
if (tetrice[(y+j)*(Xmax+1+1)+x+i-1])
return (1);
return (0);
}
int Test_Bas(int* t, int x, int y)
{
int i, j;
for (i = 0; i < 5; i ++)
for (j = 4; j >= 0; j --)
if (t[j*5+i] == 1)
if (tetrice[(y+j+1)*(Xmax+1+1)+x+i])
return (1);
return (0);
}
int Test_Ligne(int j)
{
int res = 0, i;
for (i = 1; i <= Xmax; i ++)
if (tetrice[j*(Xmax+1+1)+i])
res ++;
if (res == Xmax)
return (1);
return (0);
}
void Affiche_Tetrice(int caract)
{
int i, j;
Rectangle(Txpos, Typos, Xmax+1, Ymax+1, LIGHTRED);
for (j = 1; j <= Ymax; j ++)
for (i = 1; i <= Xmax; i ++)
{
gotoxy(Txpos+i, Typos+j);
textcolor(tetrice[j*(Xmax+1+1)+i]);
cprintf("%c", caract);
}
return;
}
int Test_Tetrice()
{
int res = 0;
int i, j, k;
for (j = Ymax; j >= 1; j --)
if (Test_Ligne(j) == 1)
{
res ++;
for (k = j; k >= 2; k --)
for (i = 1; i <= Xmax; i ++)
tetrice[k*(Xmax+1+1)+i] = tetrice[(k-1)*(Xmax+1+1)+i];
for (i = 1; i <= Xmax; i ++)
tetrice[1*(Xmax+1+1)+i] = 0;
j ++;
Affiche_Tetrice('2;');
sound(500); delay(100); nosound();
}
return (res);
}
void Affiche(int* t, int x, int y, int c, int caract)
{
int i, j;
textcolor(c);
for (j = 0; j < 5; j ++)
for (i = 0; i < 5; i ++)
if (t[j*5+i] == 1)
{
gotoxy(Txpos+x+i, Typos+y+j);
cprintf("%c", caract);
}
return;
}
void _1(int* t)
{
Init_a_zero(t, 5, 5);
t[1*5+2] = 1;
t[2*5+1] = 1;
t[2*5+2] = 1;
t[2*5+3] = 1;
return;
}
void _2(int* t)
{
Init_a_zero(t, 5, 5);
t[1*5+2] = 1;
t[1*5+3] = 1;
t[2*5+1] = 1;
t[2*5+2] = 1;
return;
}
void _3(int* t)
{
Init_a_zero(t, 5, 5);
t[1*5+1] = 1;
t[1*5+2] = 1;
t[2*5+2] = 1;
t[2*5+3] = 1;
return;
}
void _4(int* t)
{
Init_a_zero(t, 5, 5);
t[1*5+2] = 1;
t[1*5+3] = 1;
t[2*5+2] = 1;
t[2*5+3] = 1;
return;
}
void _5(int* t)
{
Init_a_zero(t, 5, 5);
t[2*5+1] = 1;
t[2*5+2] = 1;
t[2*5+3] = 1;
t[2*5+4] = 1;
return;
}
void _6(int* t)
{
Init_a_zero(t, 5, 5);
t[1*5+1] = 1;
t[2*5+1] = 1;
t[2*5+2] = 1;
t[2*5+3] = 1;
return;
}
void _7(int* t)
{
Init_a_zero(t, 5, 5);
t[1*5+3] = 1;
t[2*5+1] = 1;
t[2*5+2] = 1;
t[2*5+3] = 1;
return;
}
void Rotation(int* t, int x, int y, int obj)
{
int temp[5*5];
int i1, j1, i2, j2;
if (obj == 3)
return;
i2 = 0;
for (j1 = 0; j1 < 5; j1 ++)
{
j2 = 0;
for (i1 = 4; i1 >= 0; i1 --)
{
temp[j2*5+i2] = t[j1*5+i1];
j2 ++;
}
i2 ++;
}
if (Test_General(temp, x, y) == 1)
return;
for (j1 = 0; j1 < 5; j1 ++)
for (i1 = 0; i1 < 5; i1 ++)
t[j1*5+i1] = temp[j1*5+i1];
return;
}
void Tetrice_T(int *t, int x, int y, int coulobj)
{
int i, j;
for (j = 0; j < 5; j ++)
for (i = 0; i < 5; i ++)
if (t[j*5+i] == 1)
tetrice[(y+j)*(Xmax+1+1)+x+i] = coulobj;
return;
}
void Affiche_Score(int score, int c)
{
textcolor(c);
gotoxy(36, Typos+Ymax+2);
cprintf("Score = %d.", score);
return;
}
void Save(int score)
{
FILE* f;
char nom[20]; if ((f fopen("tetrice.sco", "wb")) NULL)
return;
window(5, 10, 30, 15);
textcolor(WHITE);
textbackground(BLUE);
clrscr();
gotoxy(2, 2);
cprintf("Entrez votre nom : \n\n\n\r ");
Getstr(nom, 19);
fwrite(nom, sizeof (char), 20, f);
fwrite(&score, sizeof (int), 1, f);
fclose(f);
return;
}
void Open(int* score)
{
FILE* f;
char nom[20] = "???????";
if ((f = fopen("tetrice.sco", "rb")) != NULL)
{
fread(nom, sizeof (char), 20, f);
fread(score, sizeof (int), 1, f);
fclose(f);
}
textcolor(WHITE);
gotoxy(5, 5);
cprintf("Nom : %s", nom);
gotoxy(5, 7);
cprintf("Score : %d", *score);
return;
}
void Affiche_Time(long s)
{
textcolor(RED);
textbackground(BLUE);
gotoxy(60, 5);
cprintf("Time : %ld", s);
textbackground(BLACK);
return;
}
void main()
{
char touche = 0;
int t[5*5], x = 4, y = 0;
int temp[5*5], xtemp = 4, ytemp = 0;
int obj;
int coulobj = RED;
int rot = 0;
int score = 0, stemp;
int smax = 0;
long compt = 0;
long maxcompt = 1500;
long s1, s2;
randomize();
clrscr();
textmode(C4350);
_setcursortype(_NOCURSOR);
Init_Tetrice();
obj = 0;
_1(t);
_1(temp);
Affiche_Tetrice('2;');
Affiche_Score(score, MAGENTA);
Open(&smax);
time (&s1);
while (touche != 27)
{
time(&s2);
Affiche_Time(s2-s1);
Affiche(t, x, y, coulobj, '1;');
switch (touche)
{
case ('M') : if (Test_Droite(t, x, y) == 0)
x ++;
break;
case ('K') : if (Test_Gauche(t, x, y) == 0)
x --;
break;
case ('P') : if (Test_Bas(t, x, y) == 0)
y ++;
else
compt = maxcompt-2-(s2-s1);
break;
case ('H') : Rotation(t, x, y, obj);
rot = 1;
break;
}
compt ++;
touche = 0;
if (kbhit())
{
touche = getch();
}
if (xtemp != x || ytemp != y || rot == 1)
{
Affiche(temp, xtemp, ytemp, BLACK, '2;');
if (rot == 1)
{
Rotation(temp, x, y, obj);
rot = 0;
}
xtemp = x;
ytemp = y;
} if (Test_Bas(t, x, y) 1 && y 0)
break;
if (Test_Bas(t, x, y) == 0)
{
if (compt == maxcompt-(s2-s1))
{
y ++;
compt = 0;
}
}
else
if (compt == maxcompt-1-(s2-s1))
{
Tetrice_T(t, x, y, coulobj);
Affiche_Tetrice('2;');
Affiche_Score(score, MAGENTA);
if ((stemp = Test_Tetrice()) > 0)
{
score = score + stemp*10 + (stemp-1)*10;
Affiche_Score(score, MAGENTA);
}
obj = random(7);
switch (obj)
{
case (0) : _1(t);
_1(temp);
coulobj = RED;
break;
case (1) : _2(t);
_2(temp);
coulobj = LIGHTGREEN;
break;
case (2) : _3(t);
_3(temp);
coulobj = LIGHTCYAN;
break;
case (3) : _4(t);
_4(temp);
coulobj = WHITE;
break;
case (4) : _5(t);
_5(temp);
coulobj = BLUE;
break;
case (5) : _6(t);
_6(temp);
coulobj = LIGHTMAGENTA;
break;
case (6) : _7(t);
_7(temp);
coulobj = YELLOW;
break;
}
if (y == 0)
break; x 4; xtemp 4; y 0; ytemp 0;
}
}
gotoxy(36, Typos+10);
textcolor(15);
cprintf("Game Over");
if (score > smax)
Save(score);
else
getch();
textmode(MONO);
_setcursortype(_NORMALCURSOR);
}
lectpe
Messages postés162Date d'inscriptionlundi 12 novembre 2007StatutMembreDernière intervention17 juillet 20103 29 mai 2009 à 12:58
Bonjour,
Alors tu as déjà un problème ici :
void Init_a_zero(int* t, int nj, int ni)
{
int i, j; //Deux simples compteurs.
for (j = 0; j < nj; j ++) //Pour toutes les lignes.
for (i = 0; i < ni; i ++) //Pour toutes les colonnes.
t[j*ni+i] = 0; //Affectation de "0" a la position "j,i".
return;
}
Pour écrire à la position "j,i" tu dois mettre t[j][ni+i] après avoir déclaré un tableau t[MAX_EN_J][MAX_EN_I];