Hi, I'm a student in Computer Science and we have a machine project due on August 20. The problem is, the professor only taught us the basics of C programming, the functions, switch statements and whatnot, and now they're giving us a project about making a game. The game is just like Tetris, only there are no blocks, instead we are matching them to trash bins. Because the overall project was too difficult to do, I thought of learning how to code falling texts first. Here is my code so far.

**mp.h is a user-defined header file that was given to us.

#include <stdio.h>
#include <windows.h>
#include <mp.h>
#include <conio.h>

void setBackground(unsigned short int color);
int pickRandom(int min, int max);
void delay(unsigned long milisec);
void playSoundBeep();
void gotoxy(int x,int y);
void setx(int x);
void sety(int y);
char getKeypressed();
void setScoreTo(int s);         // sets the score to s
void changeScoreBy(int x);      // increments the score by x.  If x is positive the score is increased.  If x is negative the score is decreased.
void showScore();               // shows the current score  
int getScore();                 // returns the current score
void clrscr(void);
int getx(void);
int gety(void);

int getObject(int *x)
{
     *x = pickRandom(0, 79);
     
     return(*x);
}
int main()
{
    int live = 3;
    int x1 = 0, y = 0;
    int x = pickRandom(0, 79);
setBackground(BLUE);

do{
clrscr();
gotoxy(getObject(&x), y);
printf("T");
gotoxy(&x, y++);
delay(1000);
}

while(y < 24);

getch();

}

The code I wrote enabled me to print my letter one line and clearing it before going to the next line. The only problem is, I can't get my letter to just stay in one straight line going down. I know I need to make my random X as it is but I don't know how. Any suggestions ? Thanks for all the help provided.

The game is just like Tetris, only there are no blocks, instead we are matching them to trash bins.

the individual words, I understand.

the sentence, makes my brain hurt.

Comments
rofl :P

the individual words, I understand.

the sentence, makes my brain hurt.

Sorry for the wrong grammar. What I meant to say was it is like Tetris in the sense that objects falling down, but they are not to be piled into lines, we have to move them into 3 positions depending on the object.

> The problem is, the professor only taught us the basics of C programming, the functions, switch statements and whatnot
That's not the only problem.
First it was a half-assed job of teaching you at all,
Then another half-assed job in teaching you obsolete TurboC as well - sheesh.

> Any suggestions ?
Pencil and paper.

Make a list of the things you need to do.
Think about how you would write the code.
Make little test programs to test your ideas. If that seems too complicated, then break the problem down into smaller steps.

When you've got a pretty good idea about how all the little bits work individually, think about how they might talk to one another (parameters, results etc), and start building up a program in stages.

Test regularly, and when you have reached a stage where an intermediate program does something useful, save a copy of it.

Yes, they didn't teach us Turbo C at all. We use Dev-C++ for compiling.

This is what I am doing right now, making small test programs, I just can't get the text to "fall down" in a straight line. If my gotoxy had a permanent number like 5, then the program would have worked. Problem is if I make my x a random number from 0 to 79, I can't get it to fall to the bottom of the screen using the x it got after picking a random number. This program I am doing right now is just 20% of the whole game, so I kinda need concrete answers rather than complaints....

I removed the reference on the first post. here's my final:

int main()
{
    int lives = 3;
    int x1 = 0, y = 0;
    int x = getx();
setBackground(BLUE);


do{
x:
clrscr();
gotoxy(pickRandom(0, 79), y);
printf("T");
gotoxy(x, y++);
delay(200);
   }
while(y < 24);

if( lives == 3)
goto x;
    
getch();

}

Same problem here. How do I set the x it chose in the pickRandom?

You have a label and a variable with the same name.

You have a LABEL (and the goto that goes with it)

Your goto is a backward jump

Your goto is INTO the middle of a loop.

First you need to learn some elements of basic program construction. Bashing in random snippets, compiling them and then asking on a forum "what's wrong now" won't get it done.

FWIW

int x = pickRandom(0, 79);
int y = 0;
do {
  gotoxy(x,y);
  printf("T");
  delay(200);
  printf("\b ");
  y = y + 1;
} while ( y < 24 );
This article has been dead for over six months. Start a new discussion instead.