Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: C Programming Help

  1. #11
    case 'a':
    if (x>5){
    erase_ship(x,y);
    x -= 7;
    draw_ship(x,y);
    }
    ship(x,y);
    break;


    case 'd':
    if (x<72){
    erase_ship(x,y);
    x += 7;
    draw_ship(x,y);
    }
    ship(x,y);
    break;
    There are 10 types of people in the world those who understand binary and those who dont

  2. Software & Hardware   -   #12
    BANNED
    Join Date
    Jul 2003
    Location
    Guatemala
    Posts
    4,044
    Anyways - I think I got all the errors fixed:

    The only problem is that I can&#39;t move/shoot while the ship on the left scrolls down.

    Code:
    #include &#60;stdio.h&#62;
    #include &#60;conio.h&#62;
    #include &#60;stdlib.h&#62;
    #include &#60;dos.h&#62;
    
    int x = 37;
    int y = 25;
    int posex = 5;
    int posey = 1;
    char b;
    
    
    void ship &#40;int x, int y&#41;;
    void shoot &#40;int x, int y&#41;;
    void menu &#40;&#41;;
    void salida &#40;&#41;;
    void centership&#40;int x, int y&#41;;
    void borrar&#40;int x, int y&#41;;
    void bala&#40;int x, int y&#41;;
    void draw_ship&#40;int x, int y&#41;;
    void erase_ship&#40;int x, int y&#41;;
    void draw_enemy&#40;int x, int y&#41;;
    void erase_tail&#40;int x, int y&#41;;
    void scroll &#40;int x, int y&#41;;
    
    
    void erase_tail&#40;int x, int y&#41;{
    	delay&#40;200&#41;;
    	gotoxy&#40;x,y&#41;;
    	printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
    }
    
    void draw_enemy&#40;int x, int y&#41;{
    	gotoxy&#40;x,y&#41;;
    	printf&#40;&#34;VvvvvvV&#34;&#41;;
    	gotoxy&#40;x,y+1&#41;;
    	printf&#40;&#34; VvvvV &#34;&#41;;
    	gotoxy&#40;x,y+2&#41;;
    	printf&#40;&#34; &nbsp;VvV &nbsp;&#34;&#41;;
    	gotoxy&#40;x,y+3&#41;;
    	printf&#40;&#34; &nbsp; V &nbsp; &#34;&#41;;
    
    }
    
    void scroll&#40;int x, int y&#41;{
    	int i = 2;
    	while &#40;i&#60;23&#41;{
     &nbsp;draw_enemy&#40;x,i&#41;; &nbsp;
     &nbsp;erase_tail&#40;x,i&#41;;
     &nbsp;i++;
    	}
    	
    
    }
    
    void salida&#40;&#41;{
    	clrscr&#40;&#41;;
    	delay&#40;500&#41;;
    	printf&#40;&#34;Gracias por jugar&#092;n&#34;&#41;;
    	exit&#40;0&#41;;
    }
    
    void erase_ship&#40;int x, int y&#41;{
     &nbsp; gotoxy&#40;x,y&#41;;
     &nbsp; printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
     &nbsp; gotoxy&#40;x,y-1&#41;;
     &nbsp; printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
     &nbsp; gotoxy&#40;x,y-2&#41;;
     &nbsp; printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
     &nbsp; gotoxy&#40;x,y-3&#41;;
     &nbsp; printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
    }
    
    void draw_ship&#40;int x, int y&#41;{
     &nbsp; gotoxy&#40;x,y&#41;;
     &nbsp; printf&#40;&#34;*-----*&#34;&#41;;
     &nbsp; gotoxy&#40;x,y-1&#41;;
     &nbsp; printf&#40;&#34; *---* &#34;&#41;;
     &nbsp; gotoxy&#40;x,y-2&#41;;
     &nbsp; printf&#40;&#34; &nbsp;*-* &nbsp;&#34;&#41;;
     &nbsp; gotoxy&#40;x,y-3&#41;;
     &nbsp; printf&#40;&#34; &nbsp; * &nbsp; &#34;&#41;;
    }
    
    void borrar_bala&#40;int x, int y&#41;{
    	int i=21;
    	delay&#40;15&#41;;
    	while &#40;i&#62;0&#41;{
     &nbsp;int ejex = x;
     &nbsp;gotoxy&#40;ejex+3,i&#41;;
     &nbsp;printf&#40;&#34; &#34;&#41;;
     &nbsp;delay &#40;7&#41;;
     &nbsp;i--;
    	}
    	ship&#40;x,y&#41;;
    
    }
    
    void bala &#40;int x, int y&#41;{
    	int i=21;
    	while &#40;i&#62;0&#41;{
     &nbsp;int ejex = x;
     &nbsp;gotoxy&#40;ejex+3,i&#41;;
     &nbsp;printf&#40;&#34;|&#34;&#41;;
     &nbsp;delay &#40;14&#41;;
     &nbsp;i--;
    	
    	}
    	borrar_bala&#40;x,y&#41;;
    	
    }
    
    
    void shoot&#40;int x, int y&#41;{
    	bala&#40;x,y&#41;;
    }
    
    void centership&#40;int x, int y&#41;{
    	clrscr&#40;&#41;;
    	gotoxy&#40;x,y&#41;;
    	printf&#40;&#34;*-----*&#34;&#41;;
    	gotoxy&#40;x,y-1&#41;;
    	printf&#40;&#34; *---* &#34;&#41;;
    	gotoxy&#40;x,y-2&#41;;
    	printf&#40;&#34; &nbsp;*-* &nbsp;&#34;&#41;;
    	gotoxy&#40;x,y-3&#41;;
    	printf&#40;&#34; &nbsp; * &nbsp; &#34;&#41;;
    	ship&#40;x,y&#41;;
    	delay&#40;500&#41;;
    	scroll&#40;posex,posey&#41;;
    }
    
    void ship&#40;int x, int y&#41;{
    
    	int exit_loop = 0;
    	do{
     &nbsp; &nbsp; &nbsp;if&#40;kbhit&#40;&#41; == 0&#41;{
     &nbsp;	b = getch&#40;&#41;;
     &nbsp;	switch&#40;b&#41;{
     &nbsp;	
     &nbsp; &nbsp;case &#39;a&#39;&#58;
     &nbsp; &nbsp;	if &#40;x&#62;5&#41;{
     &nbsp; &nbsp; &nbsp;erase_ship&#40;x,y&#41;;
     &nbsp; &nbsp; &nbsp;x -= 7;
     &nbsp; &nbsp; &nbsp;draw_ship&#40;x,y&#41;;
     &nbsp; &nbsp;	}
     &nbsp; &nbsp;	break;
     &nbsp; &nbsp; &nbsp;	
     &nbsp; &nbsp;case &#39;d&#39;&#58;
     &nbsp; &nbsp;	if &#40;x&#60;72&#41;{
     &nbsp; &nbsp; &nbsp;erase_ship&#40;x,y&#41;;
     &nbsp; &nbsp; &nbsp;x += 7;
     &nbsp; &nbsp; &nbsp;draw_ship&#40;x,y&#41;;
     &nbsp; &nbsp;	}
     &nbsp; &nbsp;	break;
     &nbsp;	
     &nbsp; &nbsp;case &#39;s&#39;&#58;
     &nbsp; &nbsp;	shoot&#40;x,y&#41;;
     &nbsp; &nbsp;	break;
     &nbsp; &nbsp;
     &nbsp; &nbsp;case &#39;m&#39;&#58;
     &nbsp; &nbsp;	menu&#40;&#41;;
     &nbsp; &nbsp;	break;
     &nbsp;
     &nbsp; &nbsp;case &#39;z&#39;&#58;
     &nbsp; &nbsp;	salida&#40;&#41;;
     &nbsp; &nbsp;	break;
    	
     &nbsp; &nbsp;default&#58;
     &nbsp; &nbsp;	ship&#40;x,y&#41;; &nbsp; &nbsp;
     &nbsp;	}
     &nbsp;
     &nbsp;}
    	}while&#40;exit_loop &#33;= 0&#41;;
     &nbsp;
    }
    
    void menu&#40;&#41;{
    
    	clrscr&#40;&#41;;
    	gotoxy&#40;22,10&#41;;
    	printf&#40;&#34;Izquierda &nbsp;	A&#092;n&#34;&#41;;
    	gotoxy&#40;22,11&#41;;
    	printf&#40;&#34;Disparar &nbsp;	S&#092;n&#34;&#41;;
    	gotoxy&#40;22,12&#41;;
    	printf&#40;&#34;Derecha &nbsp; &nbsp;D&#092;n&#34;&#41;;
    	gotoxy&#40;22,13&#41;;
    	printf&#40;&#34;Menu &nbsp; &nbsp;M&#092;n&#34;&#41;;
    	gotoxy&#40;22,14&#41;;
    	printf&#40;&#34;Salir &nbsp; &nbsp;Z&#092;n&#34;&#41;;
    	gotoxy&#40;22,16&#41;;
    	printf&#40;&#34;Para empezar a jugar, presione E&#092;n&#34;&#41;;
    	gotoxy&#40;22,17&#41;;
    	printf&#40;&#34;Para salir, presione Z&#092;n&#34;&#41;;
    
    	b = getch&#40;&#41;;
    
    	switch &#40;b&#41;{
    
     &nbsp;case &#39;e&#39;&#58;
     &nbsp;	centership&#40;x,y&#41;;
     &nbsp;	break;
    	
     &nbsp;case &#39;z&#39;&#58;
     &nbsp;	salida&#40;&#41;;
     &nbsp;	break;
    
     &nbsp;default&#58;
     &nbsp;	menu&#40;&#41;;
     &nbsp; &nbsp;	
    	}
    
    }
    
    
    void main&#40;&#41;{
    
    	menu&#40;&#41;;
    }

  3. Software & Hardware   -   #13
    Poster BT Rep: +3
    Join Date
    Feb 2003
    Posts
    340
    when I compiled ur code it throws out a error saying that gotoxy was declared, and another one saying that clear screen commmand was not declared....
    I complied it using VC++ 6.0

  4. Software & Hardware   -   #14
    clrscr is only availabe in borland c++

    and i think gotoxy is a reserved variable in VC++

    I compiled it in borland turbo c++ and it compiled fine
    There are 10 types of people in the world those who understand binary and those who dont

  5. Software & Hardware   -   #15
    BANNED
    Join Date
    Jul 2003
    Location
    Guatemala
    Posts
    4,044
    Check this out B)

    Code:
    #include &#60;stdio.h&#62;
    #include &#60;conio.h&#62;
    #include &#60;stdlib.h&#62;
    #include &#60;dos.h&#62;
    #include &#60;time.h&#62;
    
    #define ENEMY_WAIT 1
    
    void shoot &#40;int x, int y&#41;;
    void menu &#40;&#41;;
    void salida &#40;&#41;;
    void draw_ship&#40;int x, int y&#41;;
    void erase_ship&#40;int x, int y&#41;;
    void draw_enemy&#40;int x, int y&#41;;
    void erase_enemy&#40;int x, int y&#41;;
    void scroll &#40;int x, int y&#41;;
    
    
    void erase_enemy&#40;int x, int y&#41;{
     &nbsp;//delay&#40;200&#41;;
     &nbsp;int index;
     &nbsp;
    	for&#40;index=0;index&#60;4;index++&#41;{
     &nbsp;gotoxy&#40;x,y+index&#41;;
     &nbsp;printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
    	}
    }
    
    void draw_enemy&#40;int x, int y&#41;{
     &nbsp;gotoxy&#40;x,y&#41;;
     &nbsp;printf&#40;&#34;VvvvvvV&#34;&#41;;
     &nbsp;gotoxy&#40;x,y+1&#41;;
     &nbsp;printf&#40;&#34; VvvvV &#34;&#41;;
     &nbsp;gotoxy&#40;x,y+2&#41;;
     &nbsp;printf&#40;&#34; &nbsp;VvV &nbsp;&#34;&#41;;
     &nbsp;gotoxy&#40;x,y+3&#41;;
     &nbsp;printf&#40;&#34; &nbsp; V &nbsp; &#34;&#41;;
    
    }
    
    
    void salida&#40;&#41;{
     &nbsp;clrscr&#40;&#41;;
     &nbsp;//sleep&#40;500&#41;;
     &nbsp;printf&#40;&#34;Gracias por jugar&#092;n&#34;&#41;;
     &nbsp;exit&#40;0&#41;;
    }
    
    void erase_ship&#40;int x, int y&#41;{
     &nbsp; gotoxy&#40;x,y&#41;;
     &nbsp; printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
     &nbsp; gotoxy&#40;x,y-1&#41;;
     &nbsp; printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
     &nbsp; gotoxy&#40;x,y-2&#41;;
     &nbsp; printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
     &nbsp; gotoxy&#40;x,y-3&#41;;
     &nbsp; printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
    }
    
    void draw_ship&#40;int x, int y&#41;{
     &nbsp; gotoxy&#40;x,y&#41;;
     &nbsp; printf&#40;&#34;*-----*&#34;&#41;;
     &nbsp; gotoxy&#40;x,y-1&#41;;
     &nbsp; printf&#40;&#34; *---* &#34;&#41;;
     &nbsp; gotoxy&#40;x,y-2&#41;;
     &nbsp; printf&#40;&#34; &nbsp;*-* &nbsp;&#34;&#41;;
     &nbsp; gotoxy&#40;x,y-3&#41;;
     &nbsp; printf&#40;&#34; &nbsp; * &nbsp; &#34;&#41;;
    }
    
    void borrar_bala&#40;int x, int y&#41;{
     &nbsp;int i=21;
     &nbsp;while &#40;i&#62;0&#41;{
     &nbsp; &nbsp;int ejex = x;
     &nbsp; &nbsp;gotoxy&#40;ejex+3,i&#41;;
     &nbsp; &nbsp;printf&#40;&#34; &#34;&#41;;
     &nbsp; &nbsp;i--;
     &nbsp;}
    
    }
    
    void shoot&#40;int x, int y&#41;{
     &nbsp;int i=21;
     &nbsp;while &#40;i&#62;0&#41;{
     &nbsp; &nbsp;int ejex = x;
     &nbsp; &nbsp;gotoxy&#40;ejex+3,i&#41;;
     &nbsp; &nbsp;printf&#40;&#34;|&#34;&#41;;
     &nbsp; &nbsp;delay &#40;5&#41;;
     &nbsp; &nbsp;i--;
     &nbsp;
     &nbsp;}
     &nbsp;borrar_bala&#40;x,y&#41;;
     &nbsp;
    }
    
    void game_loop&#40;&#41;{
    
     &nbsp;int exit_loop = 0;
     &nbsp;int x = 35;
     &nbsp;int y = 25;
     &nbsp;int posex;
     &nbsp;int posey = 1;
     &nbsp;char b;
     &nbsp;time_t set_time;
     &nbsp;time_t check_time;
     &nbsp;
     &nbsp;time&#40;&set_time&#41;;
     &nbsp;srand&#40;&#40;int&#41; set_time&#41;;
     &nbsp;posex = &#40; &#40;rand&#40;&#41;%10&#41; + 1 &#41; * 7;
     &nbsp;clrscr&#40;&#41;;
     &nbsp;draw_ship&#40;x,y&#41;;
     &nbsp; &nbsp;
    	do{
     &nbsp; &nbsp;if&#40;kbhit&#40;&#41;&#41;{
     &nbsp; &nbsp; &nbsp;b = getch&#40;&#41;;
     &nbsp; &nbsp; &nbsp;switch&#40;b&#41;{
     &nbsp; &nbsp; &nbsp;
     &nbsp; &nbsp; &nbsp; &nbsp;case &#39;a&#39;&#58;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if &#40;x&#62;7&#41;{
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;erase_ship&#40;x,y&#41;;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x-=7;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;draw_ship&#40;x,y&#41;;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
     &nbsp; &nbsp; &nbsp; &nbsp;case &#39;d&#39;&#58;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if &#40;x&#60;70&#41;{
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;erase_ship&#40;x,y&#41;;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x+=7;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;draw_ship&#40;x,y&#41;;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;
     &nbsp; &nbsp; &nbsp;
     &nbsp; &nbsp; &nbsp; &nbsp;case &#39;s&#39;&#58;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;shoot&#40;x,y&#41;;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;
     &nbsp; &nbsp; &nbsp; &nbsp;
     &nbsp; &nbsp; &nbsp; &nbsp;case &#39;m&#39;&#58;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;menu&#40;&#41;;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;
     &nbsp; &nbsp;
     &nbsp; &nbsp; &nbsp; &nbsp;case &#39;z&#39;&#58;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;salida&#40;&#41;;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;
     &nbsp;
     &nbsp; &nbsp; &nbsp; &nbsp;//default&#58;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//ship&#40;x,y&#41;; &nbsp; &nbsp;
     &nbsp;	}
     &nbsp;}
     &nbsp; &nbsp;time&#40;&check_time&#41;;
     &nbsp; &nbsp;if&#40; &#40;check_time-set_time&#41; &#62;= ENEMY_WAIT&#41;{
     &nbsp; &nbsp; &nbsp;set_time = check_time;
     &nbsp; &nbsp; &nbsp;erase_enemy&#40;posex,posey&#41;;
     &nbsp; &nbsp; &nbsp;posey+=4;
     &nbsp; &nbsp; &nbsp;if&#40;posey &#60;= 20&#41;
     &nbsp; &nbsp; &nbsp;	draw_enemy&#40;posex,posey&#41;;
     &nbsp; &nbsp;else{
     &nbsp; &nbsp; &nbsp;posey = 1;
     &nbsp; &nbsp; &nbsp;posex = &#40; &#40;rand&#40;&#41;%10&#41; + 1 &#41; * 7;
     &nbsp; &nbsp;}
     &nbsp; &nbsp;} &nbsp; &nbsp;
     &nbsp;}while&#40;&#33;exit_loop&#41;;
     &nbsp; &nbsp;
    }
    
    void menu&#40;&#41;{
    
    	char b;
    	
     &nbsp;clrscr&#40;&#41;;
     &nbsp;gotoxy&#40;22,10&#41;;
     &nbsp;printf&#40;&#34;Izquierda &nbsp; &nbsp; &nbsp;A&#092;n&#34;&#41;;
     &nbsp;gotoxy&#40;22,11&#41;;
     &nbsp;printf&#40;&#34;Disparar &nbsp; &nbsp; &nbsp;S&#092;n&#34;&#41;;
     &nbsp;gotoxy&#40;22,12&#41;;
     &nbsp;printf&#40;&#34;Derecha &nbsp; &nbsp; &nbsp; &nbsp;D&#092;n&#34;&#41;;
     &nbsp;gotoxy&#40;22,13&#41;;
     &nbsp;printf&#40;&#34;Menu &nbsp; &nbsp; &nbsp; &nbsp;M&#092;n&#34;&#41;;
     &nbsp;gotoxy&#40;22,14&#41;;
     &nbsp;printf&#40;&#34;Salir &nbsp; &nbsp; &nbsp; &nbsp;Z&#092;n&#34;&#41;;
     &nbsp;gotoxy&#40;22,16&#41;;
     &nbsp;printf&#40;&#34;Para empezar a jugar, presione E&#092;n&#34;&#41;;
     &nbsp;gotoxy&#40;22,17&#41;;
     &nbsp;printf&#40;&#34;Para salir, presione Z&#092;n&#34;&#41;;
    
     &nbsp;b = getch&#40;&#41;;
    
     &nbsp;switch &#40;b&#41;{
    
     &nbsp; &nbsp;case &#39;e&#39;&#58;
     &nbsp; &nbsp; &nbsp;game_loop&#40;&#41;;
     &nbsp; &nbsp; &nbsp;break;
     &nbsp;
     &nbsp; &nbsp;case &#39;z&#39;&#58;
     &nbsp; &nbsp; &nbsp;salida&#40;&#41;;
     &nbsp; &nbsp; &nbsp;break;
    
     &nbsp; &nbsp;default&#58;
     &nbsp; &nbsp; &nbsp;menu&#40;&#41;;
     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
     &nbsp;}
    
    }
    
    
    int main&#40;&#41;{
    
     &nbsp;menu&#40;&#41;;
    }
    So far so good. 80% Done

  6. Software & Hardware   -   #16
    looking good
    There are 10 types of people in the world those who understand binary and those who dont

  7. Software & Hardware   -   #17
    the ship can now be hit
    Code:
    #include &#60;stdio.h&#62;
    #include &#60;conio.h&#62;
    #include &#60;stdlib.h&#62;
    #include &#60;dos.h&#62;
    #include &#60;time.h&#62;
    
    #define ENEMY_WAIT 1
    int hit;
    int hity;
    int posey = 1;
    
    void shoot &#40;int x, int y&#41;;
    void menu &#40;&#41;;
    void salida &#40;&#41;;
    void draw_ship&#40;int x, int y&#41;;
    void erase_ship&#40;int x, int y&#41;;
    void draw_enemy&#40;int x, int y&#41;;
    void erase_enemy&#40;int x, int y&#41;;
    void scroll &#40;int x, int y&#41;;
    
    
    void erase_enemy&#40;int x, int y&#41;{
     //delay&#40;200&#41;;
     int index;
    
    for&#40;index=0;index&#60;4;index++&#41;{
     gotoxy&#40;x,y+index&#41;;
     printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
    }
    }
    
    void draw_enemy&#40;int x, int y&#41;{
     gotoxy&#40;x,y&#41;;
     &nbsp;hit = x;
     &nbsp;hity = y;
     printf&#40;&#34;VvvvvvV&#34;&#41;;
     gotoxy&#40;x,y+1&#41;;
     printf&#40;&#34; VvvvV &#34;&#41;;
     gotoxy&#40;x,y+2&#41;;
     printf&#40;&#34; &nbsp;VvV &nbsp;&#34;&#41;;
     gotoxy&#40;x,y+3&#41;;
     printf&#40;&#34; &nbsp; V &nbsp; &#34;&#41;;
    
    }
    
    
    void salida&#40;&#41;{
     clrscr&#40;&#41;;
     //sleep&#40;500&#41;;
     printf&#40;&#34;Gracias por jugar&#092;n&#34;&#41;;
     exit&#40;0&#41;;
    }
    
    void erase_ship&#40;int x, int y&#41;{
     &nbsp;gotoxy&#40;x,y&#41;;
     &nbsp;printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
     &nbsp;gotoxy&#40;x,y-1&#41;;
     &nbsp;printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
     &nbsp;gotoxy&#40;x,y-2&#41;;
     &nbsp;printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
     &nbsp;gotoxy&#40;x,y-3&#41;;
     &nbsp;printf&#40;&#34; &nbsp; &nbsp; &nbsp; &#34;&#41;;
    }
    
    void draw_ship&#40;int x, int y&#41;{
     &nbsp;gotoxy&#40;x,y&#41;;
     &nbsp;printf&#40;&#34;*-----*&#34;&#41;;
     &nbsp;gotoxy&#40;x,y-1&#41;;
     &nbsp;printf&#40;&#34; *---* &#34;&#41;;
     &nbsp;gotoxy&#40;x,y-2&#41;;
     &nbsp;printf&#40;&#34; &nbsp;*-* &nbsp;&#34;&#41;;
     &nbsp;gotoxy&#40;x,y-3&#41;;
     &nbsp;printf&#40;&#34; &nbsp; * &nbsp; &#34;&#41;;
    }
    
    void borrar_bala&#40;int x, int y&#41;{
     int i=21;
     while &#40;i&#62;0&#41;{
     &nbsp; int ejex = x;
     &nbsp; gotoxy&#40;ejex+3,i&#41;;
     &nbsp; printf&#40;&#34; &#34;&#41;;
     &nbsp; i--;
     }
    
    }
    
    void shoot&#40;int x, int y&#41;{
     int i=21;
     while &#40;i&#62;0&#41;{
     &nbsp; int ejex = x;
     &nbsp; gotoxy&#40;ejex+3,i&#41;;
     &nbsp; printf&#40;&#34;|&#34;&#41;;
     &nbsp; delay &#40;5&#41;;
     &nbsp; i--;
    
     }
     if &#40;x==hit&#41;{
    erase_enemy&#40;x,hity&#41;;
    posey=18;
    }
     borrar_bala&#40;x,y&#41;;
    
    }
    
    void game_loop&#40;&#41;{
    
     int exit_loop = 0;
     int x = 35;
     int y = 25;
     int posex;
    
     char b;
     time_t set_time;
     time_t check_time;
    
     time&#40;&set_time&#41;;
     srand&#40;&#40;int&#41; set_time&#41;;
     posex = &#40; &#40;rand&#40;&#41;%10&#41; + 1 &#41; * 7;
     clrscr&#40;&#41;;
     draw_ship&#40;x,y&#41;;
    
    do{
     &nbsp; if&#40;kbhit&#40;&#41;&#41;{
     &nbsp; &nbsp; b = getch&#40;&#41;;
     &nbsp; &nbsp; switch&#40;b&#41;{
    
     &nbsp; &nbsp; &nbsp; case &#39;a&#39;&#58;
     &nbsp;if &#40;x&#62;7&#41;{
     &nbsp; &nbsp;erase_ship&#40;x,y&#41;;
     &nbsp; &nbsp;x-=7;
     &nbsp; &nbsp;draw_ship&#40;x,y&#41;;
     &nbsp;}
     &nbsp;break;
    
     &nbsp; &nbsp; &nbsp; case &#39;d&#39;&#58;
     &nbsp;if &#40;x&#60;70&#41;{
     &nbsp; &nbsp;erase_ship&#40;x,y&#41;;
     &nbsp; &nbsp;x+=7;
     &nbsp; &nbsp;draw_ship&#40;x,y&#41;;
     &nbsp;}
     &nbsp;break;
    
     &nbsp; &nbsp; &nbsp; case &#39;s&#39;&#58;
     &nbsp;shoot&#40;x,y&#41;;
     &nbsp;break;
    
     &nbsp; &nbsp; &nbsp; case &#39;m&#39;&#58;
     &nbsp;menu&#40;&#41;;
     &nbsp;break;
    
     &nbsp; &nbsp; &nbsp; case &#39;z&#39;&#58;
     &nbsp;salida&#40;&#41;;
     &nbsp;break;
    
     &nbsp; &nbsp; &nbsp; //default&#58;
     &nbsp;//ship&#40;x,y&#41;;
     &nbsp;}
     }
     &nbsp; time&#40;&check_time&#41;;
     &nbsp; if&#40; &#40;check_time-set_time&#41; &#62;= ENEMY_WAIT&#41;{
     &nbsp; &nbsp; set_time = check_time;
     &nbsp; &nbsp; erase_enemy&#40;posex,posey&#41;;
     &nbsp; &nbsp; posey+=4;
     &nbsp; &nbsp; if&#40;posey &#60;= 20&#41;
     &nbsp; &nbsp; &nbsp;draw_enemy&#40;posex,posey&#41;;
     &nbsp; else{
     &nbsp; &nbsp; posey = 1;
     &nbsp; &nbsp; posex = &#40; &#40;rand&#40;&#41;%10&#41; + 1 &#41; * 7;
     &nbsp; }
     &nbsp; }
     }while&#40;&#33;exit_loop&#41;;
    
    }
    
    void menu&#40;&#41;{
    
    char b;
    
     clrscr&#40;&#41;;
     gotoxy&#40;22,10&#41;;
     printf&#40;&#34;Izquierda&#092;tA&#092;n&#34;&#41;;
     gotoxy&#40;22,11&#41;;
     printf&#40;&#34;Disparar&#092;tS&#092;n&#34;&#41;;
     gotoxy&#40;22,12&#41;;
     printf&#40;&#34;Derecha&#092;t&#092;tD&#092;n&#34;&#41;;
     gotoxy&#40;22,13&#41;;
     printf&#40;&#34;Menu&#092;t&#092;tM&#092;n&#34;&#41;;
     gotoxy&#40;22,14&#41;;
     printf&#40;&#34;Salir&#092;t&#092;tZ&#092;n&#34;&#41;;
     gotoxy&#40;22,16&#41;;
     printf&#40;&#34;Para empezar a jugar, presione E&#092;n&#34;&#41;;
     gotoxy&#40;22,17&#41;;
     printf&#40;&#34;Para salir, presione Z&#092;n&#34;&#41;;
    
     b = getch&#40;&#41;;
    
     switch &#40;b&#41;{
    
     &nbsp; case &#39;e&#39;&#58;
     &nbsp; &nbsp; game_loop&#40;&#41;;
     &nbsp; &nbsp; break;
    
     &nbsp; case &#39;z&#39;&#58;
     &nbsp; &nbsp; salida&#40;&#41;;
     &nbsp; &nbsp; break;
    
     &nbsp; default&#58;
     &nbsp; &nbsp; menu&#40;&#41;;
    
     }
    
    }
    
    
    int main&#40;&#41;{
    
     menu&#40;&#41;;
     return 0;
    }
    There are 10 types of people in the world those who understand binary and those who dont

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •