Thread: getting input without waiting for it(tetris)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    and you might have to change your timer function (someone verify this).
    Code:
    //Timer Function
    int timer(double t)
    {
        int kp;
        double start=double(clock())/1000,end=double(clock())/1000;
        for (double dif=0;dif<=t;dif=end-start){end=double(clock())/1000;}
        while (kbhit())
        {
        kp=getkeypress();
        return kp;
        break;}
    }
    clock()'s standard, but getkeypress() isn't. BTW, you don't need a while loop, and your casts were wrong:
    Code:
    //Timer Function
    int timer(double t)
    {
        int kp;
        double start=(double)(clock())/1000,end=(double)(clock())/1000;
        for (double dif=0;dif<=t;dif=end-start){end=(double)(clock())/1000;}
        if (kbhit())
        {
        kp=getkeypress();
        return kp;
        }
        return 0;
    }
    Last edited by dwks; 12-10-2005 at 04:23 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input class project (again)
    By Elysia in forum C++ Programming
    Replies: 41
    Last Post: 02-13-2009, 10:52 AM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  4. Getting input without waiting for keypress
    By Anon48 in forum C Programming
    Replies: 2
    Last Post: 04-08-2005, 02:18 AM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM