Bonhomme

Description

juste un petit bonhomme
[a]-> pour tirer en avant
[z] ->pour tirer en arriere
-> et <- pour bouger
il faut atteindre la porte

Source / Exemple :


/*********************************************/
         /*      BONHOMME par ZEKOKO                  */
         /*          ZEKOKO@AOL.COM                   */
         /*********************************************/

#include "graphG.cpp"
#include <pc.h>
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <fstream.h>
//void entrer_code();
/*void lire();
void ecrire(); */
void LitTableau(bool sens1);
void toucheKey(int keyT);
void gagne();
void EffSprite (int spriteX,bool sens);
void ennemi(int exTTL);
void fond();
void EffHero(int h3,int j3);
void GameOver();
void hero(int h,int j);
void jeu();
void Laser(int posX,int longX);
void perdu();
void Retourhero(int h1,int j1);
void RetourLaser(int posX1,int longX1);
void tioub(bool NS);
void PRRR(bool NSP);
void InitEcran();
int testH(int pbH);
bool option();
bool NS;
bool NSP;
bool p;
bool sens1;
int temps;
int score=0;
int vie=70;
int testENX;
char cheat_code[40];
int  tableHEN[8][8] ={{ 0, 0, 0, 0, 0, 0, 0, 0},      //1
                      { 0, 0, 0,10,10, 0, 0, 0},      //2
                      { 0, 0, 0,15,15, 0,10, 0},      //3
                      { 0, 0,15,15,15,15, 0, 0},      //4
                      { 0,10, 0,15,15, 0, 0, 0},      //5
                      { 0, 0, 0,15,15, 0, 0, 0},      //6
                      { 0, 0,15, 0,15, 0, 0, 0},      //7
                      { 0,15, 0, 0,15, 0, 0, 0}};     //8
int  tableHEV[8][10]={{ 0, 0, 0, 0, 0, 0, 0, 0},      //1'
                      { 0, 0, 0,10,10, 0, 0, 0},      //2'
                      { 0,10, 0,15,15, 0, 0, 0},      //3'
                      { 0, 0,15,15,15,15, 0, 0},      //4'
                      { 0, 0, 0,15,15, 0,10, 0},      //5'
                      { 0, 0, 0,15,15, 0, 0, 0},      //6'
                      { 0, 0, 0,15, 0,15, 0, 0},      //7'
                      { 0, 0, 0,15, 0, 0,15, 0}};     //8'
char tableEN[8][8]=  {{ 0, 0, 0, 0, 0, 0, 0, 0},             //1"
                      { 0,10,10,10,10,10,10, 0},             //2"
                      {10,20,20, 5, 5,20,20,10},             //3"
                      {10, 5,20, 5, 5,20, 5,10},             //4"
                      {10, 5, 5, 5, 5, 5, 5,10},             //5"
                      {10, 5, 5,20,20, 5, 5,10},             //6"
                      { 0,10, 5, 5, 5, 5,10, 0},             //7"
                      { 0, 0,10,10,10,10, 0, 0}};            //8"

int tableJEU[40];
int  tableEff[8][8]= {{ 0, 0, 0, 0, 0, 0, 0, 0},      //1"'
                      { 0, 0, 0, 0, 0, 0, 0, 0},      //2"'
                      { 0, 0, 0, 0, 0, 0, 0, 0},      //3"'
                      { 0, 0, 0, 0, 0, 0, 0, 0},      //4"'
                      { 0, 0, 0, 0, 0, 0, 0, 0},      //5"'
                      { 0, 0, 0, 0, 0, 0, 0, 0},      //6"'
                      { 0, 0, 0, 0, 0, 0, 0, 0},      //7"'
                      { 0, 0, 0, 0, 0, 0, 0, 0}};     //8"'

/*void ecrire(int kru)
{
 ofstream scoreEXT("C\\der_score.txt");
  scoreEXT<<"dernier_score"<<kru;
  scoreEXT.close();
}

lire(int kru2)
{
 ifstream scoreEXT("C\\der_score.txt");
  char texteR[40];
  int kru3;
  kru3=kru2;
  scoreEXT<<texteR;
  scoreEXT<<kru3;
  return kru3;
}  */
  

void toucheKey(int keyT)
{
 int keyT2;
  do
   {
    keyT2=getkey();
   }
 while(keyT2!=keyT);
}

void InitEcran()
{
 int i;
 for(i=0;i<40;i++)
  {
   tableJEU[i]=0;
  }
}

bool option()
{
  char opT;
  bool op;
  char op1;
  int i=160;
  int j=160;
  int k=100;
  int l=100;
  while(j>70)
   {
     BoxG(i,k,j,l,9,1);
     BoxG(i-2,k-2,j+2,l+2,5,0);
     delay(30);
   i++;j--;k++;l--;
   }
  gotoxy(17,2);
  cout<<"option\n";
  gotoxy(11,4);
  cout<<"son o/n";
  cin>>opT;
  if(opT=='o')op=1;
  if(opT=='n')op=0;
  gotoxy(12,4);
  cout <<"cheat code o/n \n";
  cin>>op1;
  if(op1=='o');//entrer_code();
  if(op1=='n');
  return op;
tempo();
}

void EffSprite (int spriteX,bool sens)
{
   if(sens == 1)
   {
     BoxG(spriteX,100,spriteX+8,108,15,1);
     delay(60);
     BoxG(spriteX,100,spriteX+8,108,0,1);
     tableJEU[spriteX/8]=0;
    }
   else
   if(sens==0)
    {
      BoxG(spriteX,100,spriteX-8,108,15,1);
      delay(60);
      BoxG(spriteX,100,spriteX-8,108,0,1);
      tableJEU[(spriteX/8)-1]=0;
    }

   score=score+10;
}

int testH(int pbH)
{

   if(tableJEU[pbH]==1)
    {
     vie=vie-7;
     BoxG(pbH*8,100,pbH*8+8,108,4,1);
      delay(60);
     BoxG(pbH*8,100,pbH*8+8,108,0,1);
     PRRR(p);
        if(vie==0)perdu();
    }
}

void perdu()
{
 EraseScreen();
 gotoxy(1,1);
 cout<<temps<<'\n';
 temps=(30-temps)*10;
 score=(score*10)+temps;
 cout<<"perdu\n";
 cout<<"vie :"<<vie<<'\n';
 cout <<"score:"<<score;
 cout<<'\n';
 toucheKey(27);
 exit(0);
}

void ennemi(int exTTL)
{
    tableJEU[exTTL/8]=1;
    int ex,ey,exp,eyp;
    for(ey=0;ey<8;ey++)
      {
        for(ex=0;ex<8;ex++)
          {
            PixelG(exTTL+ey,100+ex,tableEN[ex][ey]);
          }
       }
}

void fond()
{
   cercleG(160,200,125,65);
   BoxG(0,109,320,200,12,1);
   BoxG(0,99,319,109,0,1);
   PixelG(12,12,15);
   PixelG(310,2,15);
   PixelG(100,25,15);
   PixelG(212,65,15);
   PixelG(35,75,15);
   BoxG(309,109,319,90,9,1);
    int xC=200;
    int yC=25;
    int rt;
      for(rt=0;rt<10;rt++)
       {
        cercleG(xC,yC,rt,15);
       }
   BoxG(200-6,25-6,200+6,25+6,15,1);
   LigneG(0,109,320,109,152);
   cercleG(50,115,5,0);
   cercleG(100,155,3,0);
   cercleG(175,125,8,0);
   cercleG(20,190,6,0);
   cercleG(50+200,115-5,5+2,0);
   cercleG(100+120,155-15,3+5,0);
   cercleG(175+115,125+10,8-4,0);
   cercleG(20+290,190-13,6-3,0);
}

void tioub(bool NS)
{
 if (NS==1)
  {
   sound(200*3);
   delay(30);
   nosound();
   sound(400*3);
   delay(30);
   nosound();
  }
}

void PRRR(bool NSP)
{
 if(NSP==1)
  {
   sound(200);
   delay(15);
   nosound();
   sound(300);
   delay(15);
   nosound();
   sound(200);
   delay(15);
   nosound();
  }
}

void Laser(int posX,int longX,int posXTable)
{
  tioub(p);
  int c8=0;
  int g=posX;
   //if(tableJEU[posXTable+1]==1)EffSprite(g,1);
   while(g<longX && tableJEU[posXTable]!=1 &&g<300)
    {
     while(c8<8)
      {
       delay(2);
       PixelG(g,104,15);
       PixelG(g-1,104,0);
       g++;
       c8++;
      }
      posXTable++;
     c8=0;
    }

     PixelG(g-1,104,0);
     PixelG(g-2,104,0);
     if(tableJEU[posXTable]==1)
      {
       EffSprite(g-8,1);
      }
}

void RetourLaser(int posX1,int longX1,int posXTable1)
 {
   tioub(p);
   int g1=posX1;
    int c81=0;
    while(g1>longX1 && tableJEU[posXTable1]!=1 && g1 > 0)
      {
       while(c81<8)
        {
         delay(2);
         PixelG(g1,104,15);
         PixelG(g1+1,104,0);
         g1--;
         c81++;
        }
       c81=0;
       posXTable1--;
      }
      PixelG(g1+1,104,0);
      PixelG(g1+2,104,0);
      if(tableJEU[posXTable1]==1)
        {
         EffSprite(g1+8,0);
        }
}

void hero(int h,int j)
{
 tableJEU[h/8]=2;
 for (int y=0;y<8;y++)
  {
   for (int x=0;x<8;x++)
    {
     PixelG(h+y,j+x,tableHEN[x][y]);
    }
  }
}

void Retourhero(int h1,int j1)
{
 tableJEU[h1/8]=2;
 for(int h2=0;h2<8;h2++)
  {
   for(int j2 =0;j2<8;j2++)
    {
     PixelG(h1+h2,j1+j2,tableHEV[j2][h2]);
    }
  }
}

void EffHero(int h3,int j3)
{
 tableJEU[h3/8]=0;
 for(int h4=0;h4<8;h4++)
  {
   for(int j4=0;j4<8;j4++)
    {
     PixelG(h3+h4,j3+j4,tableEff[j4][h4]);
    }
  }
}

void gagne()
{
 char r =169;
 char sourir =2;
 EraseScreen();
 cout<<"                temps:"<<temps<<'\n';
 temps=(30-temps)*10;
 score=(score*10);
 cout<<"                score:"<<score<<'\n';
 cout<<"                fin\n";
 cout<<'\n';
 toucheKey(27);
 EraseScreen();
 cout<<"     merci d'avoir jou‚ a BONHOMME\n";
 cout<<'\n';
 cout<<"     "<<sourir<<"    ZEKOKO"<<r<<"2001    "<<sourir;
 cout<<'\n';
 toucheKey(27);

 exit(score);
}

void jeu()
{
 int dix;
 int key;
 graphicG();
 InitEcran();
 p=option();
 EraseScreen();
 int v=100;
 int xh=0;
 int xhT=0;
 fond();
 hero(xh,v);
 int x;
 int place;
 int i;
 int posEX,posEXT;

  do
   {
    temps=clock()/CLOCKS_PER_SEC;
     posEX = rand()%5;
     posEXT=posEX;
     posEX=posEX*8;
     i=0;
       while(tableJEU[posEX]==0 && i==0)
         {
          place=rand()%2;
          if (place==0)
            {
             if(posEXT==xhT)testH(posEXT);
             else
              if(posEX+xh>290)posEX==290;
              else
               {
                 posEXT=xhT+posEXT;
               }
            }
          else
          if(place==1)
            {
             if(posEXT==xhT)testH(posEXT);
             else
              if(xh-posEX<0)posEX==0;
              else
               {
                posEXT=xhT-posEXT;
               }
            }
         i++;
         }
    tableJEU[posEXT]=1;
    key=getkey();
     switch(key)
      {
       case 333:sens1=1;EffHero(xh,v);xhT++;xh=xh+8;if(xh>300)gagne();testH(xhT);tableJEU[xhT]=2;break;
       case 331:sens1=0;EffHero(xh,v);xh=xh-8;xhT--;if(xh<0)xh=0;testH(xhT);tableJEU[xhT]=2;break;
       case 97 :sens1=1;Laser(xh+8,xh+48,xh/8);tableJEU[xhT]=2;break;
       case 122:sens1=0;RetourLaser(xh,xh-48,xh/8);tableJEU[xhT]=2;break;
      }
   LitTableau(sens1);
   }
  while(temps<30);
  perdu();
}
void LitTableau(bool sens1)
{

 int i=0;
  for(i=0;i<40;i++)
   {
     switch(tableJEU[i])
      {
       case 1:ennemi(i*8);break;
       case 2:if(sens1==1)hero(i*8,100);if(sens1==0)Retourhero(i*8,100);break;
      }
   }

}

main()
{

jeu();
textG();
Revenir();
}

Conclusion :


rien a dire

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.