Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Tetris Game

Hello,
My name is Cameron and i am trying to write a copy of tetris, but for dos, in my program you currently have to press the enter key to get the block to move down the screen, is there a function or keyword that i can use to do this automatically, and if possible to a set time (for example every second or two seconds).

If anyone could help me with this it would be a great.

My e-mail is JazzA_83@hotmail.com

Cameron

Comments

  • dmbdmb Member Posts: 18
    : Hello,
    : My name is Cameron and i am trying to write a copy of tetris, but for dos, in my program you currently have to press the enter key to get the block to move down the screen, is there a function or keyword that i can use to do this automatically, and if possible to a set time (for example every second or two seconds).
    :
    : If anyone could help me with this it would be a great.
    :
    : My e-mail is JazzA_83@hotmail.com
    :
    : Cameron

    well i havent really tried this but maybe if you use time.h and the time(); function, you could have a loop that does this
    [code]
    (include time.h at top of prog)
    float Time = time();
    int x = ?; //number of seconds you want it to wait
    for(1) {
    while(Time + x > time()) {//wait}
    let Time = time();
    MoveBlockDownOne();
    }
    [/code]
    only problem with this is they really cant do anything while its thinking, youd have to add somethign in the while loop to check if the user did anything, and then exit the two loops, hope this helped
    -dmb
    {}

    }

  • primusprimus Member Posts: 1
    if you do it in dos, i suggest you use the function [blue]delay (ms)[/blue]. This stops the whole program for ms milliseconds. i also made a tetris clone which has a main loop like this:
    [code]
    while (1)
    {
    if (kbhit()) [green]// === Control part[/green]
    {
    in = getch(); [green]//kbhit() and getch() are in conio.h[/green]
    [green]// do action[/green]
    }

    delay(10); [green]// === Calculating and painting part[/green]
    time_count++;
    if (time_count>30) [green]// if the program waited at least 300 ms[/green]
    {
    time_count = 0;
    [green]// move block down[/green]
    }
    }
    [/code]

    this allows the program to check the keyboard every 10 ms so there is no lacking keyboard information.

    i hope this helps
    mp
Sign In or Register to comment.