elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Intento de realizar un juego
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Intento de realizar un juego  (Leído 1,695 veces)
Blaster

Desconectado Desconectado

Mensajes: 190


Ver Perfil
Intento de realizar un juego
« en: 7 Octubre 2012, 15:09 pm »

 Comparto con ustedes este codigo para quien le pueda servir,
lo hice en mis tiempos libres y salio esto ;)

Código
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <windows.h>
  4.  
  5. #define ARRIBA 72
  6. #define IZQUIERDA 75
  7. #define DERECHA 77
  8. #define ABAJO 80
  9. #define ESC 27
  10.  
  11. using namespace std;
  12.  
  13. void mover_izquierda();
  14. void mover_derecha();
  15.  
  16. void juego();
  17.  
  18. char izquierda1[]={' ','0',' ',0};
  19. char izquierda2[]={'0','0','0',0};
  20. char izquierda3[]={'0',' ','0',0};
  21.  
  22. char derecha1[]={' ','0',' ',0};
  23. char derecha2[]={'0','0','0',0};
  24. char derecha3[]={'0',' ','0',0};
  25.  
  26. char tecla;
  27. int x = 0, y = 0;
  28.  
  29. void gotoxy(int x,int y)
  30. {
  31.    HANDLE hCon;
  32.    COORD dwPos;
  33.  
  34.    dwPos.X = x;
  35.    dwPos.Y = y;
  36.    hCon = GetStdHandle(STD_OUTPUT_HANDLE);
  37.    SetConsoleCursorPosition(hCon,dwPos);
  38. }
  39. void juego() {
  40.    x=37;
  41.    y=20;
  42.    do {
  43.       tecla = getch();
  44.       if (tecla == IZQUIERDA || tecla == DERECHA) {
  45.          if (tecla == IZQUIERDA)
  46.           mover_izquierda();
  47.          if (tecla == DERECHA)
  48.           mover_derecha();
  49.        }    
  50.    }while(1);
  51.    cin.get();
  52. }
  53. void mover_izquierda() {
  54.     if (x>=3) {
  55.        x-=3;
  56.        system("cls");
  57.     }
  58.     gotoxy(x,y); puts(izquierda1);
  59.     gotoxy(x,y+1); puts(izquierda2);
  60.     gotoxy(x,y+2); puts(izquierda3);
  61.     gotoxy(0,0);
  62. }
  63. void mover_derecha() {
  64.     if (x<75) {
  65.        x+=3;
  66.        system("cls");
  67.     }
  68.     gotoxy(x,y); puts(derecha1);
  69.     gotoxy(x,y+1); puts(derecha2);
  70.     gotoxy(x,y+2); puts(derecha3);
  71.     gotoxy(0,0);
  72. }
  73. int main() {
  74.    printf("\n\n\t\t\t SPACE INVADERS \n");
  75.    printf("\n\n\n\t\tPRESIONA LAS TECLA <- O -> PARA INICIAR:");
  76.  
  77.    gotoxy(0,0);
  78.    int menu = getch();
  79.    juego();
  80.  
  81.    return 0;
  82. }
  83.  


« Última modificación: 10 Octubre 2012, 21:39 pm por Neo_System » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines