PDA

View Full Version : C Programming Help



DWk
02-07-2004, 01:18 PM
Sup people. Ok, the galaga-type of game is due on monday. However, I'm having some serious trouble :ph34r:

Here's the code


#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>

int x = 37;
int y = 25;
char b;


void ship (int x, int y);
void shoot (int x, int y);
void menu ();
void enemy();
void salida ();


void salida(){
clrscr();
delay(500);
printf("Gracias por jugar\n");
exit(0);
}


void enemy(int x, int y){
gotoxy(x,y);
printf("w0otage");

}

void shoot(int x, int y){
int i=21;
while (i>0){
 int ejex = x;
 gotoxy(ejex+3, i);
 printf("|");
 delay (14);
 i--;

}
ship(x,y);

}

void ship(int x, int y){
clrscr();
gotoxy(x,y);
printf("*-----*");
gotoxy(x,y-1);
printf(" *---* ");
gotoxy(x,y-2);
printf("  *-*  ");
gotoxy(x,y-3);
printf("   *   ");


delay(3000);
enemy(x,y);

b = getch();

switch (b){

 case 'a':
  if(x<=5){
   ship(x,y);
  }else {
   ship(x-7,y);
   }
  break;
 
   
 case 'd':
  if(x>=72){
   ship(x,y);
  }else {
   ship(x+7,y);
   }
  break;
 
 case 's':
  shoot(x,y);
  break;
 
 case 'm':
  menu();
  break;

 case 'z':
  salida();
  break;

 default:
  ship(x,y);
}

}

void menu(){

clrscr();
gotoxy(22,10);
printf("Izquierda   A\n");
gotoxy(22,11);
printf("Disparar   S\n");
gotoxy(22,12);
printf("Derecha    D\n");
gotoxy(22,13);
printf("Menu    M\n");
gotoxy(22,14);
printf("Salir    Z\n");
gotoxy(22,16);
printf("Para empezar a jugar, presione E\n");
gotoxy(22,17);
printf("Para salir, presione Z\n");

b = getch();

switch (b){

 case 'e':
  ship(x,y);
  break;

 case 'z':
  salida();
  break;

 default:
  menu();
   
}

}


void main(){

menu();
}

As the last time, press E to play, A-D for left-right, S for shooting, M for menu, and Z for quitting. I compiled with borlandC 3.1

So here's the problem:
I'm trying to great the enemy ships. However, the problem is that the good ship (whenever it moves), it clears screen


void ship(int x, int y){
clrscr();
gotoxy(x,y);

So if I get the enemy ship to display, it would be erased whenever the ship does something.

Any ideas on this? Please, I'm on a hurry :ph34r: :ghostface:

ObiWan
02-07-2004, 01:59 PM
you are clearing the screen whenever the ship moves

you may want to make it redraw the enemy ships after the god ship has been moved

DWk
02-07-2004, 02:04 PM
Originally posted by ObiWan@7 February 2004 - 06:59
you are clearing the screen whenever the ship moves

you may want to make it redraw the enemy ships after the god ship has been moved
Yeps, that's what I'm thinking. The question is how. Any ideas?

ObiWan
02-07-2004, 02:23 PM
call the draw enemy ship fuction from the ship function

DWk
02-07-2004, 02:36 PM
Originally posted by ObiWan@7 February 2004 - 07:23
call the draw enemy ship fuction from the ship function
Ok I'm gonna try that right now. In the meantime, check what I did -

In this version, I don't use clrscr, but just printf which erases the ship and then re-draws it somewhere


#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>

int x = 37;
int y = 25;
char b;


void ship (int x, int y);
void shoot (int x, int y);
void menu ();
void salida ();
void centership(int x, int y);
void borrar(int x, int y);
void bala(int x, int y);

void salida(){
clrscr();
delay(500);
printf("Gracias por jugar\n");
exit(0);
}

void borrar(int x, int y){
int i=21;
delay(15);
while (i>0){
 int ejex = x;
 gotoxy(ejex+3,i);
 printf(" ");
 delay (7);
 i--;
}
ship(x,y);

}

void bala (int x, int y){
int i=21;
while (i>0){
 int ejex = x;
 gotoxy(ejex+3,i);
 printf("|");
 delay (14);
 i--;

}
borrar(x,y);

}


void shoot(int x, int y){
bala(x,y);
}

void centership(int x, int y){
clrscr();
gotoxy(x,y);
printf("*-----*");
gotoxy(x,y-1);
printf(" *---* ");
gotoxy(x,y-2);
printf("  *-*  ");
gotoxy(x,y-3);
printf("   *   ");
ship(x,y);
}

void ship(int x, int y){

b = getch();

switch (b){

 case 'a':
  if (x<=5){
  }else {
   gotoxy(x,y);
   printf("       ");
   gotoxy(x,y-1);
   printf("       ");
   gotoxy(x,y-2);
   printf("       ");
   gotoxy(x,y-3);
   printf("       ");
   gotoxy(x-7,y);
   printf("*-----*");
   gotoxy(x-7,y-1);
   printf(" *---* ");
   gotoxy(x-7,y-2);
   printf("  *-*  ");
   gotoxy(x-7,y-3);
   printf("   *   ");
   ship(x-7,y);
   break;
  }
   
   
 case 'd':
  if (x>=72){
  }else {
   gotoxy(x,y);
   printf("       ");
   gotoxy(x,y-1);
   printf("       ");
   gotoxy(x,y-2);
   printf("       ");
   gotoxy(x,y-3);
   printf("       ");
   gotoxy(x+7,y);
   printf("*-----*");
   gotoxy(x+7,y-1);
   printf(" *---* ");
   gotoxy(x+7,y-2);
   printf("  *-*  ");
   gotoxy(x+7,y-3);
   printf("   *   ");
   ship(x+7,y);
   break;
  }
 
 case 's':
  shoot(x,y);
  break;
 
 case 'm':
  menu();
  break;

 case 'z':
  salida();
  break;

 default:
  ship(x,y);
}

}

void menu(){

clrscr();
gotoxy(22,10);
printf("Izquierda   A\n");
gotoxy(22,11);
printf("Disparar   S\n");
gotoxy(22,12);
printf("Derecha    D\n");
gotoxy(22,13);
printf("Menu    M\n");
gotoxy(22,14);
printf("Salir    Z\n");
gotoxy(22,16);
printf("Para empezar a jugar, presione E\n");
gotoxy(22,17);
printf("Para salir, presione Z\n");

b = getch();

switch (b){

 case 'e':
  centership(x,y);
  break;

 case 'z':
  salida();
  break;

 default:
  menu();
   
}

}


void main(){

menu();
}


Problem is, when I go to the left end, if I press A again to go left, it goes one space right, and when I go to the right side, if I press D to go right, it shoots :ph34r:

ObiWan
02-07-2004, 03:03 PM
try
case 'a':
if (x<=5){
break;
}else {
gotoxy(x,y);

and

case &#39;d&#39;:
if (x>=72){
break;
}else {
gotoxy(x,y);

DWk
02-07-2004, 03:08 PM
Originally posted by ObiWan@7 February 2004 - 08:03
try
case &#39;a&#39;:
if (x<=5){
break;
}else {
gotoxy(x,y);

and

case &#39;d&#39;:
if (x>=72){
break;
}else {
gotoxy(x,y);
Will do right now....

Bleh forgot to say I tried that. The problem is that if I do that, the game exits :(

ObiWan
02-07-2004, 03:31 PM
ive think ive got it


#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;
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 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 borrar&#40;int x, int y&#41;{
int i=21;
delay&#40;15&#41;;
while &#40;i&#62;0&#41;{
int ejex = x;
gotoxy&#40;ejex+3,i&#41;;
printf&#40;&#34; &#34;&#41;;
delay &#40;7&#41;;
i--;
}
ship&#40;x,y&#41;;

}

void bala &#40;int x, int y&#41;{
int i=21;
while &#40;i&#62;0&#41;{
int ejex = x;
gotoxy&#40;ejex+3,i&#41;;
printf&#40;&#34;|&#34;&#41;;
delay &#40;14&#41;;
i--;

}
borrar&#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;;
}

void ship&#40;int x, int y&#41;{

b = getch&#40;&#41;;

switch &#40;b&#41;{

case &#39;a&#39;&#58;
&nbsp;if &#40;x&#60;=5&#41;{
&nbsp;ship&#40;x,y&#41;;
&nbsp;break;
&nbsp;}else {
&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;;
&nbsp; gotoxy&#40;x-7,y&#41;;
&nbsp; printf&#40;&#34;*-----*&#34;&#41;;
&nbsp; gotoxy&#40;x-7,y-1&#41;;
&nbsp; printf&#40;&#34; *---* &#34;&#41;;
&nbsp; gotoxy&#40;x-7,y-2&#41;;
&nbsp; printf&#40;&#34; &nbsp;*-* &nbsp;&#34;&#41;;
&nbsp; gotoxy&#40;x-7,y-3&#41;;
&nbsp; printf&#40;&#34; &nbsp; * &nbsp; &#34;&#41;;
&nbsp; ship&#40;x-7,y&#41;;
&nbsp; break;
&nbsp;}


case &#39;d&#39;&#58;
&nbsp;if &#40;x&#62;=72&#41;{
&nbsp;ship&#40;x,y&#41;;
&nbsp;break;
&nbsp;}else {
&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;;
&nbsp; gotoxy&#40;x+7,y&#41;;
&nbsp; printf&#40;&#34;*-----*&#34;&#41;;
&nbsp; gotoxy&#40;x+7,y-1&#41;;
&nbsp; printf&#40;&#34; *---* &#34;&#41;;
&nbsp; gotoxy&#40;x+7,y-2&#41;;
&nbsp; printf&#40;&#34; &nbsp;*-* &nbsp;&#34;&#41;;
&nbsp; gotoxy&#40;x+7,y-3&#41;;
&nbsp; printf&#40;&#34; &nbsp; * &nbsp; &#34;&#41;;
&nbsp; ship&#40;x+7,y&#41;;
&nbsp; break;
&nbsp;}

case &#39;s&#39;&#58;
&nbsp;shoot&#40;x,y&#41;;
&nbsp;break;

case &#39;m&#39;&#58;
&nbsp;menu&#40;&#41;;
&nbsp;break;

case &#39;z&#39;&#58;
&nbsp;salida&#40;&#41;;
&nbsp;break;

default&#58;
&nbsp;ship&#40;x,y&#41;;
}

}

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;{

case &#39;e&#39;&#58;
&nbsp;centership&#40;x,y&#41;;
&nbsp;break;

case &#39;z&#39;&#58;
&nbsp;salida&#40;&#41;;
&nbsp;break;

default&#58;
&nbsp;menu&#40;&#41;;
&nbsp; &nbsp;
}

}


void main&#40;&#41;{

menu&#40;&#41;;
}

its
case &#39;a&#39;:
if (x<=5){
ship(x,y);
break;
}else {
gotoxy(x,y);

DWk
02-07-2004, 03:58 PM
L33t. Hehe, that works :)

Thanks B)

DWk
02-07-2004, 05:55 PM
Ok, modified the code again:


#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;
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 salida&#40;&#41;{
&nbsp;clrscr&#40;&#41;;
&nbsp;delay&#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;delay&#40;15&#41;;
&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;7&#41;;
&nbsp; &nbsp;i--;
&nbsp;}
&nbsp;ship&#40;x,y&#41;;

}

void 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;delay &#40;14&#41;;
&nbsp; &nbsp;i--;
&nbsp;
&nbsp;}
&nbsp;borrar_bala&#40;x,y&#41;;
&nbsp;
}


void shoot&#40;int x, int y&#41;{
&nbsp;bala&#40;x,y&#41;;
}

void centership&#40;int x, int y&#41;{
&nbsp;clrscr&#40;&#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;;
&nbsp;ship&#40;x,y&#41;;
}

void ship&#40;int x, int y&#41;{

&nbsp;b = getch&#40;&#41;;

&nbsp;switch &#40;b&#41;{

&nbsp; &nbsp;case &#39;a&#39;&#58;
&nbsp; &nbsp; &nbsp;if &#40;x&#62;5&#41;{
&nbsp; &nbsp; &nbsp; &nbsp;erase_ship&#40;x,y&#41;;
&nbsp; &nbsp; &nbsp; &nbsp;x -= 7;
&nbsp; &nbsp; &nbsp; &nbsp;draw_ship&#40;x,y&#41;;
&nbsp; &nbsp; &nbsp;}
&nbsp; &nbsp; &nbsp;break;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;case &#39;d&#39;&#58;
&nbsp; &nbsp; &nbsp;if &#40;x&#60;72&#41;{
&nbsp; &nbsp; &nbsp; &nbsp;erase_ship&#40;x,y&#41;;
&nbsp; &nbsp; &nbsp; &nbsp;x += 7;
&nbsp; &nbsp; &nbsp; &nbsp;draw_ship&#40;x,y&#41;;
&nbsp; &nbsp; &nbsp;}
&nbsp; &nbsp; &nbsp;break;
&nbsp; &nbsp;
&nbsp; &nbsp;case &#39;s&#39;&#58;
&nbsp; &nbsp; &nbsp;shoot&#40;x,y&#41;;
&nbsp; &nbsp; &nbsp;break;
&nbsp; &nbsp;
&nbsp; &nbsp;case &#39;m&#39;&#58;
&nbsp; &nbsp; &nbsp;menu&#40;&#41;;
&nbsp; &nbsp; &nbsp;break;

&nbsp; &nbsp;case &#39;z&#39;&#58;
&nbsp; &nbsp; &nbsp;salida&#40;&#41;;
&nbsp; &nbsp; &nbsp;break;

&nbsp; &nbsp;default&#58;
&nbsp; &nbsp; &nbsp;ship&#40;x,y&#41;;
&nbsp;}
&nbsp;
}

void menu&#40;&#41;{

&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;centership&#40;x,y&#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;}

}


void main&#40;&#41;{

&nbsp;menu&#40;&#41;;
}

Does the same thing, but got rid of the clrscr. Any ideas for the enemies?

ObiWan
02-07-2004, 09:21 PM
case &#39;a&#39;:
if (x>5){
erase_ship(x,y);
x -= 7;
draw_ship(x,y);
}
ship(x,y);
break;


case &#39;d&#39;:
if (x<72){
erase_ship(x,y);
x += 7;
draw_ship(x,y);
}
ship(x,y);
break;

DWk
02-08-2004, 02:48 AM
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.


#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;;
}

tree_for
02-08-2004, 09:51 AM
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

ObiWan
02-08-2004, 03:54 PM
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

DWk
02-08-2004, 04:44 PM
Check this out B)


#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 :)

ObiWan
02-08-2004, 04:53 PM
looking good

ObiWan
02-08-2004, 09:17 PM
the ship can now be hit

#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;
}