0

I am setting up a slot machine with 3 squares that blink alternatively using double buffering; the while loop is infinite and stops using kbhit() (Which I believe is the mistake), even though the loop stops the commands in the if condition is not executed. rectangle()-A function I wrote to make three squares spaced out equally on the screen.

while(z!=1)
   {
    if(kbhit()!=0)
    {  cleardevice();
       delay(3000);
       bar3d((150),(110),(230),(190),0,0);
       z=1;
       continue;}

    setvisualpage(page);
    setactivepage(1-page);

    settextstyle(3,0,5);
    rectangle((x-190),y,(x+190),(y+60));
    outtextxy((x-120),(y+3),"Slot Machine");

    if(page==0)
       setfillstyle(SOLID_FILL,4);
    else
      setfillstyle(SOLID_FILL,GREEN);

    rectanfle(x,y);
    setfillstyle(SOLID_FILL,BLUE);
    bar3d((x-90),(y+255),(x+90),(y+295),5,5);
    floodfill((x-89),(y+264),WHITE);
    settextstyle(0,0,2);
    outtextxy((x-85),(y+265),"Press Enter");

    page=1-page;
    delay(100);
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • 1. [graphics] tag is not for `graphics.h` nor BGI.... You got BGI or WinBGI? I chose [WinBGI] for tags as you got Windows tag but if you're in dosbox or other emulator then the tags should be BGI and DosBox or MSDOS ... 2. did not use this for decades but IIRC `kbhit()` is not clearing the key-pressed from the keyboard handler buffer meaining after first hit to keyboard your code will never go pass that if condition (due `continue` in it) you need to add `getch()` or other method of acquiring key inside the `if` code. 3. beware `[name](link)` is format for links you had it in the OP as text – Spektre Jul 25 '19 at 04:58
  • see [How to make the last letter blink?](https://stackoverflow.com/a/36592399/2521214) looks like `getch()` is the function to use after successful `kbhit()`... – Spektre Jul 25 '19 at 05:02

0 Answers0