C ++ Cant get this to compile

mdawg

Weaksauce
Joined
Jan 4, 2006
Messages
79
Alright this is a game I found, I am doing a project in C++ right now and Im trying to use some functions from this game but they just wont compile in Dev c++ or borland. The main thing thats giving me problems is the sleep() function. Can someone help me fix this only using Dev C ++ or Borland? Thanks for any input.

Also all the background colors wont work in Dev but they dont show up as errors in Borland. Im clueless on what I should do.

#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <iostream.h>
#include <iomanip.h>
void main()
{
int i, j, r, c, s, main;
char ans, opt;
menu:
textbackground(BLUE);
textcolor(YELLOW + BLINK);
clrscr();
textbackground(BLUE);
textcolor(YELLOW + BLINK);
do
{
gotoxy(24, 6);
printf("%c", 15);
gotoxy(33, 4);
printf("%c", 15);
gotoxy(40, 6);
printf("%c", 15);
gotoxy(50, 5);
printf("%c", 15);
gotoxy(60, 7);
printf("%c", 15);
gotoxy(70, 3);
printf("%c", 15);
gotoxy(18, 2);
printf("%c", 15);
gotoxy(7, 6);
printf("%c", 15);
gotoxy(18, 9);
printf("%c", 15);
gotoxy(63, 11);
printf("%c", 15);
gotoxy(20, 14);
printf("%c", 15);
gotoxy(57, 14);
printf("%c", 15);
//B
for(i = 8; i <= 12; i++)
{
gotoxy(26, i);
printf("%c", 173);
gotoxy(30, i);
printf("%c", 173);
}
for(i = 8; i <= 12; i = i + 2)
{
gotoxy(27, i);
printf("%c%c%c", 173, 173, 173);
}
//O
for(i = 8; i <= 12; i++)
{
gotoxy(33, i);
printf("%c", 173);
gotoxy(37, i);
printf("%c", 173);
}
for(i = 8; i <= 12; i = i + 4)
{
gotoxy(34, i);
printf("%c%c%c", 173, 173, 173);
}
//M
for(i = 8; i <= 12; i++)
{
gotoxy(40, i);
printf("%c", 173);
gotoxy(42, i);
printf("%c", 173);
gotoxy(44, i);
printf("%c", 173);
}
gotoxy(41, 8);
printf("%c", 173);
gotoxy(43, 8);
printf("%c", 173);
//B
for(i = 8; i <= 12; i++)
{
gotoxy(47, i);
printf("%c", 173);
gotoxy(51, i);
printf("%c", 173);
}
for(i = 8; i <= 12; i = i + 2)
{
gotoxy(48, i);
printf("%c%c%c", 173, 173, 173);
}
gotoxy(28, 15);
printf("T H E G A M E");
gotoxy(28, 19);
printf("1. New Game");
gotoxy(28, 20);
printf("2. Instructions.");
gotoxy(28, 21);
printf("3. Exit");
opt = getche();
if(opt == '1')
{
clrscr();
textbackground(BLUE);
textcolor(YELLOW + BLINK);
printf("ENTER THE SPEED WITH WHICH YOU WANT YOUR AEROPLANE TO MOVE ( > than 0 and < than 100): ");
scanf("%d", &s);
for(main = 1; main <= 3; main++)
{
clrscr();
textbackground(BLUE);
textcolor(YELLOW + BLINK);
gotoxy(37, 20);
printf("%c", 219);
gotoxy(1, 2);
printf(">%c--->", 173);
getch();
while(!kbhit())
{
for(i = 1; i < 75; i++)
{
if(kbhit())
{
getch();
nosound();
goto drop;
}
else
{
gotoxy(i, 2);
printf(">%c--->", 173);
r = 2;
c = i;
gotoxy(37, 20);
printf("%c", 219);
sound(100);
delay(100 - s);
if(i != 36 && !kbhit())
{
clrscr();
textbackground(BLUE);
textcolor(YELLOW + BLINK);
}
}
}
}
drop:
for(j = 3; j <= 20; j++)
{
gotoxy(c, r);
printf(">---->");
gotoxy(37, 20);
printf("%c", 219);
gotoxy(i, j);
printf("%c", 173);
delay(50);
sound(3000);
if(j != 15)
{
clrscr();
textbackground(BLUE);
textcolor(YELLOW + BLINK);
}
}
nosound();
if(i == 37)
{
gotoxy(34, 20);
printf("%cBOOM!!!%c", 15, 15);
gotoxy(29, 21);
//delay(100);
printf("%c %c %c", 15, 15, 15);
gotoxy(33, 19);
//delay(100);
printf("%c %c", 15, 15);
for(i = 0; i < 10; i++)
{
delay(30);
sound((i * 100) + 50);
delay(30);
nosound();
}
getch();
clrscr();
textbackground(BLUE);
textcolor(YELLOW + BLINK);
break;
}
else
{
gotoxy(i, 20);
clreol();
gotoxy(30, 15);
printf("SORRY, YOU MISSED THE TARGET");
sound(2000);
delay(100);
nosound();
}
getch();
}
}
}
while(opt == '1');
if(opt == '2')
{
clrscr();
textbackground(BLUE);
textcolor(YELLOW + BLINK);
printf("INSTRUCTIONS :-");
printf("\n\n\n");
printf("1. The objective of this game is to destroy the target by dropping a bomb on it.\n2. The player needs to drop the bomb from an aeroplane.\n\n3. Press any key to start flying the aeroplane.\n\n4. Then again press any key to drop the bomb when you are above the target.\n\n5. The target will look like this %c.", 219);
getch();
goto menu;
}
if(opt == '3')
{
}
else
{
goto menu;
}
}
 
a little code formatting would greatly improve the readability of this. what errors do you get?
 
The problem is first off all the colors arnt showing up in the function. Its aspose to be included in the conio.h header file but for some reason its not. Because the color functions work when I compile it with borland. Even still it doesent show the delay function in either compiler. What do I need to do to get the delay function to work. Its just showing delay function undeclared and the color function undeclared.
 
I ran this through a program I have. It looks a little nicer. I can't help with your problem though. :(

Code:
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <iostream.h>
#include <iomanip.h>
void main()
{
  int i, j, r, c, s, main;
  char ans, opt;
menu:
  textbackground(BLUE);
  textcolor(YELLOW + BLINK);
  clrscr();
  textbackground(BLUE);
  textcolor(YELLOW + BLINK);
  do {
    gotoxy(24, 6);
    printf("%c", 15);
    gotoxy(33, 4);
    printf("%c", 15);
    gotoxy(40, 6);
    printf("%c", 15);
    gotoxy(50, 5);
    printf("%c", 15);
    gotoxy(60, 7);
    printf("%c", 15);
    gotoxy(70, 3);
    printf("%c", 15);
    gotoxy(18, 2);
    printf("%c", 15);
    gotoxy(7, 6);
    printf("%c", 15);
    gotoxy(18, 9);
    printf("%c", 15);
    gotoxy(63, 11);
    printf("%c", 15);
    gotoxy(20, 14);
    printf("%c", 15);
    gotoxy(57, 14);
    printf("%c", 15);
    //B
    for (i = 8; i <= 12; i++) {
      gotoxy(26, i);
      printf("%c", 173);
      gotoxy(30, i);
      printf("%c", 173);
    }
    for (i = 8; i <= 12; i = i + 2) {
      gotoxy(27, i);
      printf("%c%c%c", 173, 173, 173);
    }
    //O
    for (i = 8; i <= 12; i++) {
      gotoxy(33, i);
      printf("%c", 173);
      gotoxy(37, i);
      printf("%c", 173);
    }
    for (i = 8; i <= 12; i = i + 4) {
      gotoxy(34, i);
      printf("%c%c%c", 173, 173, 173);
    }
    //M
    for (i = 8; i <= 12; i++) {
      gotoxy(40, i);
      printf("%c", 173);
      gotoxy(42, i);
      printf("%c", 173);
      gotoxy(44, i);
      printf("%c", 173);
    }
    gotoxy(41, 8);
    printf("%c", 173);
    gotoxy(43, 8);
    printf("%c", 173);
    //B
    for (i = 8; i <= 12; i++) {
      gotoxy(47, i);
      printf("%c", 173);
      gotoxy(51, i);
      printf("%c", 173);
    }
    for (i = 8; i <= 12; i = i + 2) {
      gotoxy(48, i);
      printf("%c%c%c", 173, 173, 173);
    }
    gotoxy(28, 15);
    printf("T H E G A M E");
    gotoxy(28, 19);
    printf("1. New Game");
    gotoxy(28, 20);
    printf("2. Instructions.");
    gotoxy(28, 21);
    printf("3. Exit");
    opt = getche();
    if (opt == '1') {
      clrscr();
      textbackground(BLUE);
      textcolor(YELLOW + BLINK);
      printf("ENTER THE SPEED WITH WHICH YOU WANT YOUR AEROPLANE TO MOVE ( > than 0 and < than 100): ");
      scanf("%d", &s);
      for (main = 1; main <= 3; main++) {
        clrscr();
        textbackground(BLUE);
        textcolor(YELLOW + BLINK);
        gotoxy(37, 20);
        printf("%c", 219);
        gotoxy(1, 2);
        printf(">%c--->", 173);
        getch();
        while (!kbhit()) {
          for (i = 1; i < 75; i++) {
            if (kbhit()) {
              getch();
              nosound();
              goto drop;
            } else {
              gotoxy(i, 2);
              printf(">%c--->", 173);
              r = 2;
              c = i;
              gotoxy(37, 20);
              printf("%c", 219);
              sound(100);
              delay(100 - s);
              if (i != 36 && !kbhit()) {
                clrscr();
                textbackground(BLUE);
                textcolor(YELLOW + BLINK);
              }
            }
          }
        }
drop:
        for (j = 3; j <= 20; j++) {
          gotoxy(c, r);
          printf(">---->");
          gotoxy(37, 20);
          printf("%c", 219);
          gotoxy(i, j);
          printf("%c", 173);
          delay(50);
          sound(3000);
          if (j != 15) {
            clrscr();
            textbackground(BLUE);
            textcolor(YELLOW + BLINK);
          }
        }
        nosound();
        if (i == 37) {
          gotoxy(34, 20);
          printf("%cBOOM!!!%c", 15, 15);
          gotoxy(29, 21);
          //delay(100);
          printf("%c %c %c", 15, 15, 15);
          gotoxy(33, 19);
          //delay(100);
          printf("%c %c", 15, 15);
          for (i = 0; i < 10; i++) {
            delay(30);
            sound((i * 100) + 50);
            delay(30);
            nosound();
          }
          getch();
          clrscr();
          textbackground(BLUE);
          textcolor(YELLOW + BLINK);
          break;
        } else {
          gotoxy(i, 20);
          clreol();
          gotoxy(30, 15);
          printf("SORRY, YOU MISSED THE TARGET");
          sound(2000);
          delay(100);
          nosound();
        }
        getch();
      }
    }
  } while (opt == '1');
  if (opt == '2') {
    clrscr();
    textbackground(BLUE);
    textcolor(YELLOW + BLINK);
    printf("INSTRUCTIONS :-");
    printf("\n\n\n");
    printf("1. The objective of this game is to destroy the target by dropping a bomb on it.\n2. The player needs to drop the bomb from an aeroplane.\n\n3. Press any key to start flying the aeroplane.\n\n4. Then again press any key to drop the bomb when you are above the target.\n\n5. The target will look like this %c.", 219);
    getch();
    goto menu;
  }
  if (opt == '3') {}
  else {
    goto menu;
  }
}
 
at first i thought i saw you using goto's and i was thinking: "there goes any chance of getting a calm answer.."

but more importantly, what errors are you getting? this was asked once already.

few of us have the patience to wade through code and determine what should be a compile or parse error.
 
I don't think we need to wade through anything. This code is apparently written for a screen I/O library, and the definitions from the screen I/O library hasn't been shown to the compiler.

Back in the goold old days when we were writing 16-bit programs for DOS, compiler vendors shipped a few different screen I/O libraries. Borland had one, Microsoft had a different one. Zotech had one, I think; I don't believe Lattice ever shipped one.

Wherever you "found" this code, you should also find information about what platform it's intended to be compiled with. You'll need to get that platform (including the involved library), get the library hooked up, and that'll solve your problem.

If you're really linking to correct and active implementations of textcolor() and textbackground(), you might want to check how they're implemented. If they're expecting ANSI.SYS, I don't think you're going to have much luck getting them working under a modern version of Windows.
 
Alright, those function calls looked familiar to me, so I took a gamble and it paid off--this program compiles without trouble using Turbo C++ 3.0 for DOS. I spent many hours poking around with TC as a youngster :) The pictures below really don't do it justice--you have to see it in action!

adventure.png
 
Back
Top