Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Kickboy Face

Help with a "pacman-type" game in C

This topic is 5633 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering if someone could give me a hint on creating a score counter for a pacman-type game we are working on in a Computer Science course. We are working with the curses library and a point is supposed to be scored every time a dot is "gobbled" up and turned into a space. I have been told that an array is to be used to get the score counter to work. Could someone give me a couple tips on how to get this counter to work? We also began working with "sprintf" on Monday and I am not completely sure how it works. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Here''s what I have so far:


   #include<stdio.h>
#include<curses.h>
#include<time.h>

main () {

int i,j;
char ch,e=0,c=0,s=0,f=0;
int row, col;

initscr();
cbreak();
noecho();
nonl();


for (i=0; i<24; i++){
mvaddch(i,0,''*'');
mvaddch(i,23,''*'');
}
for(i = 0; i < 24; i++) {
mvaddch(0,i,''*'');
mvaddch(23,i,''*'');
}
for(i=1;i<23;i++){
for(j=1;j<23;j++){
mvaddch(i,j,''.'');
}
}


move(11,11);
row = 11;
col = 11;


mvaddstr(5,25,"e=up");
mvaddstr(6,25,"c=down");
mvaddstr(7,25,"s=left");
mvaddstr(8,25,"f=right");
mvaddstr(9,25,"Press X to exit.");

while(getch() != ''X'') {
ch=getch();

if(ch==''e'' && row > 1) row--;
if(ch==''c'' && row < 22) row++;
if(ch==''s'' && col > 1) col--;
if(ch==''f'' && col < 22) col++;
mvaddch(row,col,'' '');
move(row,col);
}
refresh();
endwin();
return 0;
}

Share this post


Link to post
Share on other sites
sprintf does the same thing as printf except it prints to a string buffer (which is the first parameter) instead of stdout.

Share this post


Link to post
Share on other sites
I belive it stands for "string print formatted." It works just like printf only the output is directed to a string e.g.


  
int score;
char string=new char[128];

// ... Some place in your code increment score counter ...


sprintf(string, "Score: %d", score); // Print the Users Score



In the above example, if 'score' was equal to say 100
then "Score: 100" would be stored inside of 'string'

Correct me if I'm wrong somebody

EDIT: Added Source Tags, :D

AtomicGames[http://www.geocities.com/agdev2k/]

[edited by - Ced1 on April 19, 2003 2:28:33 PM]

Share this post


Link to post
Share on other sites
Oops .. Heh you beat me to that one Lantz. Sorry bout'' that.

AtomicGames[http://www.geocities.com/agdev2k/]

Share this post


Link to post
Share on other sites
I got the ''sprintf'' statement to work, now I am having a problem with having the program recognize that a point should be added everytime the dot turns into a space.
   score=0;
for(g=1;g<23;g++){
for(h=1;h<23;h++){
a[g][h]=''.'';
if(a[g][h]=='' ''){
score=score+1;
}
}
}

I thought this would work (it seems logical to me for some reason). Am I taking the wrong approach to the problem? Any ideas? Thanks.

Share this post


Link to post
Share on other sites
i''m not understanding your code:

a[g][h]=''.'';
if(a[g][h]=='' ''){ // this is always false

you atribute ''.'' to a[g][h] and then you''re testing to see if is a space? it cant be a space its a dot.



To be considered a genius you just have to say what everybody knows in a way very few understand

Share this post


Link to post
Share on other sites
My first attempt involved just the test if(a[g][h]==' '). I did not have the a[g][h]='.' in the program and it did not work. Is there something else that should be tested, or might my problem lie in using the "sprintf" statement? How would I avoid adding extra points to the spaces that I have already been on?

[edited by - kickboy face on April 19, 2003 5:52:00 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!