begin process at 2012 05 29 00:16:05
  Trouver un code source :
 
dans
 
Accueil > Forum > 

C++ & C++ .NET

 > 

Algorithme

 > 

Maths

 > 

ce code ne marche pas??????????


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

ce code ne marche pas??????????

mardi 19 mai 2009 à 03:36:44 | ce code ne marche pas??????????

banak3181

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('');
     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('');
   Affiche_Score(score, MAGENTA);
   Open(&smax);
   time (&s1);
   while (touche != 27)
   {
      time(&s2);
      Affiche_Time(s2-s1);
      Affiche(t, x, y, coulobj, '');
      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, '');
     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('');
     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);
}

vendredi 29 mai 2009 à 12:58:08 | Re : ce code ne marche pas??????????

lectpe

Réponse acceptée !

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];

Cordialement, Grégory.

vendredi 29 mai 2009 à 12:59:19 | Re : ce code ne marche pas??????????

lectpe

Ensuite,

Ce for là ne marche pas :

   for (i = x+1; i < x+l; i ++)
   {
      gotoxy(i, y);
      cprintf("Ä");
      gotoxy(i, y+h);
      cprintf("Ä");
   }

Tu veux aller de i=x+1 à i<x+1, ce qui est une situation impossible.
vendredi 29 mai 2009 à 13:00:44 | Re : ce code ne marche pas??????????

lectpe

(Autant pour moi, c'est x+1 et x+l, comme les deux caractères se ressemblent, j'ai cru que c'était "un" et "un" au lieu de "un" et "el" minuscule)


Cette discussion est classée dans : int, for, return, if, tetrice


Répondre à ce message

Sujets en rapport avec ce message

tableau [ par imanedaoudi ] Salut,Je veux récuperer le tableaux triée sans faire return, avec ce programme je recupere le tableau non trier ,comment faire pour recuperer le tab t Table de hachage avec patronyme [ par guitoontruant ] Bonjour, Désolé, j'avais d'abord poster dans les discussions libres.Voilà je dois créer une table de hashage de patronymes par le biais de N entrées, maths et autres [ par jeanphilippe37 ] Slt, j'ai fais un prgm de maths pour savoir les nbrs premiers mais, quand je mets system("pause"), j'ai une erreur, pouvez vous me corriger ? Return tableau? [ par zut69 ] Bonjour,Je suis en train d'écrire un petit programme sur les matrices en C, mais vu que je veux faire quelque chose d'assez général, j'ai besoin que d Problème compréhension du programme le compte est bon [ par echec ] Bonjour,Je cherchai un programme c++ sur internet qui permettait de calculer la solution du jeu le compte est bon, j'en est finalement trouvé un, mais Probleme : Sudoku en C [ par seth59222 ] Bonsoir, voila je suis actuellement en première année d'info, donc assez novice et je viens de créer ce petit bout de programme en C qui consiste a ré Besoin d'aide c++ [ par sevio14 ] Quelqu'un peut-il m'aider à faire le programme de l'algorithme d'uzawa? Voici ce que j'ai commencé à définir: #include #include #include #includ Problème générateur de grille de sudoku en C [ par Dovah ] Bonjour, je suis débutant en programmation, et pour m'entraîner j'ai décidé de créer un programme qui génère aléatoirement une grille de sudoku en C classe matrice [ par monphp ] slt tt le monde, je suis entrain de réaliser un projet concernant le polymorphisme des matrices et des vecteurs. jé realisé alors une matricecaree qui probleme avec une boite de dialogue [ par anonyme_man_in_this_world ] salut !! ça sera simpa si vous m'aidiez a corriger ce code ******************************************************************************* #


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,328 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales