Is it possible to execute another statement in C while on getch function?


Is it possible to execute another statement in C while on getch function? I do not know anything about multitasking. I am just a beginner in programming. I am making an ascii dos game version of pacman. But I don’t know on how to multitask the ghosts and pacman. I just need to make pacman and the ghosts move at the same time. Even if macman stops, can the ghosts still move? Thanks you and God Bless!

4 Responses to “Is it possible to execute another statement in C while on getch function?”

  • DoomSlayer34.5:

    Yes, it is called threading. and in C it is going to be interesting. If you are writing it on Windows look at the createThread method on MSDN
    If you are using Linux look at the manual pages for pthread_create.

  • buGGedDown:

    yes you can, make two functions one for pacman and one for the ghosts

    then you can put a stop method for pacman and let the ghosts just run.

  • Craig N:

    Simple:

    char key;
    do
    {
    while(!kbhit())
    {
    update collision, ghosts here and draw
    }
    key = getch();

    switch(key)
    {
    case ‘w’: moveup():
    break:

    …..etc
    }

    }while(key!= ‘e’);
    and there you have it

  • Hbfvjhbjb:

    my openion is you contact a live expert
    javascript-desining.blogspot.com

Leave a Reply