Bienvenido a Tecnohackers

Tecnohackers » Programacion » Area de Programacion » Programacion a Bajo Nivel. APIs, Hooking, ASM, C/C++, etc.
 » 

Culebra en C++ [Juego]



Autor Tema: Culebra en C++ [Juego]  (Leído 1632 veces)

Desconectado CronuX

  • Veterano
  • ***
  • Mensajes: 303
  • OllyDBG
Culebra en C++ [Juego]
« en: Septiembre 28, 2010, 01:04:38 pm »
Clásico juego de la culebra que aparece en los celulares.

Código: You are not allowed to view links. Register or Login
                                                        /*******************************************************************

*                                                                  *

*                       Programa Culevra Vercion 1.0               *

*                       Autor: Ramirez porfirio fredy              *

*                          08 de Octubre del 2003.                 *

*                                                                  *

********************************************************************/

#include <iostream.h>

#include <conio.h>

#include <ctype.h>

#include <dos.h>

#include <string.h>

#include <stdlib.h>

#include <time.h>

char *Mensages[]={"   JUGAR   ",

                  "   NIVEL   ",

                  " ACERCA DE ",

                  "   AYUDA   ",

                  "   SALIR   "};

struct Serpiente

{

        int x;

        int y;

}Cole[750],Exito;

Serpiente Critico[500];

int Nivel=1;

int Velocidad=350/Nivel;

int Puntos;

int LONGITUD_CULEBRA;

int Posx=1;

int Posy=0;

void IniciaCulebra()

{

        Cole[0].x=10;

        Cole[0].y=10;

        Cole[1].x=9;

        Cole[1].y=10;

        Cole[2].x=8;

        Cole[2].y=10;

        LONGITUD_CULEBRA=3;

}

void LiberaCulebra()

{

        for(int S=0; S<LONGITUD_CULEBRA; S++)

        {

                Cole[S].x=0;

                Cole[S].y=0;

        }

}

void marco(int X1,int X2,int Y1,int Y2,int sombra,char Titulo[20])

{

        int Cont1=0;

        int Cont2=0;

        int Medio=(X1+((X2-X1)/2)-(strlen(Titulo)/2))-1;

        for(Cont1=X1+1; Cont1<X2; Cont1++)

        {

                gotoxy(Cont1,Y1); cprintf("Í");

                gotoxy(Cont1,Y2); cprintf("Í");

        }

        for(Cont2=Y1+1; Cont2<Y2; Cont2++)

        {

                gotoxy(X1,Cont2); cprintf("º");

                gotoxy(X2,Cont2); cprintf("º");

        }

        for(Cont1=X1+1; Cont1<=X2-1; Cont1++)

        {

                for(Cont2=Y1+1; Cont2<=Y2-1; Cont2++)

                {

                        gotoxy(Cont1,Cont2); cprintf(" ");

                }

        }

        gotoxy(X2,Y1); cprintf("»");

        gotoxy(X1,Y2); cprintf("È");

        gotoxy(X1,Y1); cprintf("É");

        gotoxy(X2,Y2); cprintf("¼");

        if(sombra)

        {

                textcolor(BLACK);

                for(int Cont1=X1+1; Cont1<=X2+1; Cont1++)

                {

                        gotoxy(Cont1,Y2+1); cprintf("Û");

                }

                for(int Cont2=Y1+1; Cont2<=Y2+1; Cont2++)

                {

                        gotoxy(X2+1,Cont2); cprintf("ÛÛ");

                }

        }

        if(strlen(Titulo)!=0)

                gotoxy(Medio,Y1); cout <<" "<<Titulo<<" ";

}

void ResaltaNivel()

{

        textattr(65 + ((66) << 4));

        gotoxy(30,13);

        for(int For=1; For<=Nivel; For++)

                cprintf("   ");

        delay(50);

}

void Niveles()

{

        char Opc;

        gotoxy(3,25); cprintf("Pulse [ENTER] para aceptar.");

        textbackground(7);

        textcolor(0);

        marco(28,52,11,15,1,"NIVELES");

        do

        {

                textbackground(BLUE);

                gotoxy(30,13); cprintf("               ");

                ResaltaNivel();

                textbackground(7);

                gotoxy(50,13); cprintf("%d",Nivel);

                Opc=getch();

                switch(Opc)

                {

                        case 77: if(Nivel<=4) Nivel++; break;

                        case 75: if(Nivel>=2) Nivel--; break;

                        case 13: return;

                }

        }while(1);

}

void Resalta(int x)

{

        textattr(65 + ((66) << 4));

        gotoxy(1+(11*x),1);cprintf("%s",Mensages[x]);

        delay(50);

}

void Linea(int Y)

{

        for(int x=0; x<80; x++)

        {

                gotoxy(x,Y); cprintf(" ");

        }

}

void Proceso()

{

        textcolor(BLUE);

        textbackground(RED);

        Linea(1);

        Linea(25);

        gotoxy(1,1);

        for(int X=0; X<5;X++)

                cprintf("%s",Mensages[X]);

        textcolor(WHITE);

        textbackground(BLUE);

        marco(1,80,2,24,0,"");

}

void DibujaManzana()

{

        int Error;

        randomize();

        textbackground(BLUE);

        textcolor(RED);

        do

        {

                Error=0;

                Exito.x=random(77)+2;

                Exito.y=random(20)+3;

                for(int Corre=0; Corre<LONGITUD_CULEBRA; Corre++)

                        if((Exito.x==Cole[Corre].x) && (Exito.y==Cole[Corre].y))

                                Error=1;

        }while(Error);

        gotoxy(Exito.x,Exito.y); cprintf("ä");

}

int ErrorTerminal()

{

        for(int X=1; X<=79; X++)

        {

                if(((Cole[0].x)==X) && (Cole[0].y==2 || Cole[0].y==24))

                        return 1;

        }

        for(int Y=2; Y<=23; Y++)

        {

                if(((Cole[0].y)==Y) && (Cole[0].x==1 || Cole[0].x==80))

                        return 1;

        }

        for(int Corre=2; Corre<LONGITUD_CULEBRA; Corre++)

        {

                        if(Cole[0].x==Cole[Corre].x && Cole[0].y==Cole[Corre].y)

                                return 1;

        }

        return 0;

}

void DibujaCulebra(int Aumen)

{

        textcolor(BLACK);

        textbackground(BLUE);

        if(Aumen)

        {

                Cole[LONGITUD_CULEBRA].x=Cole[LONGITUD_CULEBRA-1].x;

                Cole[LONGITUD_CULEBRA].y=Cole[LONGITUD_CULEBRA-1].y;

                LONGITUD_CULEBRA++;

        }

        gotoxy(Cole[LONGITUD_CULEBRA-1].x,Cole[LONGITUD_CULEBRA-1].y); cprintf(" ");

        gotoxy(Cole[0].x+Posx,Cole[0].y+Posy); cprintf("²");

        for(int i=LONGITUD_CULEBRA-1; i>0; i--)

        {

                Cole[i].x=Cole[i-1].x;

                Cole[i].y=Cole[i-1].y;

        }

        Cole[0].x+=Posx;

        Cole[0].y+=Posy;

}

void Mueve()

{

        int Trampa;

        int Aux=77;

        while(1)

        {

                if(kbhit())

                {

                        Trampa=getch();

                        if(Trampa==0) Trampa=getch();

                        switch(Trampa)

                        {

                                case 72: if(Aux!=80){Posy=-1; Posx=0; Velocidad=((75*2)*(6-Nivel));}else Trampa=80; break;

                                case 80: if(Aux!=72){Posy=1;  Posx=0; Velocidad=((75*2)*(6-Nivel));}else Trampa=72;break;

                                case 75: if(Aux!=77){Posy=0; Posx=-1; Velocidad=(75*(6-Nivel));}    else Trampa=77;break;

                                case 77: if(Aux!=75){Posy=0; Posx=1;  Velocidad=(75*(6-Nivel));}    else Trampa=75;break;

                                case 27: return;

                        }

                }

                Aux=Trampa;

                if(!ErrorTerminal())

                {

                        DibujaCulebra(0);

                        if(Cole[0].x==Exito.x && Cole[0].y==Exito.y)

                        {

                                DibujaCulebra(1);

                                DibujaManzana();

                                Puntos+=Nivel;

                                textcolor(BLACK);

                                textbackground(RED);

                                gotoxy(66,1); cprintf("Puntos: %4d",Puntos);

                        }

                }

                else

                {

                        textbackground(7);

                        marco(20,60,10,15,1,"FIN DEL JUEGO");

                        gotoxy(23,13); cprintf("Tu Puntuacion es. %d",Puntos);

                        delay(5000);

                        return;

                }

                delay(Velocidad);

        }

}

void Juega()

{

        LiberaCulebra();

        IniciaCulebra();

        Puntos=0;

        Linea(25);

        gotoxy(3,25); cprintf(" [ESC] Para suspender el juego.     ");

        DibujaManzana();

        textcolor(BLACK);

        textbackground(RED);

        gotoxy(66,1); cprintf("Puntos: %4d",Puntos);

        textbackground(BLUE);

        gotoxy(8,10); cprintf("²²²");

        Mueve();

}

void AcercaDe()

{

        gotoxy(3,25); cprintf("Pulse una tecla para continuar.");

        textbackground(7);

        textcolor(BLUE);

        marco(20,60,9,15,1,"ACERCA DE");

        textcolor(BLUE);

        gotoxy(28,11); cprintf("JUEGO CULEBRA VERCION 1.0");

        gotoxy(25,13); cprintf("AUTOR: RAMIREZ PORFIRIO FREDY.");

        getch();

}

void Ayuda()

{

        gotoxy(3,25); cprintf("Pulse una tecla para continuar.");

        textbackground(7);

        textcolor(BLUE);

        marco(20,60,4,21,1,"AYUDA");

        textcolor(BLUE);

        gotoxy(23,6); cprintf("ESTE JUEGO CONSISTE EN COMER EL MAYOR");

        gotoxy(23,7); cprintf("NUMERO DE MANZANAS POSIBLES, Y NO ");

        gotoxy(23,8); cprintf("TOCAR EL BORDE O ASI MISMO.");

        gotoxy(23,10); cprintf("COTROLES:");

        gotoxy(25,12); cprintf("F. DERECHA   DERECHA.");

        gotoxy(25,13); cprintf("F. IZQUIERDA IZQUIERDA.");

        gotoxy(25,14); cprintf("F. ARRIBA    ARRIBA.");

        gotoxy(25,15); cprintf("F. ABAJO     ABAJO.");

        gotoxy(25,16); cprintf("[ESC]        SUSPENDAR.");

        gotoxy(23,18); cprintf("EN LA PARTE DE ABAJO DE CADA OPCION");

        gotoxy(23,19); cprintf("APARECE UNA SALIDA RAPIDA.");

        getch();

}

void Ejecuta(int x)

{

        switch(x)

        {

                case 1: Juega();    break;

                case 2: Niveles();  break;

                case 3: AcercaDe(); break;

                case 4: Ayuda();break;

        }

}

void OpcionesMenu()

{

        char Opc;

        int X=1;

        do

        {

                Proceso();

                Resalta(X-1);

                Opc=getch();

                switch(Opc)

                {

                        case 77: X++; if(X==6) X=1; break;

                        case 75: X--; if(X==0) X=5; break;

                        case 13: if(X==5) return; Ejecuta(X); break;

                }

        }while(1);

}

int main()

{

        clrscr();

        OpcionesMenu();

        textbackground(7);

        textcolor(BLUE);

        marco(20,60,8,18,1,"FIN");

        textcolor(BLUE);

        gotoxy(25,12); cprintf("Espero que te hayas divertido,");

        gotoxy(25,13); cprintf("hasta la proxima...");

        gotoxy(48,17); cprintf("Att. Fredy.");

        delay(5000);

        return 0;

}

Fuente: Pm



Tags:
Tags:

 


SMF 2.0.19 | SMF © 2016, Simple Machines
Paginas Afiliadas
Twitter - FaceBook - Daraxblog
Designed by Smf Personal