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)


  Mostrar Mensajes
Páginas: [1]
1  Programación / Programación C/C++ / Re: [Capitulo III]Threads. en: 28 Octubre 2010, 15:41 pm
excelente :D, solo que el primer ejemplo cuando lo pongo me tira un error
"undefined reference to `_imp__pthread_create'" en C::B, O:,

Saludos!
2  Programación / Programación C/C++ / Re: Help!! Poblema para Identificar Teclas Presionadas. en: 28 Octubre 2010, 06:03 am
Bueno, ya lo arregle, este e smi nuevo codigo, xdd.

Código
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. #include <conio.h>
  5.  
  6.  
  7. struct cuerpo
  8. {
  9.    char sprite;
  10.    int x, y;
  11. };
  12.  
  13. struct plano
  14. {
  15.    char sprite;
  16.    int x, y;
  17. };
  18.  
  19. struct proy
  20. {
  21.    char sprite;
  22.    int x, y;
  23.    int rango;
  24. };
  25.  
  26.  
  27. int main()
  28. {
  29.    int m, n, i, j, k, l, e=30, b=3;
  30.    char c;
  31.    struct cuerpo nave, player;
  32.    struct proy bala;
  33.    struct plano a[20][20];
  34.  
  35.  
  36.    nave.sprite=1;
  37.    player.sprite=2;
  38.    bala.sprite='`';
  39.    bala.rango=5;
  40.  
  41.    void start()
  42.    {
  43.        for(i=0; i<20; i++)
  44.        {
  45.            for(j=0; j<20; j++)
  46.            {
  47.                a[i][j].sprite=' ';
  48.                a[i][j].x=i;
  49.                a[i][j].y=j;
  50.            }
  51.        }
  52.    }
  53.  
  54.    void pspawn()
  55.    {
  56.        player.x=19;
  57.        player.y=10;
  58.    }
  59.    void bspawn()
  60.    {
  61.        bala.x=player.x-1;
  62.        bala.y=player.y;
  63.    }
  64.  
  65.    void ppos()
  66.    {
  67.        a[player.x][player.y].sprite=player.sprite;
  68.    }
  69.    void bpos()
  70.    {
  71.        a[bala.x][bala.y].sprite=bala.sprite;
  72.    }
  73.    void epos()
  74.    {
  75.        for(l=0; l<20; l++)
  76.        {
  77.            a[0][l].sprite=nave.sprite;
  78.        }
  79.    }
  80.  
  81.    void chkp()
  82.    {
  83.        if(player.x==0)
  84.        {
  85.            m=player.y;
  86.            pspawn();
  87.            b--;
  88.            a[0][m].sprite='X';
  89.        }
  90.    }
  91.    void chke()
  92.    {
  93.        if(bala.x==0)
  94.        {
  95.            m=bala.y;
  96.            bspawn();
  97.            a[0][m].sprite='X';
  98.        }
  99.    }
  100.  
  101.    void disp()
  102.    {
  103.        system("cls");
  104.        for(i=0; i<20; i++)
  105.        {
  106.            for(j=0; j<20; j++)
  107.            {
  108.                if(i==player.x && j==player.y)
  109.                {
  110.                    ppos();
  111.                }
  112.                else if (i==bala.x && j==bala.y)
  113.                {
  114.                    bpos();
  115.                }
  116.                else if (a[i][j].sprite!=nave.sprite && a[i][j].sprite!='X')
  117.                {
  118.                    a[i][j].sprite=' ';
  119.                }
  120.                printf("%c ", a[i][j].sprite);
  121.            }
  122.            printf("\n");
  123.        }
  124.        printf("\nVidas: %i Ammo: %i\n", b, e);
  125.    }
  126.  
  127.    void mov()
  128.    {
  129.        c='1';
  130.        k=0;
  131.        c=getch();
  132.  
  133.        switch(c)
  134.        {
  135.        case 'w':
  136.            if(player.x>0)
  137.                player.x=(player.x)-1;
  138.            break;
  139.  
  140.        case 'd':
  141.            if(player.y<19)
  142.                player.y=(player.y)+1;
  143.            break;
  144.  
  145.        case 's':
  146.            if(player.x<19)
  147.                player.x=(player.x)+1;
  148.            break;
  149.  
  150.        case 'a':
  151.            if(player.y>0)
  152.                player.y=(player.y)-1;
  153.            break;
  154.        case ' ':
  155.            bala.x=player.x-1;
  156.            bala.y=player.y;
  157.            a[bala.x][bala.y].sprite='*';
  158.            while(k<bala.rango)
  159.            {
  160.                bala.x=bala.x-1;
  161.                chke();
  162.                disp();
  163.                k++;
  164.            }
  165.            e--;
  166.            break;
  167.  
  168.        default:
  169.            break;
  170.        }
  171.    }
  172.  
  173.    start();
  174.    epos();
  175.    pspawn();
  176.    disp();
  177.  
  178.    while(b!=0 && e!=0)
  179.    {
  180.        disp();
  181.        mov();
  182.        chkp();
  183.        bspawn();
  184.    }
  185.  
  186.    if(b==0 || e==0)
  187.    {
  188.        system("cls");
  189.        printf("\t\t\tGAME OVER!\n\n");
  190.    }
  191.  
  192.    system("pause");
  193.    return 0;
  194. }
3  Programación / Programación C/C++ / Re: Help!! Poblema para Identificar Teclas Presionadas. en: 27 Octubre 2010, 03:19 am
¡Buenas!

¡¡¡¡Olvida el goto!!!!, haz el programa utilizando programacion estructurada (estructuras de control) y luego lo vuelves a colgar.

¡Saludos!

Gracias, pero sin el goto pasa lo mismo, yo creo que tiene que ver con el teclado, sabes alguna otra forma de identificar si apreto una tecla o no?.

Saludos!
4  Programación / Programación C/C++ / Problema identificar teclas preisonadas (Solucionado) en: 27 Octubre 2010, 01:25 am
Hola, estoy aprendiendo a programar en C y queria hacer un jueguito pero tengo un problema con el movimiento que derrepente se hecha  a perder, le meti fflush por todas partes y ni asi se arreglo, xdd, asi que no he seguido avanzando. Por favor si alguien lo puede revisar y hecharme una manito :).

(Como hago un spoiler?? :D?)


Este es el codigo.

Código
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. #include <conio.h>
  5.  
  6.  
  7. struct nave{
  8.       char sprite;
  9.       int x, y;
  10.       };
  11.  
  12. int main(){
  13.    int i, j, b=3;
  14.    char a[20][20];
  15.    char c;
  16.  
  17. start:
  18. struct nave nave1;
  19.       nave1.sprite=1;
  20.       nave1.x=9;
  21.       nave1.y=9;
  22.  
  23. struct nave nave2;
  24.       nave2.sprite=2;
  25.       nave2.x=3;
  26.       nave2.y=3;
  27.  
  28. while(b!=0){
  29.    for(i=0; i<20;i++){
  30.             for(j=0; j<20; j++){
  31.                      if(i==nave1.y && j==nave1.x && i==nave2.y && j==nave2.x){
  32.                           b--;
  33.                           system("cls");
  34.                           goto start;
  35.                           }
  36.                      else if(i==nave1.y && j==nave1.x){
  37.                                    a[i][j]=nave1.sprite;
  38.                                    }
  39.                      else if(i==nave2.y && j==nave2.x){
  40.                                    a[i][j]=nave2.sprite;
  41.                                    }
  42.  
  43.                      else{
  44.                           a[i][j]=' ';
  45.                           }
  46.  
  47.                            printf("%c ", a[i][j]);
  48.                            }
  49.                            printf("\n");
  50.                            }
  51.                            printf("\nVidas: %i\n", b);
  52.  
  53.  
  54.                           system("pause");           //probe con getch() pero agrava el bug
  55.  
  56.                           if(GetKeyState(38))        //37-40 son las flechitas
  57.                           if(nave1.y>0)
  58.                           nave1.y=nave1.y-1;
  59.  
  60.                           if(GetKeyState(40))
  61.                           if(nave1.y<19)
  62.                           nave1.y=nave1.y+1;
  63.  
  64.                           if(GetKeyState(37))
  65.                           if(nave1.x>0)
  66.                           nave1.x=nave1.x-1;
  67.  
  68.                           if(GetKeyState(39))
  69.                           if(nave1.x<19)
  70.                           nave1.x=nave1.x+1;
  71.  
  72.  
  73.                      system("cls");                    
  74. }
  75. printf("\t\t\tGAME OVER!\n\n");
  76.  
  77. system("pause");
  78. return 0;
  79. }
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines