Machine Project..need help

Reply

Join Date: Jul 2009
Posts: 4
Reputation: louieansonng is an unknown quantity at this point 
Solved Threads: 0
louieansonng louieansonng is offline Offline
Newbie Poster

Machine Project..need help

 
0
  #1
Jul 22nd, 2009
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.
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <mp.h>
  4. #include <conio.h>
  5.  
  6. void setBackground(unsigned short int color);
  7. int pickRandom(int min, int max);
  8. void delay(unsigned long milisec);
  9. void playSoundBeep();
  10. void gotoxy(int x,int y);
  11. void setx(int x);
  12. void sety(int y);
  13. char getKeypressed();
  14. void setScoreTo(int s); // sets the score to s
  15. 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.
  16. void showScore(); // shows the current score
  17. int getScore(); // returns the current score
  18. void clrscr(void);
  19. int getx(void);
  20. int gety(void);
  21.  
  22. int getObject(int *x)
  23. {
  24. *x = pickRandom(0, 79);
  25.  
  26. return(*x);
  27. }
  28. int main()
  29. {
  30. int live = 3;
  31. int x1 = 0, y = 0;
  32. int x = pickRandom(0, 79);
  33. setBackground(BLUE);
  34.  
  35. do{
  36. clrscr();
  37. gotoxy(getObject(&x), y);
  38. printf("T");
  39. gotoxy(&x, y++);
  40. delay(1000);
  41. }
  42.  
  43. while(y < 24);
  44.  
  45. getch();
  46.  
  47. }

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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,604
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 120
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: Machine Project..need help

 
1
  #2
Jul 22nd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: louieansonng is an unknown quantity at this point 
Solved Threads: 0
louieansonng louieansonng is offline Offline
Newbie Poster

Re: Machine Project..need help

 
0
  #3
Jul 22nd, 2009
Originally Posted by jephthah View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Machine Project..need help

 
0
  #4
Jul 22nd, 2009
> 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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: louieansonng is an unknown quantity at this point 
Solved Threads: 0
louieansonng louieansonng is offline Offline
Newbie Poster

Re: Machine Project..need help

 
0
  #5
Jul 22nd, 2009
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....
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Machine Project..need help

 
0
  #6
Jul 23rd, 2009
Well one of your gotoxy is at the very least a compiler warning, if not an outright error.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 4
Reputation: louieansonng is an unknown quantity at this point 
Solved Threads: 0
louieansonng louieansonng is offline Offline
Newbie Poster

Re: Machine Project..need help

 
0
  #7
Jul 23rd, 2009
I removed the reference on the first post. here's my final:
  1.  
  2. int main()
  3. {
  4. int lives = 3;
  5. int x1 = 0, y = 0;
  6. int x = getx();
  7. setBackground(BLUE);
  8.  
  9.  
  10. do{
  11. x:
  12. clrscr();
  13. gotoxy(pickRandom(0, 79), y);
  14. printf("T");
  15. gotoxy(x, y++);
  16. delay(200);
  17. }
  18. while(y < 24);
  19.  
  20. if( lives == 3)
  21. goto x;
  22.  
  23. getch();
  24.  
  25. }

Same problem here. How do I set the x it chose in the pickRandom?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Machine Project..need help

 
0
  #8
Jul 23rd, 2009
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
  1. int x = pickRandom(0, 79);
  2. int y = 0;
  3. do {
  4. gotoxy(x,y);
  5. printf("T");
  6. delay(200);
  7. printf("\b ");
  8. y = y + 1;
  9. } while ( y < 24 );
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC