Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compilers LCC > My code won't c...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 983 of 1058
Post > Topic >>

My code won't compile!

by Albert <albert.xtheunknown0@[EMAIL PROTECTED] > Sep 24, 2007 at 01:46 AM

Hi everyone,

1. This is NOT my code - this was from someone off the internet
2. The reason why I decided to download this code was to analyse it;
seeing how people make simple C games
3. This code is BAD - it uses global variables, a lot of the variables
have meaningless letters
4. I've posted my question to comp.lang.c and got quite a lot of
feedback - they say that 'I' (meaning the code) contained "#include
clrscr()" in order for the error to occur - that wasn't in the code
5. This code is apparently specific to this lcc compiler; use of
tcconio.h; conio.h isn't standard, tcconio.h definitely isn't
6. From the majority of people, I conclude that I should look for a
better example of a C game; that is - that the author has carefully
thought out his function calls, parameters, arguments, variables and
structure.
7. SOMEONE just solve this problem - PLEASE!
8. This game is crap but that's what I expect (but of course not the
CODE to be CRAP AS WELL!)

And here's the code:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <tcconio.h>

int x = 40, l, k = 2, z = 0, i, score = 0;
void gameover();
void game();
void top();
void shoot();
void gotoxy (int x, int y);

void main()
{
        int ch;
        clrscr();
        printf("\n\t\t\t\tSHOOTING IN C");
        printf("\n\t\t\t\t*************");
        printf("\n\n\n1.NEW GAME\n2.INSTRUCTIONS\n3.QUIT");
        printf("\n\n\n ENTER YOUR CHOICE:");
        scanf("%d", &ch);

        switch(ch)
        {
                case 1:
                        game();
                        break;
                case 2:
                        clrscr();
                        printf("\n\t\t1. Press any key to start the
game.");
                        printf("\n\t\t2. Use'n' for left and 'm' for
right directions.");
                        printf("\n\t\t3. Press ENTER key for
shooting");
                        printf("\n\t\t4. PRESS 'x' KEY for Exit");
                        printf("\n\n\n\t\t\t Don't Use any other
keys");
                        getch();
                        main();
                        break;

                case 3:
                        exit(1);
        }

}

void game()
{
        char n, c;
        int k, y = 24;
        clrscr();
        i = 0;
        n = (char)i;
        clrscr();
        gotoxy(12,25);
        cprintf("\nUSE 'n' or 'm' For Moving and then press Enter for
shoot");

        while(c!=120)
        {
                c = getch();

                switch(c)
                {
                        case 'n':
                                top();
                                gotoxy(x--, y);
                                shoot();
                                break;

                        case 'm':
                                top();
                                gotoxy(x++,y);
                                cprintf("  ");
                                shoot();
                }
                cprintf("%c ",n);
        }

}

void top()
{
        char n;
        l = 254;
        n = (char)l;
        randomize();

        gotoxy(rand()%75, k);
        cprintf("%c", n);

}

void shoot()
{
        int c,a;
        c = getch();

        if (c == 13)
        {
                cprintf("%c", 263);

                for (a = 0; a <= k; a++)
                {
                        gotoxy(x, a);
                        cprintf(" ");
                }

                score += 10;
                gotoxy(1, 1);
                cprintf("SCORE=%d", score);
                gameover();
        }

}

void gameover()
{
        int b;
        z = z + 1;

        if(z >= 3)
        {
                k++;
                z = 0;
        }

        if ( k> 20)
        {
                printf("\n\t\t\tGAME OVER");
                sleep(3);
                getch();
                exit(0);
        }
}

The compiler re****ts an error about the clrscr() function
 




 4 Posts in Topic:
My code won't compile!
Albert <albert.xtheunk  2007-09-24 01:46:22 
Re: My code won't compile!
Friedrich Dominicus <j  2007-09-24 14:14:34 
Re: My code won't compile!
jacob navia <jacob@[EM  2007-09-24 13:05:21 
Re: My code won't compile!
"Antoine Leca"   2007-09-25 16:26:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Jul 6 16:56:49 CDT 2008.