Were working on a family feud game and i wanted to apply changing colors to a group of circles randomly
i tried using for loop in this given code, but i know its wrong. how do i randomize?
//looping set1
for(x=0;x<=15;x++)
{
setcolor(x);
sleep(3000);
}
setfillstyle(1,1);
fillpoly(13,lyt1);
fillpoly(9,lyt2);
fillpoly(9,lyt3);
fillpoly(12,lyt4);
//looping set2
for(x=0;x<=15;x++);
{
setcolor(x);
sleep(3000);
}
setfillstyle(1,1);
fillpoly(11,lyt5);
fillpoly(12,lyt6);
fillpoly(13,lyt7);
fillpoly(12,lyt8);
I am assuming you are in MS-DOS (not sure if emulated or real one or just windows console) but the animation and randomization is done a bit differently.
Due to various restrictions (so it works on each platform and do not use any advanced stuff) the program structure of your main loop should look more like this:
This structure does not need any interrupts so it is easy to understand for rookies. But games need usually more speed and event handlers are faster. For that you would need to use interrupts ISR for stuff like keyboard,PIT,...
Using
sleep()
is not precise so if you want precise measurement of time you should either usePIT
orRDTSC
but that could create incompatibilities in emulated environments...Haven't code in MS-DOS for ages so I am not sure in which lib the
random
andrandomize
routines are they might also be calledRandom,Randomize
my bet is they are instdio.h
orconio.h
. Simply typerandom
into program place cursor at it and hitALT+F1
to bring up context help. There you will read which lib to include. Also I am not sure if to userandom(15)
orrandom(16)
so read which is correct there too.If you are coding a game then you will probably need some menu's. Either incorporate them into main loop or have separate main loop for each game page and use
goto
or encode each as separate function.Have a look at few related QA's of mine:
And setcolor doc