DWk
01-26-2004, 01:59 AM
Hey what up. Well if you didn't read before, I'm learning C right now (and should have learned it in 1 week lol). Anyways, the only C project the teachers are leaving is either making a Galaga-type of game or a text editor. I went for the game, since it looks easier (specially since the text editor has to be a notepad wannabe).
Here's my code for the game
#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 salida(){
clrscr();
delay(1000);
printf("Gracias por jugar\n");
exit(0);
}
void shoot(int x, int y){
int i=21;
while (i>0){
int ejex = x;
gotoxy(ejex+3, i);
printf("|");
delay (10);
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(" * ");
b = getch();
switch (b){
case 'a':
ship(x-7,y);
break;
case 'd':
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();
}
The menu and stuff is in spanish. Just press E to go playing or Z to exit. While playing, you use A and D to move left and right, S to shoot, M to return to the menu, and Z to exit.
As you would obviously see, the game is at no point done. The only thing the ship can do now is move and shoot. However my question would be this:
1. Try moving to the far right or far left, beyond the screen. Any ideas on how to set the limits? I have an idea of putting an if statement in the switch in the ship function, but if you have any more ideas, please share.
2. Any ideas on how to create random evil ships? And as well, how to actually make em die?
Thanks, it's all in the name of knowledge :)
By the way, compile with Borland 3.1, cuz I don't think the other compilers will work (since it's not an ANSI program, it contains other functions and libs).
Bye :) B)
Here's my code for the game
#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 salida(){
clrscr();
delay(1000);
printf("Gracias por jugar\n");
exit(0);
}
void shoot(int x, int y){
int i=21;
while (i>0){
int ejex = x;
gotoxy(ejex+3, i);
printf("|");
delay (10);
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(" * ");
b = getch();
switch (b){
case 'a':
ship(x-7,y);
break;
case 'd':
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();
}
The menu and stuff is in spanish. Just press E to go playing or Z to exit. While playing, you use A and D to move left and right, S to shoot, M to return to the menu, and Z to exit.
As you would obviously see, the game is at no point done. The only thing the ship can do now is move and shoot. However my question would be this:
1. Try moving to the far right or far left, beyond the screen. Any ideas on how to set the limits? I have an idea of putting an if statement in the switch in the ship function, but if you have any more ideas, please share.
2. Any ideas on how to create random evil ships? And as well, how to actually make em die?
Thanks, it's all in the name of knowledge :)
By the way, compile with Borland 3.1, cuz I don't think the other compilers will work (since it's not an ANSI program, it contains other functions and libs).
Bye :) B)